test(qa-matrix): stabilize sync timeout cursor · openclaw/openclaw@bf132d6
steipete
·
2026-04-23
·
via Recent Commits to openclaw:main
File tree
extensions/qa-matrix/src/substrate
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import type { MatrixQaObservedEvent } from "./events.js"; |
3 | 3 | import { |
4 | 4 | createMatrixQaRoomObserver, |
@@ -50,16 +50,22 @@ describe("matrix sync helpers", () => {
|
50 | 50 | |
51 | 51 | const observedEvents: MatrixQaObservedEvent[] = []; |
52 | 52 | |
53 | | -const result = await waitForOptionalMatrixQaRoomEvent({ |
54 | | -accessToken: "token", |
55 | | -baseUrl: "http://127.0.0.1:28008/", |
56 | | - fetchImpl, |
57 | | - observedEvents, |
58 | | -predicate: (event) => event.sender === "@sut:matrix-qa.test", |
59 | | -roomId: "!room:matrix-qa.test", |
60 | | -since: "start-batch", |
61 | | -timeoutMs: 1_000, |
62 | | -}); |
| 53 | +const nowSpy = vi.spyOn(Date, "now").mockReturnValueOnce(0).mockReturnValue(1); |
| 54 | +let result: Awaited<ReturnType<typeof waitForOptionalMatrixQaRoomEvent>>; |
| 55 | +try { |
| 56 | +result = await waitForOptionalMatrixQaRoomEvent({ |
| 57 | +accessToken: "token", |
| 58 | +baseUrl: "http://127.0.0.1:28008/", |
| 59 | + fetchImpl, |
| 60 | + observedEvents, |
| 61 | +predicate: (event) => event.sender === "@sut:matrix-qa.test", |
| 62 | +roomId: "!room:matrix-qa.test", |
| 63 | +since: "start-batch", |
| 64 | +timeoutMs: 1, |
| 65 | +}); |
| 66 | +} finally { |
| 67 | +nowSpy.mockRestore(); |
| 68 | +} |
63 | 69 | |
64 | 70 | expect(result).toEqual({ |
65 | 71 | matched: false, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -144,6 +144,7 @@ export function createMatrixQaRoomObserver(
|
144 | 144 | const startSince = await this.prime(); |
145 | 145 | const startedAt = Date.now(); |
146 | 146 | let cursorIndex = roomObserver.cursorIndex; |
| 147 | +let didPoll = false; |
147 | 148 | while (true) { |
148 | 149 | const matched = findMatrixQaObservedEventMatch({ |
149 | 150 | cursorIndex, |
@@ -161,7 +162,7 @@ export function createMatrixQaRoomObserver(
|
161 | 162 | } |
162 | 163 | |
163 | 164 | const elapsedMs = Date.now() - startedAt; |
164 | | -if (elapsedMs >= waitParams.timeoutMs) { |
| 165 | +if (elapsedMs >= waitParams.timeoutMs && (didPoll || waitParams.timeoutMs <= 0)) { |
165 | 166 | roomObserver.cursorIndex = Math.max(roomObserver.cursorIndex, cursorIndex); |
166 | 167 | return { |
167 | 168 | matched: false, |
@@ -177,6 +178,7 @@ export function createMatrixQaRoomObserver(
|
177 | 178 | roomObserver, |
178 | 179 | timeoutMs: remainingMs, |
179 | 180 | }); |
| 181 | +didPoll = true; |
180 | 182 | } |
181 | 183 | }, |
182 | 184 | async waitForRoomEvent(waitParams) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。