Skip to content

Commit 3d09ddc

Browse files
zherczegyichoi
authored andcommitted
Rework test_net_10.js. (#962)
Does not depend on lookup timeout anymore. IoT.js-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 29af137 commit 3d09ddc

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

test/run_pass/test_net_10.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,40 @@
1616
var net = require('net');
1717
var assert = require('assert');
1818

19+
var server = net.createServer();
20+
var port = 22709;
21+
1922
var timedout = false;
2023
var connected = false;
2124

22-
// Try connect to host that is not exist (Reserved address of TEST-NET-1)
23-
var socket1 = net.createConnection(11111, '192.0.2.1');
25+
server.listen(port, 1);
2426

25-
socket1.setTimeout(1000);
27+
server.on('connection', function(newSocket) {
28+
connected = true;
29+
console.log("Connected!");
2630

27-
socket1.on('timeout', function() {
28-
timedout = true;
29-
socket1.destroy();
30-
});
31+
newSocket.on('error', function() {
32+
assert.fail();
33+
});
3134

32-
socket1.on('error', function() {
33-
assert.fail();
35+
newSocket.setTimeout(500);
36+
37+
newSocket.on('timeout', function() {
38+
console.log("Timeout");
39+
timedout = true;
40+
newSocket.destroy();
41+
socket.destroy();
42+
server.close();
43+
});
3444
});
3545

36-
socket1.on('connect', function() {
37-
connected = true;
38-
socket1.destroy();
46+
var socket = net.createConnection(port);
47+
48+
socket.on('error', function() {
49+
assert.fail();
3950
});
4051

4152
process.on('exit', function() {
4253
assert(timedout);
43-
assert(!connected);
54+
assert(connected);
4455
});

0 commit comments

Comments
 (0)