test(realtime): stabilize websocket timeout test · openclaw/openclaw@f3ea298
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
File tree
src/realtime-transcription
| Original file line number | Diff line number | Diff line change |
|---|
@@ -179,6 +179,7 @@ describe("createRealtimeTranscriptionWebSocketSession", () => {
|
179 | 179 | }); |
180 | 180 | |
181 | 181 | it("applies the connect timeout while resolving async connection details", async () => { |
| 182 | +vi.useFakeTimers(); |
182 | 183 | const onError = vi.fn(); |
183 | 184 | const session = createRealtimeTranscriptionWebSocketSession({ |
184 | 185 | providerId: "test", |
@@ -192,14 +193,23 @@ describe("createRealtimeTranscriptionWebSocketSession", () => {
|
192 | 193 | }, |
193 | 194 | }); |
194 | 195 | |
195 | | -await expect(session.connect()).rejects.toThrow( |
196 | | -"test realtime transcription connection timeout", |
197 | | -); |
198 | | -expect(session.isConnected()).toBe(false); |
199 | | -expect(onError).toHaveBeenCalledTimes(1); |
200 | | -const timeoutError = requireFirstMockArg(onError, "connect timeout error"); |
201 | | -expect(timeoutError).toBeInstanceOf(Error); |
202 | | -expect(timeoutError.message).toBe("test realtime transcription connection timeout"); |
| 196 | +try { |
| 197 | +const connecting = session.connect(); |
| 198 | +const timeoutAssertion = expect(connecting).rejects.toThrow( |
| 199 | +"test realtime transcription connection timeout", |
| 200 | +); |
| 201 | +await vi.advanceTimersByTimeAsync(10); |
| 202 | + |
| 203 | +await timeoutAssertion; |
| 204 | +expect(session.isConnected()).toBe(false); |
| 205 | +expect(onError).toHaveBeenCalledTimes(1); |
| 206 | +const timeoutError = requireFirstMockArg(onError, "connect timeout error"); |
| 207 | +expect(timeoutError).toBeInstanceOf(Error); |
| 208 | +expect(timeoutError.message).toBe("test realtime transcription connection timeout"); |
| 209 | +} finally { |
| 210 | +session.close(); |
| 211 | +vi.useRealTimers(); |
| 212 | +} |
203 | 213 | }); |
204 | 214 | |
205 | 215 | it("does not open a socket when closed while async connection resolves", async () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。