changeset 2347:7d73d18e19f8

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.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 29 May 2024 22:23:55 -0700
parents d80048eb970d
children 7c671d50f646
files test/fs/methods.t.js
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 flags: [async]
 ---*/
 
+let unique = 0;
+
 function p(args, default_opts) {
     let params = Object.assign({}, default_opts, args);
 
@@ -10,7 +12,7 @@
         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);
         }