summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-09-17 15:34:31 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-09-18 13:12:34 +0200
commit9ccf5c8954b8260d1a016c9b1442012ad8626bea (patch)
tree96dc32f562b8017530a0672a438781c8de061fe0 /test
parenta9e7369b117f857f24ed67ece1f212b4b605c584 (diff)
downloadandroid-node-v8-9ccf5c8954b8260d1a016c9b1442012ad8626bea.tar.gz
android-node-v8-9ccf5c8954b8260d1a016c9b1442012ad8626bea.tar.bz2
android-node-v8-9ccf5c8954b8260d1a016c9b1442012ad8626bea.zip
test: don't inspect values if not necessary
The inspection triggered on each assert call eagerly even tough the assertion was never triggered. That caused significant CPU overhead. PR-URL: https://github.com/nodejs/node/pull/22903 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/common/heap.js25
-rw-r--r--test/internet/test-trace-events-dns.js7
-rw-r--r--test/parallel/test-trace-events-fs-sync.js7
-rw-r--r--test/parallel/test-worker-message-port-transfer-self.js12
4 files changed, 39 insertions, 12 deletions
diff --git a/test/common/heap.js b/test/common/heap.js
index a36223fa9c..382d1d3642 100644
--- a/test/common/heap.js
+++ b/test/common/heap.js
@@ -33,10 +33,17 @@ class State {
(node) => [expectedChild.name, 'Node / ' + expectedChild.name]
.includes(node.name);
- assert(snapshot.some((node) => {
+ const hasChild = snapshot.some((node) => {
return node.outgoingEdges.map((edge) => edge.toNode).some(check);
- }), `expected to find child ${util.inspect(expectedChild)} ` +
- `in ${util.inspect(snapshot)}`);
+ });
+ // Don't use assert with a custom message here. Otherwise the
+ // inspection in the message is done eagerly and wastes a lot of CPU
+ // time.
+ if (!hasChild) {
+ throw new Error(
+ 'expected to find child ' +
+ `${util.inspect(expectedChild)} in ${util.inspect(snapshot)}`);
+ }
}
}
}
@@ -61,9 +68,15 @@ class State {
node.value.constructor.name === expectedChild.name);
};
- assert(graph.some((node) => node.edges.some(check)),
- `expected to find child ${util.inspect(expectedChild)} ` +
- `in ${util.inspect(snapshot)}`);
+ // Don't use assert with a custom message here. Otherwise the
+ // inspection in the message is done eagerly and wastes a lot of CPU
+ // time.
+ const hasChild = graph.some((node) => node.edges.some(check));
+ if (!hasChild) {
+ throw new Error(
+ 'expected to find child ' +
+ `${util.inspect(expectedChild)} in ${util.inspect(snapshot)}`);
+ }
}
}
}
diff --git a/test/internet/test-trace-events-dns.js b/test/internet/test-trace-events-dns.js
index e1cfd6a597..9e5a0ccb02 100644
--- a/test/internet/test-trace-events-dns.js
+++ b/test/internet/test-trace-events-dns.js
@@ -49,7 +49,12 @@ for (const tr in tests) {
{ encoding: 'utf8' });
// Make sure the operation is successful.
- assert.strictEqual(proc.status, 0, `${tr}:\n${util.inspect(proc)}`);
+ // Don't use assert with a custom message here. Otherwise the
+ // inspection in the message is done eagerly and wastes a lot of CPU
+ // time.
+ if (proc.status !== 0) {
+ throw new Error(`${tr}:\n${util.inspect(proc)}`);
+ }
const file = path.join(tmpdir.path, traceFile);
diff --git a/test/parallel/test-trace-events-fs-sync.js b/test/parallel/test-trace-events-fs-sync.js
index 71ffc9da72..54222bcb33 100644
--- a/test/parallel/test-trace-events-fs-sync.js
+++ b/test/parallel/test-trace-events-fs-sync.js
@@ -136,7 +136,12 @@ for (const tr in tests) {
}
// Make sure the operation is successful.
- assert.strictEqual(proc.status, 0, `${tr}:\n${util.inspect(proc)}`);
+ // Don't use assert with a custom message here. Otherwise the
+ // inspection in the message is done eagerly and wastes a lot of CPU
+ // time.
+ if (proc.status !== 0) {
+ throw new Error(`${tr}:\n${util.inspect(proc)}`);
+ }
// Confirm that trace log file is created.
assert(fs.existsSync(traceFile));
diff --git a/test/parallel/test-worker-message-port-transfer-self.js b/test/parallel/test-worker-message-port-transfer-self.js
index 4fe12c0a88..c6f29163df 100644
--- a/test/parallel/test-worker-message-port-transfer-self.js
+++ b/test/parallel/test-worker-message-port-transfer-self.js
@@ -27,14 +27,18 @@ assert.throws(common.mustCall(() => {
port2.onmessage = common.mustCall((message) => {
assert.strictEqual(message, 2);
- assert(util.inspect(port1).includes('active: true'), util.inspect(port1));
- assert(util.inspect(port2).includes('active: true'), util.inspect(port2));
+ const inspectedPort1 = util.inspect(port1);
+ const inspectedPort2 = util.inspect(port2);
+ assert(inspectedPort1.includes('active: true'), inspectedPort1);
+ assert(inspectedPort2.includes('active: true'), inspectedPort2);
port1.close();
tick(10, () => {
- assert(util.inspect(port1).includes('active: false'), util.inspect(port1));
- assert(util.inspect(port2).includes('active: false'), util.inspect(port2));
+ const inspectedPort1 = util.inspect(port1);
+ const inspectedPort2 = util.inspect(port2);
+ assert(inspectedPort1.includes('active: false'), inspectedPort1);
+ assert(inspectedPort2.includes('active: false'), inspectedPort2);
});
});
port1.postMessage(2);