Dmitry Volyntsev
April 02, 2024 11:54AM
details: https://hg.nginx.org/njs/rev/454d9c032c60
branches:
changeset: 2306:454d9c032c60
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Apr 01 23:13:24 2024 -0700
description:
Tests: adapt stream_js_preload_object.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_preload_object.t | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)

diffs (56 lines):

diff -r 498b2387ef04 -r 454d9c032c60 nginx/t/stream_js_preload_object.t
--- a/nginx/t/stream_js_preload_object.t Mon Apr 01 23:13:23 2024 -0700
+++ b/nginx/t/stream_js_preload_object.t Mon Apr 01 23:13:24 2024 -0700
@@ -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 @@ 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 @@ EOF
###############################################################################

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');

###############################################################################
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Tests: adapt stream_js_preload_object.t to nginx changes.

Dmitry Volyntsev 186 April 02, 2024 11:54AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 112
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready