Skip to content

Commit c2cf47a

Browse files
Trottjasnell
authored andcommitted
benchmark: remove writing to benchmark directory
A benchmark for module loading creates a temporary directory in the benchmark directory. Re-use the test common module to put the tmp directory in test instead. This was causing intermittent test failures because run.js (invoked by benchmark tests, mulitple of which could be running at once) throws if a subdirectory of benchmark disappears at just the wrong time. There are other possible solutions than repurposing the `test/common` module but two arguments for doing it this way are: * There is already another benchmark file that does this (`http_server_for_chunky_client.js`) so the dependency already exists in the benchmarks. * This also eliminates a re-implementation of rimraf in the benchmark code. PR-URL: nodejs#16144 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b41d215 commit c2cf47a

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

benchmark/module/module-loader.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const fs = require('fs');
33
const path = require('path');
44
const common = require('../common.js');
55

6-
const tmpDirectory = path.join(__dirname, '..', 'tmp');
7-
const benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module');
6+
const { refreshTmpDir, tmpDir } = require('../../test/common');
7+
const benchmarkDirectory = path.join(tmpDir, 'nodejs-benchmark-module');
88

99
const bench = common.createBenchmark(main, {
1010
thousands: [50],
@@ -15,8 +15,7 @@ const bench = common.createBenchmark(main, {
1515
function main(conf) {
1616
const n = +conf.thousands * 1e3;
1717

18-
rmrf(tmpDirectory);
19-
try { fs.mkdirSync(tmpDirectory); } catch (e) {}
18+
refreshTmpDir();
2019
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
2120

2221
for (var i = 0; i <= n; i++) {
@@ -36,7 +35,7 @@ function main(conf) {
3635
else
3736
measureDir(n, conf.useCache === 'true');
3837

39-
rmrf(tmpDirectory);
38+
refreshTmpDir();
4039
}
4140

4241
function measureFull(n, useCache) {
@@ -66,21 +65,3 @@ function measureDir(n, useCache) {
6665
}
6766
bench.end(n / 1e3);
6867
}
69-
70-
function rmrf(location) {
71-
try {
72-
const things = fs.readdirSync(location);
73-
things.forEach(function(thing) {
74-
var cur = path.join(location, thing),
75-
isDirectory = fs.statSync(cur).isDirectory();
76-
if (isDirectory) {
77-
rmrf(cur);
78-
return;
79-
}
80-
fs.unlinkSync(cur);
81-
});
82-
fs.rmdirSync(location);
83-
} catch (err) {
84-
// Ignore error
85-
}
86-
}

0 commit comments

Comments
 (0)