-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13763 from Microsoft/ben/buffered-process-send
Add a queue for process.send
- Loading branch information
Showing
6 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import processes = require('vs/base/node/processes'); | ||
|
||
const sender = processes.createQueuedSender(process); | ||
|
||
process.on('message', msg => { | ||
sender.send(msg); | ||
}); | ||
|
||
sender.send('ready'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import processes = require('vs/base/node/processes'); | ||
|
||
const sender = processes.createQueuedSender(process); | ||
|
||
process.on('message', msg => { | ||
sender.send(msg); | ||
sender.send(msg); | ||
sender.send(msg); | ||
sender.send('done'); | ||
}); | ||
|
||
sender.send('ready'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import * as assert from 'assert'; | ||
import * as cp from 'child_process'; | ||
import * as objects from 'vs/base/common/objects'; | ||
import URI from 'vs/base/common/uri'; | ||
import processes = require('vs/base/node/processes'); | ||
|
||
function fork(id: string): cp.ChildProcess { | ||
const opts: any = { | ||
env: objects.mixin(objects.clone(process.env), { | ||
AMD_ENTRYPOINT: id, | ||
PIPE_LOGGING: 'true', | ||
VERBOSE_LOGGING: true | ||
}) | ||
}; | ||
|
||
return cp.fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=processTests'], opts); | ||
} | ||
|
||
suite('Processes', () => { | ||
test('buffered sending - simple data', function (done: () => void) { | ||
const child = fork('vs/base/test/node/processes/fixtures/fork'); | ||
const sender = processes.createQueuedSender(child); | ||
|
||
let counter = 0; | ||
|
||
const msg1 = 'Hello One'; | ||
const msg2 = 'Hello Two'; | ||
const msg3 = 'Hello Three'; | ||
|
||
child.on('message', msgFromChild => { | ||
if (msgFromChild === 'ready') { | ||
sender.send(msg1); | ||
sender.send(msg2); | ||
sender.send(msg3); | ||
} else { | ||
counter++; | ||
|
||
if (counter === 1) { | ||
assert.equal(msgFromChild, msg1); | ||
} else if (counter === 2) { | ||
assert.equal(msgFromChild, msg2); | ||
} else if (counter === 3) { | ||
assert.equal(msgFromChild, msg3); | ||
|
||
child.kill(); | ||
done(); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
test('buffered sending - lots of data (potential deadlock on win32)', function (done: () => void) { | ||
const child = fork('vs/base/test/node/processes/fixtures/fork_large'); | ||
const sender = processes.createQueuedSender(child); | ||
|
||
const largeObj = Object.create(null); | ||
for (let i = 0; i < 10000; i++) { | ||
largeObj[i] = 'some data'; | ||
} | ||
|
||
const msg = JSON.stringify(largeObj); | ||
child.on('message', msgFromChild => { | ||
if (msgFromChild === 'ready') { | ||
sender.send(msg); | ||
sender.send(msg); | ||
sender.send(msg); | ||
} else if (msgFromChild === 'done') { | ||
child.kill(); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters