Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
benchmark: remove writing to benchmark directory
Browse files Browse the repository at this point in the history
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/node#16144
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Oct 15, 2017
1 parent 9b0a54a commit 86a4f16
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const fs = require('fs');
const path = require('path');
const common = require('../common.js');

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

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

rmrf(tmpDirectory);
try { fs.mkdirSync(tmpDirectory); } catch (e) {}
refreshTmpDir();
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}

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

rmrf(tmpDirectory);
refreshTmpDir();
}

function measureFull(n, useCache) {
Expand Down Expand Up @@ -66,21 +65,3 @@ function measureDir(n, useCache) {
}
bench.end(n / 1e3);
}

function rmrf(location) {
try {
const things = fs.readdirSync(location);
things.forEach(function(thing) {
var cur = path.join(location, thing),
isDirectory = fs.statSync(cur).isDirectory();
if (isDirectory) {
rmrf(cur);
return;
}
fs.unlinkSync(cur);
});
fs.rmdirSync(location);
} catch (err) {
// Ignore error
}
}

0 comments on commit 86a4f16

Please sign in to comment.