Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/port.test.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 net from 'net';
8
import * as ports from '../../node/ports.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
10
import { flakySuite } from './testUtils.js';
11
12
flakySuite('Ports', () => {
13
(process.env['VSCODE_PID'] ? test.skip /* this test fails when run from within VS Code */ : test)('Finds a free port (no timeout)', function (done) {
14
15
// get an initial freeport >= 7000
16
ports.findFreePort(7000, 100, 300000).then(initialPort => {
17
assert.ok(initialPort >= 7000);
18
19
// create a server to block this port
20
const server = net.createServer();
21
server.listen(initialPort, undefined, undefined, () => {
22
23
// once listening, find another free port and assert that the port is different from the opened one
24
ports.findFreePort(7000, 50, 300000).then(freePort => {
25
assert.ok(freePort >= 7000 && freePort !== initialPort);
26
server.close();
27
28
done();
29
}, err => done(err));
30
});
31
}, err => done(err));
32
});
33
34
ensureNoDisposablesAreLeakedInTestSuite();
35
});
36
37