-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-timeout.js
30 lines (27 loc) · 915 Bytes
/
test-timeout.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
var common = require('../common');
var assert = require('assert');
var net = require('net');
var LazySocket = common.LazySocket;
var wasClosed = false;
var server = net.createServer(function(socket) {
// when a connection is received, close it after 1 second as a
// cleanup step. our test should have done its thing by then.
setTimeout(function() {
socket.end();
server.close();
}, 1000);
socket.once('end', function() {
wasClosed = true;
});
});
server.listen(common.port, function() {
var socket = LazySocket.createConnection(common.port, undefined /* host */, 250 /* timeout */);
socket._lazyConnect();
// socket is now open and should timeout after 250ms of idleness.
assert.ok(!wasClosed);
setTimeout(function() {
// socket should have timed out after 250ms which was about 250ms ago.
assert.ok(wasClosed);
socket.destroy();
}, 500);
});