mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-14 09:06:08 +00:00
fix(zalouser): clear probe timeout after auth resolves (#101649)
This commit is contained in:
@@ -60,6 +60,23 @@ describe("probeZalouser", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("clears the probe timeout after auth resolves", async () => {
|
||||
vi.useFakeTimers();
|
||||
const clearTimeoutSpy = vi.spyOn(globalThis, "clearTimeout");
|
||||
mockGetUserInfo.mockResolvedValueOnce({
|
||||
userId: "123",
|
||||
displayName: "Alice",
|
||||
});
|
||||
|
||||
await expect(probeZalouser("default", 10)).resolves.toEqual({
|
||||
ok: true,
|
||||
user: { userId: "123", displayName: "Alice" },
|
||||
});
|
||||
|
||||
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1);
|
||||
expect(vi.getTimerCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("caps oversized lookup timeout before scheduling", async () => {
|
||||
vi.useFakeTimers();
|
||||
mockGetUserInfo.mockReturnValueOnce(new Promise(() => {}));
|
||||
|
||||
@@ -14,14 +14,27 @@ export async function probeZalouser(
|
||||
timeoutMs?: number,
|
||||
): Promise<ZalouserProbeResult> {
|
||||
try {
|
||||
const user = timeoutMs
|
||||
? await Promise.race([
|
||||
let user: ZcaUserInfo | null;
|
||||
if (timeoutMs) {
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
try {
|
||||
user = await Promise.race([
|
||||
getZaloUserInfo(profile),
|
||||
new Promise<null>((resolve) => {
|
||||
setTimeout(() => resolve(null), resolveTimerTimeoutMs(timeoutMs, 1000, 1000));
|
||||
timeout = setTimeout(
|
||||
() => resolve(null),
|
||||
resolveTimerTimeoutMs(timeoutMs, 1000, 1000),
|
||||
);
|
||||
}),
|
||||
])
|
||||
: await getZaloUserInfo(profile);
|
||||
]);
|
||||
} finally {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
user = await getZaloUserInfo(profile);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return { ok: false, error: "Not authenticated" };
|
||||
|
||||
Reference in New Issue
Block a user