details:   https://hg.nginx.org/njs/rev/17af51d42ad9
branches:  
changeset: 2307:17af51d42ad9
user:      Dmitry Volyntsev <xei...@nginx.com>
date:      Mon Apr 01 23:13:25 2024 -0700
description:
Tests: adapt stream_js.t to nginx changes.

Make the test more robust against changes in nginx, specifically
cf890df37bb6 (Stream: socket peek in preread phase).

The filter callbacks may be called multiple times by nginx and the exact
number is not specified. The new test avoids relying on the exact number
of calls from nginx.

diffstat:

 nginx/t/stream_js.t |  15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diffs (57 lines):

diff -r 454d9c032c60 -r 17af51d42ad9 nginx/t/stream_js.t
--- a/nginx/t/stream_js.t       Mon Apr 01 23:13:24 2024 -0700
+++ b/nginx/t/stream_js.t       Mon Apr 01 23:13:25 2024 -0700
@@ -227,9 +227,10 @@ EOF
     }
 
     var res = '';
+    var step = (v) => { if (!res || res[res.length - 1] != v) res += v };
 
     function access_step(s) {
-        res += '1';
+        step(1);
 
         setTimeout(function() {
             if (s.remoteAddress.match('127.0.0.1')) {
@@ -240,8 +241,8 @@ EOF
 
     function preread_step(s) {
         s.on('upload', function (data) {
-            res += '2';
-            if (res.length >= 3) {
+            step(2);
+            if (data.length > 0) {
                 s.done();
             }
         });
@@ -249,18 +250,18 @@ EOF
 
     function filter_step(s) {
         s.on('upload', function(data, flags) {
+            step(3);
             s.send(data);
-            res += '3';
         });
 
         s.on('download', function(data, flags) {
 
             if (!flags.last) {
-                res += '4';
+                step(4);
                 s.send(data);
 
             } else {
-                res += '5';
+                step(5);
                 s.send(res, {last:1});
                 s.off('download');
             }
@@ -409,7 +410,7 @@ is(stream('127.0.0.1:' . port(8082))->re
 is(stream('127.0.0.1:' . port(8083))->read(), '', 'stream js unknown 
function');
 is(stream('127.0.0.1:' . port(8084))->read(), 'sess_unk=undefined', 's.unk');
 
-is(stream('127.0.0.1:' . port(8086))->io('0'), '0122345',
+is(stream('127.0.0.1:' . port(8086))->io('0'), '012345',
        'async handlers order');
 is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'access_undecided');
 is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'access_allow');
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to