Path: blob/main/src/vs/base/test/node/processes/processes.integrationTest.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import * as cp from 'child_process';7import { FileAccess } from '../../../common/network.js';8import * as objects from '../../../common/objects.js';9import * as platform from '../../../common/platform.js';10import * as processes from '../../../node/processes.js';1112function fork(id: string): cp.ChildProcess {13const opts: any = {14env: objects.mixin(objects.deepClone(process.env), {15VSCODE_ESM_ENTRYPOINT: id,16VSCODE_PIPE_LOGGING: 'true',17VSCODE_VERBOSE_LOGGING: true18})19};2021return cp.fork(FileAccess.asFileUri('bootstrap-fork').fsPath, ['--type=processTests'], opts);22}2324suite('Processes', () => {25test('buffered sending - simple data', function (done: () => void) {26if (process.env['VSCODE_PID']) {27return done(); // this test fails when run from within VS Code28}2930const child = fork('vs/base/test/node/processes/fixtures/fork');31const sender = processes.createQueuedSender(child);3233let counter = 0;3435const msg1 = 'Hello One';36const msg2 = 'Hello Two';37const msg3 = 'Hello Three';3839child.on('message', msgFromChild => {40if (msgFromChild === 'ready') {41sender.send(msg1);42sender.send(msg2);43sender.send(msg3);44} else {45counter++;4647if (counter === 1) {48assert.strictEqual(msgFromChild, msg1);49} else if (counter === 2) {50assert.strictEqual(msgFromChild, msg2);51} else if (counter === 3) {52assert.strictEqual(msgFromChild, msg3);5354child.kill();55done();56}57}58});59});6061(!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 builds62const child = fork('vs/base/test/node/processes/fixtures/fork_large');63const sender = processes.createQueuedSender(child);6465const largeObj = Object.create(null);66for (let i = 0; i < 10000; i++) {67largeObj[i] = 'some data';68}6970const msg = JSON.stringify(largeObj);71child.on('message', msgFromChild => {72if (msgFromChild === 'ready') {73sender.send(msg);74sender.send(msg);75sender.send(msg);76} else if (msgFromChild === 'done') {77child.kill();78done();79}80});81});82});838485