Skip to content

Commit

Permalink
benchmark: fix race condition on fs benchs
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Oct 4, 2023
1 parent 95b8f5d commit bc9e25f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
16 changes: 11 additions & 5 deletions benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ function main({ len, duration, concurrent, encoding }) {
const totalOps = reads + zips;
benchEnded = true;
bench.end(totalOps);
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}

// This delay is needed because on windows this can cause
// race condition with afterRead, which makes this benchmark
// fails to delete the temp file
setTimeout(() => {
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
}, 10);
}, duration * 1000);

function read() {
Expand Down
18 changes: 12 additions & 6 deletions benchmark/fs/readfile-permission-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ function main({ len, duration, concurrent, encoding }) {
setTimeout(() => {
benchEnded = true;
bench.end(reads);
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);

// This delay is needed because on windows this can cause
// race condition with afterRead, which makes this benchmark
// fails to delete the temp file
setTimeout(() => {
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, 10);
}, duration * 1000);

function read() {
Expand Down
18 changes: 12 additions & 6 deletions benchmark/fs/readfile-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ function main({ len, duration, concurrent, encoding }) {
setTimeout(() => {
benchEnded = true;
bench.end(writes);
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);

// This delay is needed because on windows this can cause
// race condition with afterRead, which makes this benchmark
// fails to delete the temp file
setTimeout(() => {
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, 10);
}, duration * 1000);

function read() {
Expand Down
18 changes: 12 additions & 6 deletions benchmark/fs/readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ function main({ len, duration, concurrent, encoding }) {
setTimeout(() => {
benchEnded = true;
bench.end(reads);
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);

// This delay is needed because on windows this can cause
// race condition with afterRead, which makes this benchmark
// fails to delete the temp file
setTimeout(() => {
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, 10);
}, duration * 1000);

function read() {
Expand Down
20 changes: 13 additions & 7 deletions benchmark/fs/writefile-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ function main({ encodingType, duration, concurrent, size }) {
setTimeout(() => {
benchEnded = true;
bench.end(writes);
for (let i = 0; i < filesWritten; i++) {
try {
fs.unlinkSync(`${filename}-${i}`);
} catch {
// Continue regardless of error.

// This delay is needed because on windows this can cause
// race condition with afterRead, which makes this benchmark
// fails to delete the temp file
setTimeout(() => {
for (let i = 0; i < filesWritten; i++) {
try {
fs.unlinkSync(`${filename}-${i}`);
} catch {
// Continue regardless of error.
}
}
}
process.exit(0);
process.exit(0);
}, 10);
}, duration * 1000);

function write() {
Expand Down

0 comments on commit bc9e25f

Please sign in to comment.