-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
42 lines (35 loc) · 938 Bytes
/
test.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
var tape = require('tape');
var topology = require('./');
tape('2 peers', function(t) {
var t1 = topology('127.0.0.1:10002', ['127.0.0.1:10003']);
var t2 = topology('127.0.0.1:10003', ['127.0.0.1:10002']);
var missing = 2;
var end = function() {
t1.destroy();
t2.destroy();
t.end();
};
t1.once('connection', function(s, peer) {
t.same(peer, '127.0.0.1:10003');
if (!--missing) end();
});
t2.once('connection', function(s, peer) {
t.same(peer, '127.0.0.1:10002');
if (!--missing) end();
});
});
tape('reconnects', function(t) {
var t1 = topology('127.0.0.1:10002', ['127.0.0.1:10003']);
var t2 = topology('127.0.0.1:10003', ['127.0.0.1:10002']);
var missing = 3;
var end = function() {
t1.destroy();
t2.destroy();
t.end();
};
t1.on('connection', function(s, peer) {
t.same(peer, '127.0.0.1:10003');
if (--missing) return s.destroy();
end();
});
});