]> git.kaiwu.me - njs.git/commitdiff
Test262: fixed flaky fs tests.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 30 May 2024 05:23:55 +0000 (22:23 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 30 May 2024 16:25:23 +0000 (09:25 -0700)
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.

test/fs/methods.t.js

index cc840c6cc0a76dc212ff15a2902ccda1e307c19d..8077c0c0dbe5ad0f05b03218d204f37907799f76 100644 (file)
@@ -3,6 +3,8 @@ includes: [compatFs.js, compatBuffer.js, runTsuite.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);
         }