Lazy Deferred per roomId with a timeout on await. Lets concurrent joiner sessions block until their host announces the room code without polling or page scraping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { RoomCoordinator } from '../core/room-coordinator';
|
|
|
|
describe('RoomCoordinator', () => {
|
|
it('resolves await with the announced code (announce then await)', async () => {
|
|
const rc = new RoomCoordinator();
|
|
rc.announce('room-1', 'ABCD');
|
|
await expect(rc.await('room-1')).resolves.toBe('ABCD');
|
|
});
|
|
|
|
it('resolves await with the announced code (await then announce)', async () => {
|
|
const rc = new RoomCoordinator();
|
|
const p = rc.await('room-2');
|
|
rc.announce('room-2', 'WXYZ');
|
|
await expect(p).resolves.toBe('WXYZ');
|
|
});
|
|
|
|
it('rejects await after timeout if not announced', async () => {
|
|
const rc = new RoomCoordinator();
|
|
await expect(rc.await('room-3', 50)).rejects.toThrow(/timed out/i);
|
|
});
|
|
|
|
it('isolates rooms — announcing room-A does not unblock room-B', async () => {
|
|
const rc = new RoomCoordinator();
|
|
const pB = rc.await('room-B', 100);
|
|
rc.announce('room-A', 'A-CODE');
|
|
await expect(pB).rejects.toThrow(/timed out/i);
|
|
});
|
|
});
|