fix(qa): cap Matrix readiness polling · openclaw/openclaw@099b0f8
vincentkoc
·
2026-05-27
·
via Recent Commits to openclaw:main
File tree
extensions/qa-matrix/src/runners/contract
| Original file line number | Diff line number | Diff line change |
|---|
@@ -654,4 +654,32 @@ describe("matrix live qa runtime", () => {
|
654 | 654 | await vi.advanceTimersByTimeAsync(300); |
655 | 655 | await expectation; |
656 | 656 | }); |
| 657 | + |
| 658 | +it("caps Matrix readiness status RPCs and sleeps to the remaining timeout budget", async () => { |
| 659 | +vi.useFakeTimers(); |
| 660 | +const gateway = { |
| 661 | +call: vi.fn().mockResolvedValue({ |
| 662 | +channelAccounts: { |
| 663 | +matrix: [{ accountId: "sut", running: true, connected: true, healthState: "degraded" }], |
| 664 | +}, |
| 665 | +}), |
| 666 | +}; |
| 667 | + |
| 668 | +const waitPromise = liveTesting.waitForMatrixChannelReady(gateway as never, "sut", { |
| 669 | +timeoutMs: 250, |
| 670 | +pollMs: 1_000, |
| 671 | +}); |
| 672 | +const expectation = expect(waitPromise).rejects.toThrow( |
| 673 | +'matrix account "sut" did not become ready', |
| 674 | +); |
| 675 | +await vi.advanceTimersByTimeAsync(250); |
| 676 | + |
| 677 | +await expectation; |
| 678 | +expect(gateway.call).toHaveBeenCalledTimes(1); |
| 679 | +expect(gateway.call).toHaveBeenCalledWith( |
| 680 | +"channels.status", |
| 681 | +{ probe: false, timeoutMs: 250 }, |
| 682 | +{ timeoutMs: 250 }, |
| 683 | +); |
| 684 | +}); |
657 | 685 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -444,13 +444,16 @@ async function waitForMatrixChannelReady(
|
444 | 444 | const pollMs = opts?.pollMs ?? 500; |
445 | 445 | const timeoutMs = opts?.timeoutMs ?? 60_000; |
446 | 446 | const startedAt = Date.now(); |
| 447 | +const deadlineMs = startedAt + timeoutMs; |
447 | 448 | let lastAccounts: unknown; |
448 | | -while (Date.now() - startedAt < timeoutMs) { |
| 449 | +while (Date.now() < deadlineMs) { |
| 450 | +const remainingMs = Math.max(1, deadlineMs - Date.now()); |
| 451 | +const statusTimeoutMs = Math.min(5_000, remainingMs); |
449 | 452 | try { |
450 | 453 | const payload = (await gateway.call( |
451 | 454 | "channels.status", |
452 | | -{ probe: false, timeoutMs: 2_000 }, |
453 | | -{ timeoutMs: 5_000 }, |
| 455 | +{ probe: false, timeoutMs: Math.min(2_000, statusTimeoutMs) }, |
| 456 | +{ timeoutMs: statusTimeoutMs }, |
454 | 457 | )) as { |
455 | 458 | channelAccounts?: Record< |
456 | 459 | string, |
@@ -472,7 +475,7 @@ async function waitForMatrixChannelReady(
|
472 | 475 | } catch { |
473 | 476 | // retry |
474 | 477 | } |
475 | | -await sleep(pollMs); |
| 478 | +await sleep(Math.min(pollMs, Math.max(1, deadlineMs - Date.now()))); |
476 | 479 | } |
477 | 480 | throw new Error( |
478 | 481 | `matrix account "${accountId}" did not become ready; last matrix accounts: ${JSON.stringify( |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。