提交 d483315e 编写于 作者: B Benjamin Pasero

add a test for the free port finder

上级 53e6c567
/*---------------------------------------------------------------------------------------------
* 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', function (done: () => void) {
// get an initial freeport >= 7000
ports.findFreePort(7000, 100, (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, (freePort) => {
assert.ok(freePort >= 7000 && freePort !== initialPort);
server.close();
done();
});
});
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册