[njs] Test262: fixed flaky fs tests.

noreply at nginx.com noreply at nginx.com
Thu May 30 16:26:03 UTC 2024


details:   https://hg.nginx.org/njs/rev/7d73d18e19f8
branches:  
changeset: 2347:7d73d18e19f8
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed May 29 22:23:55 2024 -0700
description:
Test262: fixed flaky fs tests.

Previously, two tests running in parallel could occasionally generate
identical file names because Math.random() was used for part of the file
name, leading to one of the tests failing.

The fix is to use a single global counter to generate file names,
ensuring deterministic and unique file names for each test.

diffstat:

 test/fs/methods.t.js |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (21 lines):

diff -r d80048eb970d -r 7d73d18e19f8 test/fs/methods.t.js
--- a/test/fs/methods.t.js	Wed May 29 17:04:27 2024 -0700
+++ b/test/fs/methods.t.js	Wed May 29 22:23:55 2024 -0700
@@ -3,6 +3,8 @@ includes: [compatFs.js, compatBuffer.js,
 flags: [async]
 ---*/
 
+let unique = 0;
+
 function p(args, default_opts) {
     let params = Object.assign({}, default_opts, args);
 
@@ -10,7 +12,7 @@ function p(args, default_opts) {
         let fname = params.args[0];
 
         if (fname[0] == '@') {
-            let gen = `${test_dir}/fs_test_${Math.round(Math.random() * 1000000)}`;
+            let gen = `${test_dir}/fs_test_${unique++}`;
             params.args = params.args.map(v => v);
             params.args[0] = gen + fname.slice(1);
         }


More information about the nginx-devel mailing list