aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBamieh <ahmadbamieh@gmail.com>2017-11-21 20:33:16 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-16 18:32:59 +0100
commit941bc93f2229d4a28c3d3246878c7fd4fbf443ec (patch)
tree63db8a75e2e7940878ef308f205e6395a7e03f2e /test
parent96c57fbfaa8c1644648fa1414c9ad131b1320b60 (diff)
downloadandroid-node-v8-941bc93f2229d4a28c3d3246878c7fd4fbf443ec.tar.gz
android-node-v8-941bc93f2229d4a28c3d3246878c7fd4fbf443ec.tar.bz2
android-node-v8-941bc93f2229d4a28c3d3246878c7fd4fbf443ec.zip
test: wrap countdown callback in common.mustCall
This adds a implicit common.mustCall to the callback provided to the countdown. PR-URL: https://github.com/nodejs/node/pull/18506 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/common/README.md2
-rw-r--r--test/common/countdown.js3
-rw-r--r--test/fixtures/failcounter.js2
-rw-r--r--test/parallel/test-common-countdown.js22
-rw-r--r--test/parallel/test-http-after-connect.js2
-rw-r--r--test/parallel/test-http-agent-destroyed-socket.js2
-rw-r--r--test/parallel/test-http-agent-maxsockets-regress-4050.js2
-rw-r--r--test/parallel/test-http-agent-maxsockets.js4
-rw-r--r--test/parallel/test-http-client-abort.js6
-rw-r--r--test/parallel/test-http-client-parse-error.js2
-rw-r--r--test/parallel/test-http-exceptions.js23
-rw-r--r--test/parallel/test-http2-no-more-streams.js4
-rw-r--r--test/parallel/test-http2-server-rst-stream.js4
-rw-r--r--test/parallel/test-performanceobserver.js4
-rw-r--r--test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js2
15 files changed, 55 insertions, 29 deletions
diff --git a/test/common/README.md b/test/common/README.md
index 73779fd537..f0bbe7d13d 100644
--- a/test/common/README.md
+++ b/test/common/README.md
@@ -380,7 +380,7 @@ Synchronous version of `spawnPwd`.
The `Countdown` module provides a simple countdown mechanism for tests that
require a particular action to be taken after a given number of completed
tasks (for instance, shutting down an HTTP server after a specific number of
-requests).
+requests). The Countdown will fail the test if the remainder did not reach 0.
<!-- eslint-disable strict, required-modules -->
```js
diff --git a/test/common/countdown.js b/test/common/countdown.js
index 93bdbbfb16..5fcb77c4ed 100644
--- a/test/common/countdown.js
+++ b/test/common/countdown.js
@@ -4,13 +4,14 @@
const assert = require('assert');
const kLimit = Symbol('limit');
const kCallback = Symbol('callback');
+const common = require('./');
class Countdown {
constructor(limit, cb) {
assert.strictEqual(typeof limit, 'number');
assert.strictEqual(typeof cb, 'function');
this[kLimit] = limit;
- this[kCallback] = cb;
+ this[kCallback] = common.mustCall(cb);
}
dec() {
diff --git a/test/fixtures/failcounter.js b/test/fixtures/failcounter.js
new file mode 100644
index 0000000000..f3bc34a730
--- /dev/null
+++ b/test/fixtures/failcounter.js
@@ -0,0 +1,2 @@
+const Countdown = require('../common/countdown');
+new Countdown(2, () => {});
diff --git a/test/parallel/test-common-countdown.js b/test/parallel/test-common-countdown.js
index ec0543f36f..6a1a2f1bbc 100644
--- a/test/parallel/test-common-countdown.js
+++ b/test/parallel/test-common-countdown.js
@@ -3,13 +3,31 @@
const common = require('../common');
const assert = require('assert');
const Countdown = require('../common/countdown');
+const fixtures = require('../common/fixtures');
+const { execFile } = require('child_process');
let done = '';
-
-const countdown = new Countdown(2, common.mustCall(() => done = true));
+const countdown = new Countdown(2, () => done = true);
assert.strictEqual(countdown.remaining, 2);
countdown.dec();
assert.strictEqual(countdown.remaining, 1);
countdown.dec();
assert.strictEqual(countdown.remaining, 0);
assert.strictEqual(done, true);
+
+const failFixtures = [
+ [
+ fixtures.path('failcounter.js'),
+ 'Mismatched <anonymous> function calls. Expected exactly 1, actual 0.',
+ ]
+];
+
+for (const p of failFixtures) {
+ const [file, expected] = p;
+ execFile(process.argv[0], [file], common.mustCall((ex, stdout, stderr) => {
+ assert.ok(ex);
+ assert.strictEqual(stderr, '');
+ const firstLine = stdout.split('\n').shift();
+ assert.strictEqual(firstLine, expected);
+ }));
+}
diff --git a/test/parallel/test-http-after-connect.js b/test/parallel/test-http-after-connect.js
index 324186bab7..d209c82083 100644
--- a/test/parallel/test-http-after-connect.js
+++ b/test/parallel/test-http-after-connect.js
@@ -32,7 +32,7 @@ const server = http.createServer(common.mustCall((req, res) => {
setTimeout(() => res.end(req.url), 50);
}, 2));
-const countdown = new Countdown(2, common.mustCall(() => server.close()));
+const countdown = new Countdown(2, () => server.close());
server.on('connect', common.mustCall((req, socket) => {
socket.write('HTTP/1.1 200 Connection established\r\n\r\n');
diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js
index 7970ce8bae..39f4ebef53 100644
--- a/test/parallel/test-http-agent-destroyed-socket.js
+++ b/test/parallel/test-http-agent-destroyed-socket.js
@@ -80,7 +80,7 @@ const server = http.createServer(common.mustCall((req, res) => {
assert(request1.socket.destroyed);
// assert not reusing the same socket, since it was destroyed.
assert.notStrictEqual(request1.socket, request2.socket);
- const countdown = new Countdown(2, common.mustCall(() => server.close()));
+ const countdown = new Countdown(2, () => server.close());
request2.socket.on('close', common.mustCall(() => countdown.dec()));
response.on('end', common.mustCall(() => countdown.dec()));
response.resume();
diff --git a/test/parallel/test-http-agent-maxsockets-regress-4050.js b/test/parallel/test-http-agent-maxsockets-regress-4050.js
index 57a90e4b05..eb1c95d520 100644
--- a/test/parallel/test-http-agent-maxsockets-regress-4050.js
+++ b/test/parallel/test-http-agent-maxsockets-regress-4050.js
@@ -17,7 +17,7 @@ const server = http.createServer(common.mustCall((req, res) => {
res.end('hello world');
}, 6));
-const countdown = new Countdown(6, common.mustCall(() => server.close()));
+const countdown = new Countdown(6, () => server.close());
function get(path, callback) {
return http.get({
diff --git a/test/parallel/test-http-agent-maxsockets.js b/test/parallel/test-http-agent-maxsockets.js
index 4d422f4a90..267f820e04 100644
--- a/test/parallel/test-http-agent-maxsockets.js
+++ b/test/parallel/test-http-agent-maxsockets.js
@@ -26,13 +26,13 @@ function get(path, callback) {
}, callback);
}
-const countdown = new Countdown(2, common.mustCall(() => {
+const countdown = new Countdown(2, () => {
const freepool = agent.freeSockets[Object.keys(agent.freeSockets)[0]];
assert.strictEqual(freepool.length, 2,
`expect keep 2 free sockets, but got ${freepool.length}`);
agent.destroy();
server.close();
-}));
+});
function dec() {
process.nextTick(() => countdown.dec());
diff --git a/test/parallel/test-http-client-abort.js b/test/parallel/test-http-client-abort.js
index 71fd2ad64c..f767189ea9 100644
--- a/test/parallel/test-http-client-abort.js
+++ b/test/parallel/test-http-client-abort.js
@@ -26,7 +26,7 @@ const Countdown = require('../common/countdown');
const N = 8;
-const countdown = new Countdown(N, common.mustCall(() => server.close()));
+const countdown = new Countdown(N, () => server.close());
const server = http.Server(common.mustCall((req, res) => {
res.writeHead(200);
@@ -37,9 +37,9 @@ const server = http.Server(common.mustCall((req, res) => {
server.listen(0, common.mustCall(() => {
const requests = [];
- const reqCountdown = new Countdown(N, common.mustCall(() => {
+ const reqCountdown = new Countdown(N, () => {
requests.forEach((req) => req.abort());
- }));
+ });
const options = { port: server.address().port };
diff --git a/test/parallel/test-http-client-parse-error.js b/test/parallel/test-http-client-parse-error.js
index 60f1ee45c8..cb4e3ff084 100644
--- a/test/parallel/test-http-client-parse-error.js
+++ b/test/parallel/test-http-client-parse-error.js
@@ -25,7 +25,7 @@ const http = require('http');
const net = require('net');
const Countdown = require('../common/countdown');
-const countdown = new Countdown(2, common.mustCall(() => server.close()));
+const countdown = new Countdown(2, () => server.close());
const payloads = [
'HTTP/1.1 302 Object Moved\r\nContent-Length: 0\r\n\r\nhi world',
diff --git a/test/parallel/test-http-exceptions.js b/test/parallel/test-http-exceptions.js
index 0b6ac5bdc1..03e30b67e1 100644
--- a/test/parallel/test-http-exceptions.js
+++ b/test/parallel/test-http-exceptions.js
@@ -21,7 +21,12 @@
'use strict';
require('../common');
+const Countdown = require('../common/countdown');
const http = require('http');
+const NUMBER_OF_EXCEPTIONS = 4;
+const countdown = new Countdown(NUMBER_OF_EXCEPTIONS, () => {
+ process.exit(0);
+});
const server = http.createServer(function(req, res) {
intentionally_not_defined(); // eslint-disable-line no-undef
@@ -30,16 +35,16 @@ const server = http.createServer(function(req, res) {
res.end();
});
+function onUncaughtException(err) {
+ console.log(`Caught an exception: ${err}`);
+ if (err.name === 'AssertionError') throw err;
+ countdown.dec();
+}
+
+process.on('uncaughtException', onUncaughtException);
+
server.listen(0, function() {
- for (let i = 0; i < 4; i += 1) {
+ for (let i = 0; i < NUMBER_OF_EXCEPTIONS; i += 1) {
http.get({ port: this.address().port, path: `/busy/${i}` });
}
});
-
-let exception_count = 0;
-
-process.on('uncaughtException', function(err) {
- console.log(`Caught an exception: ${err}`);
- if (err.name === 'AssertionError') throw err;
- if (++exception_count === 4) process.exit(0);
-});
diff --git a/test/parallel/test-http2-no-more-streams.js b/test/parallel/test-http2-no-more-streams.js
index dd06a709f2..ff0c8baa14 100644
--- a/test/parallel/test-http2-no-more-streams.js
+++ b/test/parallel/test-http2-no-more-streams.js
@@ -23,10 +23,10 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(client.state.nextStreamID, nextID);
- const countdown = new Countdown(2, common.mustCall(() => {
+ const countdown = new Countdown(2, () => {
server.close();
client.close();
- }));
+ });
{
// This one will be ok
diff --git a/test/parallel/test-http2-server-rst-stream.js b/test/parallel/test-http2-server-rst-stream.js
index c2d938c22f..4b59a5ebe8 100644
--- a/test/parallel/test-http2-server-rst-stream.js
+++ b/test/parallel/test-http2-server-rst-stream.js
@@ -32,10 +32,10 @@ server.on('stream', (stream, headers) => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
- const countdown = new Countdown(tests.length, common.mustCall(() => {
+ const countdown = new Countdown(tests.length, () => {
client.close();
server.close();
- }));
+ });
tests.forEach((test) => {
const req = client.request({
diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js
index 196675d1f5..2a62999522 100644
--- a/test/parallel/test-performanceobserver.js
+++ b/test/parallel/test-performanceobserver.js
@@ -65,10 +65,10 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
new PerformanceObserver(common.mustCall(callback, 3));
const countdown =
- new Countdown(3, common.mustCall(() => {
+ new Countdown(3, () => {
observer.disconnect();
assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 1);
- }));
+ });
function callback(list, obs) {
assert.strictEqual(obs, observer);
diff --git a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js
index 842c818070..5dceb386fd 100644
--- a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js
+++ b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js
@@ -33,7 +33,7 @@ const server = net.createServer(function onClient(client) {
});
server.listen(0, common.localhostIPv4, common.mustCall(() => {
- const countdown = new Countdown(2, common.mustCall(() => server.close()));
+ const countdown = new Countdown(2, () => server.close());
{
const client = net.connect({ port: server.address().port });