Welcome! Log In Create A New Profile


[njs] Tests: fixed incr() tests for a shared dictionary.

Dmitry Volyntsev
September 07, 2023 07:14PM
details: https://hg.nginx.org/njs/rev/5b52293ad769
changeset: 2193:5b52293ad769
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Sep 07 16:12:31 2023 -0700
Tests: fixed incr() tests for a shared dictionary.

Previously, the incr() method called SharedDict.incr() with a NaN value
as a second argument because parseInt(undefined) returns NaN.

The test itself failed to capture the issue because it matches the whole
HTTP response and the pattern itself was too short, so it matched


nginx/t/js_shared_dict.t | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)

diffs (28 lines):

diff -r 1f0adb4b81da -r 5b52293ad769 nginx/t/js_shared_dict.t
--- a/nginx/t/js_shared_dict.t Wed Sep 06 18:02:50 2023 -0700
+++ b/nginx/t/js_shared_dict.t Thu Sep 07 16:12:31 2023 -0700
@@ -190,8 +190,8 @@ EOF

function incr(r) {
var dict = ngx.shared[r.args.dict];
- var val = dict.incr(r.args.key, parseInt(r.args.by),
- parseInt(r.args.def));
+ var def = r.args.def ? parseInt(r.args.def) : 0;
+ var val = dict.incr(r.args.key, parseInt(r.args.by), def);
r.return(200, val);

@@ -272,9 +272,10 @@ like(http_get('/set?dict=waka&key=FOO&va
like(http_get('/chain?dict=bar&key=FOO2&value=aaa'), qr/aaa/, 'chain bar.FOO2');

like(http_get('/incr?dict=waka&key=FOO&by=5'), qr/47/, 'incr waka.FOO');
-like(http_get('/incr?dict=waka&key=FOO2&by=1'), qr/1/, 'incr waka.FOO2');
-like(http_get('/incr?dict=waka&key=FOO2&by=2'), qr/3/, 'incr waka.FOO2');
-like(http_get('/incr?dict=waka&key=FOO3&by=3&def=5'), qr/8/, 'incr waka.FOO3');
+like(http_get('/incr?dict=waka&key=FOO2&by=7777'), qr/7777/, 'incr waka.FOO2');
+like(http_get('/incr?dict=waka&key=FOO2&by=2'), qr/7779/, 'incr waka.FOO2');
+like(http_get('/incr?dict=waka&key=FOO3&by=3333&def=5'), qr/3338/,
+ 'incr waka.FOO3');

like(http_get('/has?dict=foo&key=FOO'), qr/true/, 'has foo.FOO');
like(http_get('/has?dict=foo&key=NOT_EXISTING'), qr/false/,
nginx-devel mailing list
Subject Author Views Posted

[njs] Tests: fixed incr() tests for a shared dictionary.

Dmitry Volyntsev 275 September 07, 2023 07:14PM

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

Online Users

Guests: 155
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