Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/processes/processes.integrationTest.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import * as cp from 'child_process';
8
import { FileAccess } from '../../../common/network.js';
9
import * as objects from '../../../common/objects.js';
10
import * as platform from '../../../common/platform.js';
11
import * as processes from '../../../node/processes.js';
12
13
function fork(id: string): cp.ChildProcess {
14
const opts: any = {
15
env: objects.mixin(objects.deepClone(process.env), {
16
VSCODE_ESM_ENTRYPOINT: id,
17
VSCODE_PIPE_LOGGING: 'true',
18
VSCODE_VERBOSE_LOGGING: true
19
})
20
};
21
22
return cp.fork(FileAccess.asFileUri('bootstrap-fork').fsPath, ['--type=processTests'], opts);
23
}
24
25
suite('Processes', () => {
26
test('buffered sending - simple data', function (done: () => void) {
27
if (process.env['VSCODE_PID']) {
28
return done(); // this test fails when run from within VS Code
29
}
30
31
const child = fork('vs/base/test/node/processes/fixtures/fork');
32
const sender = processes.createQueuedSender(child);
33
34
let counter = 0;
35
36
const msg1 = 'Hello One';
37
const msg2 = 'Hello Two';
38
const msg3 = 'Hello Three';
39
40
child.on('message', msgFromChild => {
41
if (msgFromChild === 'ready') {
42
sender.send(msg1);
43
sender.send(msg2);
44
sender.send(msg3);
45
} else {
46
counter++;
47
48
if (counter === 1) {
49
assert.strictEqual(msgFromChild, msg1);
50
} else if (counter === 2) {
51
assert.strictEqual(msgFromChild, msg2);
52
} else if (counter === 3) {
53
assert.strictEqual(msgFromChild, msg3);
54
55
child.kill();
56
done();
57
}
58
}
59
});
60
});
61
62
(!platform.isWindows || process.env['VSCODE_PID'] ? test.skip : test)('buffered sending - lots of data (potential deadlock on win32)', function (done: () => void) { // test is only relevant for Windows and seems to crash randomly on some Linux builds
63
const child = fork('vs/base/test/node/processes/fixtures/fork_large');
64
const sender = processes.createQueuedSender(child);
65
66
const largeObj = Object.create(null);
67
for (let i = 0; i < 10000; i++) {
68
largeObj[i] = 'some data';
69
}
70
71
const msg = JSON.stringify(largeObj);
72
child.on('message', msgFromChild => {
73
if (msgFromChild === 'ready') {
74
sender.send(msg);
75
sender.send(msg);
76
sender.send(msg);
77
} else if (msgFromChild === 'done') {
78
child.kill();
79
done();
80
}
81
});
82
});
83
});
84
85