mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:00:43 +00:00
test: clear feishu drive cleanup timers
This commit is contained in:
@@ -21,6 +21,22 @@ function createFeishuToolRuntime(): PluginRuntime {
|
||||
return {} as PluginRuntime;
|
||||
}
|
||||
|
||||
async function raceWithNextMacrotask<T>(promise: Promise<T>): Promise<T | "pending"> {
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
promise,
|
||||
new Promise<"pending">((resolve) => {
|
||||
timer = setTimeout(() => resolve("pending"), 0);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createDriveToolApi(params: {
|
||||
config: OpenClawPluginApi["config"];
|
||||
registerTool: OpenClawPluginApi["registerTool"];
|
||||
@@ -559,10 +575,7 @@ describe("registerFeishuDriveTools", () => {
|
||||
action: "reply_comment",
|
||||
content: "ambient success",
|
||||
});
|
||||
const status = await Promise.race([
|
||||
replyCommentPromise.then(() => "done"),
|
||||
new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
|
||||
]);
|
||||
const status = await raceWithNextMacrotask(replyCommentPromise.then(() => "done"));
|
||||
|
||||
expect(status).toBe("done");
|
||||
expect(requestMock).toHaveBeenNthCalledWith(
|
||||
@@ -656,10 +669,7 @@ describe("registerFeishuDriveTools", () => {
|
||||
action: "add_comment",
|
||||
content: "ambient top-level comment",
|
||||
});
|
||||
const status = await Promise.race([
|
||||
addCommentPromise.then(() => "done"),
|
||||
new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
|
||||
]);
|
||||
const status = await raceWithNextMacrotask(addCommentPromise.then(() => "done"));
|
||||
|
||||
expect(status).toBe("done");
|
||||
expect(requestMock).toHaveBeenCalledWith(
|
||||
|
||||
Reference in New Issue
Block a user