forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 1.18 KB
/
test.js
File metadata and controls
36 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const common = require('../../common');
if (common.isAIX || common.isIBMi) {
// see: https://github.com/libuv/libuv/pull/4599#issuecomment-2498376606
common.skip('AIX, IBM i do not support get/set thread name');
}
const assert = require('node:assert');
const { parentPort, Worker, isMainThread } = require('node:worker_threads');
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const binding = require(bindingPath);
if (isMainThread) {
assert.strictEqual(binding.getThreadName(), 'node-MainThread');
const worker = new Worker(__filename);
worker.on('message', common.mustCall((data) => {
assert.strictEqual(data, 'WorkerThread');
}));
worker.on('error', common.mustNotCall());
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
const namedWorker = new Worker(__filename, { name: 'NamedThread' });
namedWorker.on('message', common.mustCall((data) => {
assert.strictEqual(data, 'NamedThread');
}));
namedWorker.on('error', common.mustNotCall());
namedWorker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
} else {
parentPort.postMessage(binding.getThreadName());
}