GeezerVison is showing github.com — test: regression tests for async_hooks + Promise + Worker interaction · nodejs/node@b93a723
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const { Worker } = require('worker_threads'); |
| 4 | + |
| 5 | +const w = new Worker(` |
| 6 | +const { createHook } = require('async_hooks'); |
| 7 | +
|
| 8 | +setImmediate(async () => { |
| 9 | + createHook({ init() {} }).enable(); |
| 10 | + await 0; |
| 11 | + process.exit(); |
| 12 | +}); |
| 13 | +`, { eval: true }); |
| 14 | + |
| 15 | +w.on('exit', common.mustCall()); |
Collapse file
Copy file name to clipboard +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const { Worker } = require('worker_threads'); |
| 4 | + |
| 5 | +// Like test-async-hooks-worker-promise.js but with the `await` and `createHook` |
| 6 | +// lines switched, because that resulted in different assertion failures |
| 7 | +// (one a Node.js assertion and one a V8 DCHECK) and it seems prudent to |
| 8 | +// cover both of those failures. |
| 9 | + |
| 10 | +const w = new Worker(` |
| 11 | +const { createHook } = require('async_hooks'); |
| 12 | +
|
| 13 | +setImmediate(async () => { |
| 14 | + await 0; |
| 15 | + createHook({ init() {} }).enable(); |
| 16 | + process.exit(); |
| 17 | +}); |
| 18 | +`, { eval: true }); |
| 19 | + |
| 20 | +w.postMessage({}); |
| 21 | +w.on('exit', common.mustCall()); |
Collapse file
Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const { Worker } = require('worker_threads'); |
| 4 | + |
| 5 | +// Like test-async-hooks-worker-promise.js but with an additional statement |
| 6 | +// after the `process.exit()` call, that shouldn’t really make a difference |
| 7 | +// but apparently does. |
| 8 | + |
| 9 | +const w = new Worker(` |
| 10 | +const { createHook } = require('async_hooks'); |
| 11 | +
|
| 12 | +setImmediate(async () => { |
| 13 | + createHook({ init() {} }).enable(); |
| 14 | + await 0; |
| 15 | + process.exit(); |
| 16 | + process._rawDebug('THIS SHOULD NEVER BE REACHED'); |
| 17 | +}); |
| 18 | +`, { eval: true }); |
| 19 | + |
| 20 | +w.on('exit', common.mustCall()); |
Collapse file
Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const { Worker } = require('worker_threads'); |
| 5 | + |
| 6 | +// Like test-async-hooks-worker-promise.js but doing a trivial counter increase |
| 7 | +// after process.exit(). This should not make a difference, but apparently it |
| 8 | +// does. This is *also* different from test-async-hooks-worker-promise-3.js, |
| 9 | +// in that the statement is an ArrayBuffer access rather than a full method, |
| 10 | +// which *also* makes a difference even though it shouldn’t. |
| 11 | + |
| 12 | +const workerData = new Int32Array(new SharedArrayBuffer(4)); |
| 13 | +const w = new Worker(` |
| 14 | +const { createHook } = require('async_hooks'); |
| 15 | +
|
| 16 | +setImmediate(async () => { |
| 17 | + createHook({ init() {} }).enable(); |
| 18 | + await 0; |
| 19 | + process.exit(); |
| 20 | + workerData[0]++; |
| 21 | +}); |
| 22 | +`, { eval: true, workerData }); |
| 23 | + |
| 24 | +w.on('exit', common.mustCall(() => assert.strictEqual(workerData[0], 0))); |