mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
perf(test): dedupe telegram allowlist and speed twitch probe
This commit is contained in:
@@ -26,9 +26,8 @@ const mockOnAuthenticationFailure = vi.fn((_handler: () => void) => {
|
||||
|
||||
// Connect mock that triggers the registered handler
|
||||
const defaultConnectImpl = async () => {
|
||||
// Simulate successful connection by calling the handler after a delay
|
||||
// Simulate successful connection by calling the handler immediately.
|
||||
if (connectHandler) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
connectHandler();
|
||||
}
|
||||
};
|
||||
@@ -114,15 +113,19 @@ describe("probeTwitch", () => {
|
||||
});
|
||||
|
||||
it("times out when connection takes too long", async () => {
|
||||
mockConnect.mockImplementationOnce(() => new Promise(() => {})); // Never resolves
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
mockConnect.mockImplementationOnce(() => new Promise(() => {})); // Never resolves
|
||||
const resultPromise = probeTwitch(mockAccount, 100);
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
const result = await resultPromise;
|
||||
|
||||
const result = await probeTwitch(mockAccount, 100);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.error).toContain("timeout");
|
||||
|
||||
// Reset mock
|
||||
mockConnect.mockImplementation(defaultConnectImpl);
|
||||
expect(result.ok).toBe(false);
|
||||
expect(result.error).toContain("timeout");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
mockConnect.mockImplementation(defaultConnectImpl);
|
||||
}
|
||||
});
|
||||
|
||||
it("cleans up client even on failure", async () => {
|
||||
@@ -130,7 +133,6 @@ describe("probeTwitch", () => {
|
||||
// Simulate connection failure by calling disconnect handler
|
||||
// onDisconnect signature: (manually: boolean, reason?: Error) => void
|
||||
if (disconnectHandler) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
disconnectHandler(false, new Error("Connection failed"));
|
||||
}
|
||||
});
|
||||
@@ -150,7 +152,6 @@ describe("probeTwitch", () => {
|
||||
// Simulate connection failure by calling disconnect handler
|
||||
// onDisconnect signature: (manually: boolean, reason?: Error) => void
|
||||
if (disconnectHandler) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
disconnectHandler(false, new Error("Network error"));
|
||||
}
|
||||
});
|
||||
@@ -180,7 +181,6 @@ describe("probeTwitch", () => {
|
||||
// Simulate connection failure by calling disconnect handler
|
||||
// onDisconnect signature: (manually: boolean, reason?: Error) => void
|
||||
if (disconnectHandler) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
disconnectHandler(false, "String error" as unknown as Error);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user