| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | ||
| 5 | 5 | /** | |
@@ -15,7 +15,7 @@ const assert = require('assert'); | |||
| 15 | 15 | * @param {string} stage the name of the stage in the test at which we are | |
| 16 | 16 | * checking the invocations | |
| 17 | 17 | */ | |
| 18 | - exports.checkInvocations = function checkInvocations(activity, hooks, stage) { | ||
| 18 | + exports.checkInvocations = common.mustCallAtLeast(function checkInvocations(activity, hooks, stage) { | ||
| 19 | 19 | const stageInfo = `Checking invocations at stage "${stage}":\n `; | |
| 20 | 20 | ||
| 21 | 21 | assert.ok(activity != null, | |
@@ -24,9 +24,7 @@ exports.checkInvocations = function checkInvocations(activity, hooks, stage) { | |||
| 24 | 24 | ); | |
| 25 | 25 | ||
| 26 | 26 | // Check that actual invocations for all hooks match the expected invocations | |
| 27 | - [ 'init', 'before', 'after', 'destroy', 'promiseResolve' ].forEach(checkHook); | ||
| 28 | - | ||
| 29 | - function checkHook(k) { | ||
| 27 | + [ 'init', 'before', 'after', 'destroy', 'promiseResolve' ].forEach((k) => { | ||
| 30 | 28 | const val = hooks[k]; | |
| 31 | 29 | // Not expected ... all good | |
| 32 | 30 | if (val == null) return; | |
@@ -49,5 +47,5 @@ exports.checkInvocations = function checkInvocations(activity, hooks, stage) { | |||
| 49 | 47 | `time(s), but expected ${val} invocation(s).`; | |
| 50 | 48 | assert.strictEqual(activity[k].length, val, msg2); | |
| 51 | 49 | } | |
| 52 | - } | ||
| 53 | - }; | ||
| 50 | + }); | ||
| 51 | + }, 0); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { | |
| 5 | 5 | executionAsyncResource, | |
@@ -22,16 +22,16 @@ const server = http.createServer((req, res) => { | |||
| 22 | 22 | }, 1000); | |
| 23 | 23 | }); | |
| 24 | 24 | ||
| 25 | - server.listen(0, () => { | ||
| 25 | + server.listen(0, common.mustCallAtLeast(() => { | ||
| 26 | 26 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 27 | - http.get({ port: server.address().port }, (res) => { | ||
| 27 | + http.get({ port: server.address().port }, common.mustCallAtLeast((res) => { | ||
| 28 | 28 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 29 | - res.on('data', () => { | ||
| 29 | + res.on('data', common.mustCallAtLeast(() => { | ||
| 30 | 30 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 31 | - }); | ||
| 32 | - res.on('end', () => { | ||
| 31 | + })); | ||
| 32 | + res.on('end', common.mustCall(() => { | ||
| 33 | 33 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 34 | 34 | server.close(); | |
| 35 | - }); | ||
| 36 | - }); | ||
| 37 | - }); | ||
| 35 | + })); | ||
| 36 | + })); | ||
| 37 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const { | |
| 6 | 6 | executionAsyncResource, | |
@@ -20,11 +20,11 @@ const server = http.createServer((req, res) => { | |||
| 20 | 20 | res.end('ok'); | |
| 21 | 21 | }); | |
| 22 | 22 | ||
| 23 | - server.listen(0, () => { | ||
| 23 | + server.listen(0, common.mustCall(() => { | ||
| 24 | 24 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 25 | 25 | ||
| 26 | - http.get({ port: server.address().port }, () => { | ||
| 26 | + http.get({ port: server.address().port }, common.mustCall(() => { | ||
| 27 | 27 | assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); | |
| 28 | 28 | server.close(); | |
| 29 | - }); | ||
| 30 | - }); | ||
| 29 | + })); | ||
| 30 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,13 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { AsyncLocalStorage } = require('async_hooks'); | |
| 5 | 5 | ||
| 6 | 6 | const asyncLocalStorage = new AsyncLocalStorage(); | |
| 7 | 7 | ||
| 8 | - asyncLocalStorage.run({}, (runArg) => { | ||
| 8 | + asyncLocalStorage.run({}, common.mustCall((runArg) => { | ||
| 9 | 9 | assert.strictEqual(runArg, 'foo'); | |
| 10 | - asyncLocalStorage.exit((exitArg) => { | ||
| 10 | + asyncLocalStorage.exit(common.mustCall((exitArg) => { | ||
| 11 | 11 | assert.strictEqual(exitArg, 'bar'); | |
| 12 | - }, 'bar'); | ||
| 13 | - }, 'foo'); | ||
| 12 | + }), 'bar'); | ||
| 13 | + }), 'foo'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | ||
| 5 | 5 | // Regression tests for https://github.com/nodejs/node/issues/40693 | |
| 6 | 6 | ||
@@ -10,17 +10,17 @@ const { AsyncLocalStorage } = require('async_hooks'); | |||
| 10 | 10 | ||
| 11 | 11 | dgram.createSocket('udp4') | |
| 12 | 12 | .on('message', function(msg, rinfo) { this.send(msg, rinfo.port); }) | |
| 13 | - .on('listening', function() { | ||
| 13 | + .on('listening', common.mustCall(function() { | ||
| 14 | 14 | const asyncLocalStorage = new AsyncLocalStorage(); | |
| 15 | 15 | const store = { val: 'abcd' }; | |
| 16 | - asyncLocalStorage.run(store, () => { | ||
| 16 | + asyncLocalStorage.run(store, common.mustCall(() => { | ||
| 17 | 17 | const client = dgram.createSocket('udp4'); | |
| 18 | - client.on('message', (msg, rinfo) => { | ||
| 18 | + client.on('message', common.mustCall((msg, rinfo) => { | ||
| 19 | 19 | assert.deepStrictEqual(asyncLocalStorage.getStore(), store); | |
| 20 | 20 | client.close(); | |
| 21 | 21 | this.close(); | |
| 22 | - }); | ||
| 22 | + })); | ||
| 23 | 23 | client.send('Hello, world!', this.address().port); | |
| 24 | - }); | ||
| 25 | - }) | ||
| 24 | + })); | ||
| 25 | + })) | ||
| 26 | 26 | .bind(0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { AsyncLocalStorage } = require('async_hooks'); | |
| 5 | 5 | ||
| 6 | 6 | const asyncLocalStorage = new AsyncLocalStorage(); | |
| 7 | 7 | ||
| 8 | - asyncLocalStorage.run(new Map(), () => { | ||
| 8 | + asyncLocalStorage.run(new Map(), common.mustCall(() => { | ||
| 9 | 9 | asyncLocalStorage.getStore().set('foo', 'bar'); | |
| 10 | 10 | process.nextTick(() => { | |
| 11 | 11 | assert.strictEqual(asyncLocalStorage.getStore().get('foo'), 'bar'); | |
@@ -17,16 +17,16 @@ asyncLocalStorage.run(new Map(), () => { | |||
| 17 | 17 | assert.strictEqual(asyncLocalStorage.getStore(), undefined); | |
| 18 | 18 | ||
| 19 | 19 | // Calls to exit() should not mess with enabled status | |
| 20 | - asyncLocalStorage.exit(() => { | ||
| 20 | + asyncLocalStorage.exit(common.mustCall(() => { | ||
| 21 | 21 | assert.strictEqual(asyncLocalStorage.getStore(), undefined); | |
| 22 | - }); | ||
| 22 | + })); | ||
| 23 | 23 | assert.strictEqual(asyncLocalStorage.getStore(), undefined); | |
| 24 | 24 | ||
| 25 | 25 | process.nextTick(() => { | |
| 26 | 26 | assert.strictEqual(asyncLocalStorage.getStore(), undefined); | |
| 27 | - asyncLocalStorage.run(new Map().set('bar', 'foo'), () => { | ||
| 27 | + asyncLocalStorage.run(new Map().set('bar', 'foo'), common.mustCall(() => { | ||
| 28 | 28 | assert.strictEqual(asyncLocalStorage.getStore().get('bar'), 'foo'); | |
| 29 | - }); | ||
| 29 | + })); | ||
| 30 | 30 | }); | |
| 31 | 31 | }); | |
| 32 | - }); | ||
| 32 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,20 +1,20 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { AsyncLocalStorage } = require('async_hooks'); | |
| 5 | 5 | ||
| 6 | 6 | const asyncLocalStorage = new AsyncLocalStorage(); | |
| 7 | 7 | ||
| 8 | - setImmediate(() => { | ||
| 8 | + setImmediate(common.mustCall(() => { | ||
| 9 | 9 | const store = { foo: 'bar' }; | |
| 10 | 10 | asyncLocalStorage.enterWith(store); | |
| 11 | 11 | ||
| 12 | 12 | assert.strictEqual(asyncLocalStorage.getStore(), store); | |
| 13 | - setTimeout(() => { | ||
| 13 | + setTimeout(common.mustCall(() => { | ||
| 14 | 14 | assert.strictEqual(asyncLocalStorage.getStore(), store); | |
| 15 | - }, 10); | ||
| 16 | - }); | ||
| 15 | + }), 10); | ||
| 16 | + })); | ||
| 17 | 17 | ||
| 18 | - setTimeout(() => { | ||
| 18 | + setTimeout(common.mustCall(() => { | ||
| 19 | 19 | assert.strictEqual(asyncLocalStorage.getStore(), undefined); | |
| 20 | - }, 10); | ||
| 20 | + }), 10); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,11 @@ const { onGC } = require('../common/gc'); | |||
| 11 | 11 | ||
| 12 | 12 | let asyncLocalStorage = new AsyncLocalStorage(); | |
| 13 | 13 | ||
| 14 | - asyncLocalStorage.run({}, () => { | ||
| 14 | + asyncLocalStorage.run({}, common.mustCall(() => { | ||
| 15 | 15 | asyncLocalStorage.disable(); | |
| 16 | 16 | ||
| 17 | 17 | onGC(asyncLocalStorage, { ongc: common.mustCall() }); | |
| 18 | - }); | ||
| 18 | + })); | ||
| 19 | 19 | ||
| 20 | 20 | if (AsyncContextFrame.enabled) { | |
| 21 | 21 | // This disable() is needed to remove reference form AsyncContextFrame | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ server.listen(0, common.mustCall(() => { | |||
| 21 | 21 | const port = server.address().port; | |
| 22 | 22 | ||
| 23 | 23 | for (let i = 0; i < N; i++) { | |
| 24 | - asyncLocalStorage.run(i, () => { | ||
| 24 | + asyncLocalStorage.run(i, common.mustCall(() => { | ||
| 25 | 25 | http.get({ agent, port }, common.mustCall((res) => { | |
| 26 | 26 | assert.strictEqual(asyncLocalStorage.getStore(), i); | |
| 27 | 27 | if (++responses === N) { | |
@@ -30,6 +30,6 @@ server.listen(0, common.mustCall(() => { | |||
| 30 | 30 | } | |
| 31 | 31 | res.resume(); | |
| 32 | 32 | })); | |
| 33 | - }); | ||
| 33 | + })); | ||
| 34 | 34 | } | |
| 35 | 35 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const { mustCall } = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { AsyncLocalStorage } = require('async_hooks'); | |
| 5 | 5 | const http = require('http'); | |
@@ -13,9 +13,9 @@ server.listen(0, () => { | |||
| 13 | 13 | asyncLocalStorage.run(new Map(), () => { | |
| 14 | 14 | const store = asyncLocalStorage.getStore(); | |
| 15 | 15 | store.set('hello', 'world'); | |
| 16 | - http.get({ host: 'localhost', port: server.address().port }, () => { | ||
| 16 | + http.get({ host: 'localhost', port: server.address().port }, mustCall(() => { | ||
| 17 | 17 | assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world'); | |
| 18 | 18 | server.close(); | |
| 19 | - }); | ||
| 19 | + })); | ||
| 20 | 20 | }); | |
| 21 | 21 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments