@@ -118,4 +118,39 @@ describe("getOrCreateAccountThrottler", () => {
|
118 | 118 | |
119 | 119 | expect(entered).toEqual(["101:first-edit", "202:other-edit", "101:second-edit"]); |
120 | 120 | }); |
| 121 | + |
| 122 | +it("does not group-throttle fractional chat ids", async () => { |
| 123 | +const firstGate = deferred<void>(); |
| 124 | +const entered: string[] = []; |
| 125 | +const throttler = createTelegramAccountThrottler( |
| 126 | +() => async (prev, method, payload, signal) => prev(method, payload, signal), |
| 127 | +); |
| 128 | +const prev = vi.fn(async (_method: string, payload: unknown) => { |
| 129 | +const request = payload as { text?: string }; |
| 130 | +entered.push(request.text ?? ""); |
| 131 | +if (entered.length === 1) { |
| 132 | +await firstGate.promise; |
| 133 | +} |
| 134 | +return { ok: true, result: request.text ?? "" }; |
| 135 | +}) as unknown as TelegramPreviousCall; |
| 136 | + |
| 137 | +const first = throttler( |
| 138 | +prev, |
| 139 | +"sendMessage", |
| 140 | +{ chat_id: "-100123.5", message_thread_id: 10, text: "first" }, |
| 141 | +undefined, |
| 142 | +); |
| 143 | +await vi.waitFor(() => expect(entered).toEqual(["first"])); |
| 144 | + |
| 145 | +const second = throttler( |
| 146 | +prev, |
| 147 | +"sendMessage", |
| 148 | +{ chat_id: "-100123.5", message_thread_id: 20, text: "second" }, |
| 149 | +undefined, |
| 150 | +); |
| 151 | +await vi.waitFor(() => expect(entered).toEqual(["first", "second"])); |
| 152 | + |
| 153 | +firstGate.resolve(); |
| 154 | +await Promise.all([first, second]); |
| 155 | +}); |
121 | 156 | }); |