-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathstartup-tests.js
84 lines (69 loc) · 1.94 KB
/
startup-tests.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
require(__dirname + '/test-helper')
var Connection = require(__dirname + '/../../../lib/connection')
test('connection can take existing stream', function () {
var stream = new MemoryStream()
var con = new Connection({stream: stream})
assert.equal(con.stream, stream)
})
test('using closed stream', function () {
var makeStream = function () {
var stream = new MemoryStream()
stream.readyState = 'closed'
stream.connect = function (port, host) {
this.connectCalled = true
this.port = port
this.host = host
}
return stream
}
var stream = makeStream()
var con = new Connection({stream: stream})
con.connect(1234, 'bang')
test('makes stream connect', function () {
assert.equal(stream.connectCalled, true)
})
test('uses configured port', function () {
assert.equal(stream.port, 1234)
})
test('uses configured host', function () {
assert.equal(stream.host, 'bang')
})
test('after stream connects client emits connected event', function () {
var hit = false
con.once('connect', function () {
hit = true
})
assert.ok(stream.emit('connect'))
assert.ok(hit)
})
test('after stream emits connected event init TCP-keepalive', function () {
var stream = makeStream()
var con = new Connection({ stream: stream, keepAlive: true })
con.connect(123, 'test')
var res = false
stream.setKeepAlive = function (bit) {
res = bit
}
assert.ok(stream.emit('connect'))
setTimeout(function () {
assert.equal(res, true)
})
})
})
test('using opened stream', function () {
var stream = new MemoryStream()
stream.readyState = 'open'
stream.connect = function () {
assert.ok(false, 'Should not call open')
}
var con = new Connection({stream: stream})
test('does not call open', function () {
var hit = false
con.once('connect', function () {
hit = true
})
con.connect()
assert.ok(hit)
})
})