mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:58:28 +00:00
perf(test): replace telegram media flush sleeps
This commit is contained in:
@@ -13,10 +13,6 @@ const TELEGRAM_TEST_TIMINGS = {
|
|||||||
textFragmentGapMs: 30,
|
textFragmentGapMs: 30,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const sleep = async (ms: number) => {
|
|
||||||
await new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
||||||
};
|
|
||||||
|
|
||||||
async function createBotHandler(): Promise<{
|
async function createBotHandler(): Promise<{
|
||||||
handler: (ctx: Record<string, unknown>) => Promise<void>;
|
handler: (ctx: Record<string, unknown>) => Promise<void>;
|
||||||
replySpy: ReturnType<typeof vi.fn>;
|
replySpy: ReturnType<typeof vi.fn>;
|
||||||
@@ -257,10 +253,14 @@ describe("telegram media groups", () => {
|
|||||||
await second;
|
await second;
|
||||||
|
|
||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
await sleep(MEDIA_GROUP_FLUSH_MS);
|
await vi.waitFor(
|
||||||
|
() => {
|
||||||
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
|
},
|
||||||
|
{ timeout: MEDIA_GROUP_FLUSH_MS * 2, interval: 10 },
|
||||||
|
);
|
||||||
|
|
||||||
expect(runtimeError).not.toHaveBeenCalled();
|
expect(runtimeError).not.toHaveBeenCalled();
|
||||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
|
||||||
const payload = replySpy.mock.calls[0][0];
|
const payload = replySpy.mock.calls[0][0];
|
||||||
expect(payload.Body).toContain("Here are my photos");
|
expect(payload.Body).toContain("Here are my photos");
|
||||||
expect(payload.MediaPaths).toHaveLength(2);
|
expect(payload.MediaPaths).toHaveLength(2);
|
||||||
@@ -305,9 +305,12 @@ describe("telegram media groups", () => {
|
|||||||
await Promise.all([first, second]);
|
await Promise.all([first, second]);
|
||||||
|
|
||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
await sleep(MEDIA_GROUP_FLUSH_MS);
|
await vi.waitFor(
|
||||||
|
() => {
|
||||||
expect(replySpy).toHaveBeenCalledTimes(2);
|
expect(replySpy).toHaveBeenCalledTimes(2);
|
||||||
|
},
|
||||||
|
{ timeout: MEDIA_GROUP_FLUSH_MS * 2, interval: 10 },
|
||||||
|
);
|
||||||
|
|
||||||
fetchSpy.mockRestore();
|
fetchSpy.mockRestore();
|
||||||
},
|
},
|
||||||
@@ -558,9 +561,13 @@ describe("telegram text fragments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
await sleep(TEXT_FRAGMENT_FLUSH_MS);
|
await vi.waitFor(
|
||||||
|
() => {
|
||||||
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
|
},
|
||||||
|
{ timeout: TEXT_FRAGMENT_FLUSH_MS * 2, interval: 10 },
|
||||||
|
);
|
||||||
|
|
||||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
|
||||||
const payload = replySpy.mock.calls[0][0] as { RawBody?: string; Body?: string };
|
const payload = replySpy.mock.calls[0][0] as { RawBody?: string; Body?: string };
|
||||||
expect(payload.RawBody).toContain(part1.slice(0, 32));
|
expect(payload.RawBody).toContain(part1.slice(0, 32));
|
||||||
expect(payload.RawBody).toContain(part2.slice(0, 32));
|
expect(payload.RawBody).toContain(part2.slice(0, 32));
|
||||||
|
|||||||
Reference in New Issue
Block a user