]> git.kaiwu.me - njs.git/commitdiff
Tests: adapt stream_js_preload_object.t to nginx changes.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 2 Apr 2024 06:13:24 +0000 (23:13 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 2 Apr 2024 06:13:24 +0000 (23:13 -0700)
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.

nginx/t/stream_js_preload_object.t

index c28c401ad714b8bdcaca44a0b4552d50d6f0c71f..3c27098dd136665a44898bac0ab0841754acf03b 100644 (file)
@@ -66,16 +66,17 @@ EOF
 
 $t->write_file('lib.js', <<EOF);
     var res = '';
+    var acc, pup, fup, fdown;
 
     function access(s) {
-        res += g1.a;
+        acc = g1.a;
         s.allow();
     }
 
     function preread(s) {
         s.on('upload', function (data) {
-            res += g1.b[1];
-            if (res.length >= 3) {
+            pup = g1.b[1];
+            if (data.length > 0) {
                 s.done();
             }
         });
@@ -83,18 +84,16 @@ $t->write_file('lib.js', <<EOF);
 
     function filter(s) {
         s.on('upload', function(data, flags) {
+            fup = g1.c.prop[0].a;
             s.send(data);
-            res += g1.c.prop[0].a;
         });
 
         s.on('download', function(data, flags) {
-            if (!flags.last) {
-                res += g1.b[3];
-                s.send(data);
+            fdown = g1.b[3];
+            s.send(data);
 
-            } else {
-                res += g1.b[4];
-                s.send(res, {last:1});
+            if (flags.last) {
+                s.send(`\${acc}\${pup}\${fup}\${fdown}`, flags);
                 s.off('download');
             }
         });
@@ -117,6 +116,6 @@ $t->try_run('no js_preload_object available')->plan(2);
 ###############################################################################
 
 is(stream('127.0.0.1:' . port(8081))->read(), 'element', 'foo.bar.p');
-is(stream('127.0.0.1:' . port(8082))->io('0'), 'x122345', 'lib.access');
+is(stream('127.0.0.1:' . port(8082))->io('0'), 'x1234', 'filter chain');
 
 ###############################################################################