Skip to content

Commit

Permalink
Test262: fixed flaky fs tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xeioex committed May 30, 2024
1 parent 8c43855 commit 7695542
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/fs/methods.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ includes: [compatFs.js, compatBuffer.js, runTsuite.js]
flags: [async]
---*/

let unique = 0;

function p(args, default_opts) {
let params = Object.assign({}, default_opts, args);

if (params.args) {
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);
}
Expand Down

0 comments on commit 7695542

Please sign in to comment.