forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-worker-environmentdata.js
More file actions
33 lines (29 loc) · 902 Bytes
/
test-worker-environmentdata.js
File metadata and controls
33 lines (29 loc) · 902 Bytes
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
'use strict';
require('../common');
const {
Worker,
getEnvironmentData,
setEnvironmentData,
threadId,
} = require('worker_threads');
const {
deepStrictEqual,
strictEqual,
} = require('assert');
if (!process.env.HAS_STARTED_WORKER) {
process.env.HAS_STARTED_WORKER = 1;
setEnvironmentData('foo', 'bar');
setEnvironmentData('hello', { value: 'world' });
setEnvironmentData(1, 2);
strictEqual(getEnvironmentData(1), 2);
setEnvironmentData(1); // Delete it, key won't show up in the worker.
new Worker(__filename);
setEnvironmentData('hello'); // Delete it. Has no impact on the worker.
} else {
strictEqual(getEnvironmentData('foo'), 'bar');
deepStrictEqual(getEnvironmentData('hello'), { value: 'world' });
strictEqual(getEnvironmentData(1), undefined);
// Recurse to make sure the environment data is inherited
if (threadId <= 2)
new Worker(__filename);
}