-
Notifications
You must be signed in to change notification settings - Fork 576
/
test-net-server-call-listen-multiple-times.js
56 lines (44 loc) · 1.39 KB
/
test-net-server-call-listen-multiple-times.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
// TODO: support net.Server() without new
// First test. Check that after error event you can listen right away.
{
const dummyServer = new net.Server();
const server = new net.Server();
// Run some server in order to simulate EADDRINUSE error.
dummyServer.listen(common.mustCall(() => {
// Try to listen used port.
server.listen(dummyServer.address().port);
}));
server.on('error', common.mustCall((e) => {
server.listen(common.mustCall(() => {
dummyServer.close();
server.close();
}));
}));
}
// Second test. Check that second listen call throws an error.
{
const server = new net.Server();
server.listen(common.mustCall(() => server.close()));
assert.throws(() => server.listen(), {
code: 'ERR_SERVER_ALREADY_LISTEN',
name: 'Error'
});
}
// Third test.
// Check that after the close call you can run listen method just fine.
{
const server = new net.Server();
server.listen(common.mustCall(() => {
server.close();
server.listen(common.mustCall(() => server.close()));
}));
}