forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport.test.ts
More file actions
36 lines (29 loc) · 1.21 KB
/
port.test.ts
File metadata and controls
36 lines (29 loc) · 1.21 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
/*---------------------------------------------------------------------------------------------
* 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 net from 'net';
import ports = require('vs/base/node/ports');
suite('Ports', () => {
test('Finds a free port (no timeout)', function (done: () => void) {
if (process.env['VSCODE_PID']) {
return done(); // TODO@Ben find out why test fails when run from within VS Code
}
// get an initial freeport >= 7000
ports.findFreePort(7000, 100, 300000, (initialPort) => {
assert.ok(initialPort >= 7000);
// create a server to block this port
const server = net.createServer();
server.listen(initialPort, null, null, () => {
// once listening, find another free port and assert that the port is different from the opened one
ports.findFreePort(7000, 50, 300000, (freePort) => {
assert.ok(freePort >= 7000 && freePort !== initialPort);
server.close();
done();
});
});
});
});
});