This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 605
Expand file tree
/
Copy patherror.js
More file actions
executable file
·112 lines (95 loc) · 3 KB
/
error.js
File metadata and controls
executable file
·112 lines (95 loc) · 3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var dnode = require('../');
var test = require('tap').test;
test('errors', function (t) {
t.plan(4);
var port = Math.floor(Math.random() * 40000 + 10000);
var errors = { server : [], client : [] };
var server = dnode(function (remote, conn) {
conn.on('error', function (err) {
errors.server.push(err);
});
this.one = function () {
throw 'string throw'
};
this.two = function () {
undefined.name
};
this.three = function () {
remote.pow();
};
}).listen(port);
var ts = setTimeout(function () {
t.fail('server never ended');
}, 5000);
server.on('end', function () {
clearTimeout(ts);
t.deepEqual(errors.server[0], 'string throw');
try { undefined.name }
catch (refErr) {
process.nextTick(function () {
t.equal(refErr.message, errors.server[1].message);
t.equal(refErr.type, errors.server[1].type);
t.equal(errors.server.length, 2);
t.end();
});
}
});
server.on('ready', function () {
var client = dnode(function (client, conn) {
conn.on('error', function (err) {
errors.client.push(err);
});
conn.on('end', function () {
t.deepEqual(errors.client, [ 'Local error' ]);
});
this.pow = function () {
throw 'Local error';
};
}).connect(port, function (remote, conn) {
remote.one();
remote.two();
remote.three();
setTimeout(function () {
conn.end();
server.end();
server.close();
}, 500);
});
});
});
test('refused', function (t) {
t.plan(2);
var port = Math.floor(Math.random() * 40000 + 10000);
var client = dnode.connect(port, function (remote, conn) {
assert.fail('should have been refused, very unlikely');
});
client.on('error', function (err) {
t.equal(err.code, 'ECONNREFUSED');
t.equal(err.syscall, 'connect');
t.end();
});
});
test('close same server twice shouldn\'t throw errors', function(t) {
var port = Math.floor(Math.random() * 40000 + 10000);
var server = dnode();
server.on('ready', function() {
server.once('close', function() {
server.once('close', function() {
t.end();
})
server.close();
})
server.close();
});
server.listen(port);
});
test('bad connection string', function(t) {
try {
var client = dnode.connect('garbage', function (remote, conn) {
assert.fail('should have been refused, very unlikely');
});
} catch (err) {
t.ok(/Could not create a stream/.test(err.message));
t.end();
}
});