提交 55cfb983 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Node: avoid the ugly unhandled "error" event propagation and really fix test units.

上级 8babce3c
......@@ -140,8 +140,11 @@ class Channel extends EventEmitter
// Close every pending sent
this._pendingSent.forEach((sent) => sent.close());
// Remove event listeners but leave a fake 'error' hander
// to avoid propagation
this._socket.removeAllListeners('end');
this._socket.removeAllListeners('error');
this._socket.on('error', () => null);
// Destroy the socket after a while to allow pending incoming
// messages
......
......@@ -103,8 +103,11 @@ class Worker extends EventEmitter
// Kill child
if (this._child)
{
// Remove event listeners but leave a fake 'error' hander
// to avoid propagation
this._child.removeAllListeners('exit');
this._child.removeAllListeners('error');
this._child.on('error', () => null);
this._child.kill('SIGTERM');
}
......
......@@ -36,8 +36,7 @@ tap.test('room.Peer() without `peerId` must fail', { timeout: 1000 }, (t) =>
room.Peer();
}, 'room.Peer() should throw error');
// Wait a bit so Channel requests receive response
setTimeout(() => t.end(), 50);
t.end();
});
tap.test('room.Peer() with same `peerId` must fail', { timeout: 1000 }, (t) =>
......@@ -55,8 +54,7 @@ tap.test('room.Peer() with same `peerId` must fail', { timeout: 1000 }, (t) =>
room.Peer('alice');
}, 'room.Peer() should throw error');
// Wait a bit so Channel requests receive response
setTimeout(() => t.end(), 50);
t.end();
});
tap.test('room.Peer() with same `peerId` must succeed if previous peer was closed before', { timeout: 1000 }, (t) =>
......
......@@ -66,8 +66,7 @@ tap.test('server.updateSettings() in a closed server must fail', { timeout: 1000
});
});
// Wait a bit for workers to be created
setTimeout(() => server.close(), 100);
server.close();
});
tap.test('server.Room() must succeed', { _timeout: 1000 }, (t) =>
......@@ -103,8 +102,7 @@ tap.test('server.Room() in a closed server must fail', { timeout: 1000 }, (t) =>
t.end();
});
// Wait a bit for workers to be created
setTimeout(() => server.close(), 100);
server.close();
});
tap.test('server.dump() must succeed', { timeout: 1000 }, (t) =>
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论