Skip to content

Commit

Permalink
tests: cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Jan 6, 2024
1 parent 55fc5d6 commit 6827cd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
26 changes: 26 additions & 0 deletions tests/essentials/Server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,30 @@ describe('# server::Server', () => {
await server.stop();
});
});

describe(`## server.onClientDisconnect(func)`, () => {
it(`should be called`, async () => {
const server = new Server(config);
await server.start();

let onDisconnectCalled = false;
let onDisconnectClientId = null;

server.onClientDisconnect(client => {
onDisconnectCalled = true;
onDisconnectClientId = client.id;
});

const client = new Client({ role: 'test', ...config });
await client.start();
await client.stop();

await delay(20);

assert.equal(onDisconnectCalled, true);
assert.equal(onDisconnectClientId, client.id);

await server.stop();
});
});
});
16 changes: 7 additions & 9 deletions tests/states/SharedState.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,11 @@ describe('# SharedState', () => {
const aCreated = await server.stateManager.create('a');
const aAttached = await client.stateManager.attach('a');

// DELETE_REQUEST is received first on the SharedStatePrivate which deletes
// all its listeners.
// Concurrently DETACH_REQUEST is sent but cannot have a response,
// flush pending requests when DELETE_NOTIFICATION is received
// - DELETE_REQUEST sent by `aCreated` is received first on the
// SharedStatePrivate which deletes all its listeners.
// - Concurrently DETACH_REQUEST is sent by `aAttached` but cannot have a response,
// - Flush pending requests on `aAttached` when DELETE_NOTIFICATION is received

aCreated.delete();

let errored = false;
Expand Down Expand Up @@ -543,10 +544,6 @@ describe('# SharedState', () => {
});
});

// ---------------------------------------------------
// clients
// ---------------------------------------------------

const client = new Client({ role: 'test', ...localConfig });
await client.start();

Expand All @@ -564,7 +561,8 @@ describe('# SharedState', () => {

await delay(20);

// we have both the create request and the batched update requests
// 1 message for create request / response (i.e.await client.stateManager.create)
// 1 message for the batched updates requests / responses
assert.equal(batchedRequests, 2);
assert.equal(batchedResponses, 2);

Expand Down

0 comments on commit 6827cd6

Please sign in to comment.