mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 21:45:54 +00:00
grace period disconnect should be per-client
This commit is contained in:
@@ -54,4 +54,37 @@ describe('ClientManager', () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
assert(!manager.hasClient('foobar'));
|
||||
}).timeout(5000);
|
||||
|
||||
it('should remove correct client once it goes offline', async () => {
|
||||
const manager = new ClientManager();
|
||||
const clientFoo = await manager.newClient('foo');
|
||||
const clientBar = await manager.newClient('bar');
|
||||
|
||||
const socket = await new Promise((resolve) => {
|
||||
const netClient = net.createConnection({ port: clientFoo.port }, () => {
|
||||
resolve(netClient);
|
||||
});
|
||||
});
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
|
||||
// foo should still be ok
|
||||
assert(manager.hasClient('foo'));
|
||||
|
||||
// clientBar shound be removed - nothing connected to it
|
||||
assert(!manager.hasClient('bar'));
|
||||
|
||||
manager.removeClient('foo');
|
||||
socket.end();
|
||||
}).timeout(5000);
|
||||
|
||||
it('should remove clients if they do not connect within 5 seconds', async () => {
|
||||
const manager = new ClientManager();
|
||||
const clientFoo = await manager.newClient('foo');
|
||||
assert(manager.hasClient('foo'));
|
||||
|
||||
// wait past grace period (1s)
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
assert(!manager.hasClient('foo'));
|
||||
}).timeout(5000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user