Skip to content

Commit

Permalink
benchmark: fix race condition on readfile
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Oct 4, 2023
1 parent 95b8f5d commit c44de49
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 32 deletions.
18 changes: 12 additions & 6 deletions benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const path = require('path');
const common = require('../common.js');
const filename = path.resolve(__dirname,
`.removeme-benchmark-garbage-${process.pid}`);
`.removeme-benchmark-garbage-${process.pid}`);

Check failure on line 14 in benchmark/fs/readfile-partitioned.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 30 spaces but found 2
const fs = require('fs');
const zlib = require('zlib');
const assert = require('assert');
Expand Down 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

Check failure on line 47 in benchmark/fs/readfile-partitioned.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
// 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
20 changes: 13 additions & 7 deletions benchmark/fs/readfile-permission-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ function main({ len, duration, concurrent, encoding }) {
let benchEnded = false;
bench.start();
setTimeout(() => {
benchEnded = true;
benchEnded = true

Check failure on line 42 in benchmark/fs/readfile-permission-enabled.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
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

Check failure on line 45 in benchmark/fs/readfile-permission-enabled.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
// 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

Check failure on line 45 in benchmark/fs/readfile-promises.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
// 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

Check failure on line 38 in benchmark/fs/readfile.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
// 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

Check failure on line 47 in benchmark/fs/writefile-promises.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
// 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 c44de49

Please sign in to comment.