A fake transport that records every send/edit, with a hand-driven clock.
(maxLen = 50, minIntervalMs = 1000)
| 4 | |
| 5 | /** A fake transport that records every send/edit, with a hand-driven clock. */ |
| 6 | function fakeIO(maxLen = 50, minIntervalMs = 1000) { |
| 7 | const log: Array<{ op: 'send' | 'edit'; id: string; text: string }> = []; |
| 8 | let clock = 0; |
| 9 | let n = 0; |
| 10 | const messages = new Map<string, string>(); |
| 11 | const io: PumpIO = { |
| 12 | maxLen, |
| 13 | minIntervalMs, |
| 14 | now: () => clock, |
| 15 | send: async (text) => { const id = `m${++n}`; messages.set(id, text); log.push({ op: 'send', id, text }); return { id } as MessageRef; }, |
| 16 | edit: async (ref, text) => { messages.set(ref.id, text); log.push({ op: 'edit', id: ref.id, text }); }, |
| 17 | }; |
| 18 | return { io, log, messages, tick: (ms: number) => { clock += ms; }, sends: () => log.filter(l => l.op === 'send').length, edits: () => log.filter(l => l.op === 'edit').length }; |
| 19 | } |
| 20 | |
| 21 | describe('StreamPump', () => { |
| 22 | it('throttles: many rapid pushes inside one window cause at most the first send', async () => { |
no test coverage detected