summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-10-11 06:15:14 -0700
committerJames M Snell <jasnell@gmail.com>2017-10-12 18:16:44 -0700
commitc2cf47a23953f4fed7275bf37371d258113035c2 (patch)
tree0f6349b88bb75f82051d46e998a99bc99d23e086
parentb41d215f2856e07e12773bf20c3153d0de04a217 (diff)
downloadandroid-node-v8-c2cf47a23953f4fed7275bf37371d258113035c2.tar.gz
android-node-v8-c2cf47a23953f4fed7275bf37371d258113035c2.tar.bz2
android-node-v8-c2cf47a23953f4fed7275bf37371d258113035c2.zip
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: https://github.com/nodejs/node/pull/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>
-rw-r--r--benchmark/module/module-loader.js27
1 files changed, 4 insertions, 23 deletions
diff --git a/benchmark/module/module-loader.js b/benchmark/module/module-loader.js
index d40e36dc3e..cca5fc2c22 100644
--- a/benchmark/module/module-loader.js
+++ b/benchmark/module/module-loader.js
@@ -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],
@@ -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++) {
@@ -36,7 +35,7 @@ function main(conf) {
else
measureDir(n, conf.useCache === 'true');
- rmrf(tmpDirectory);
+ refreshTmpDir();
}
function measureFull(n, useCache) {
@@ -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
- }
-}