* Polls until predicate returns true or deadline expires. Used in lieu of arbitrary * `setTimeout` waits for "session flushed to disk" so fast machines exit immediately * and slow CI machines still get up to `timeoutMs` before the test fails.
(
predicate: () => Promise<boolean> | boolean,
timeoutMs = 10_000
)
| 12 | * and slow CI machines still get up to `timeoutMs` before the test fails. |
| 13 | */ |
| 14 | async function waitFor( |
| 15 | predicate: () => Promise<boolean> | boolean, |
| 16 | timeoutMs = 10_000 |
| 17 | ): Promise<void> { |
| 18 | const deadline = Date.now() + timeoutMs; |
| 19 | while (Date.now() < deadline) { |
| 20 | if (await predicate()) return; |
| 21 | await new Promise((r) => setTimeout(r, 50)); |
| 22 | } |
| 23 | throw new Error(`waitFor: condition not met within ${timeoutMs}ms`); |
| 24 | } |
| 25 | |
| 26 | describe("Session Lifecycle", async () => { |
| 27 | const { copilotClient: client } = await createSdkTestContext(); |
no test coverage detected
searching dependent graphs…