mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 20:50:42 +00:00
fix(feishu): route /btw through out-of-band lanes (#64324)
* fix(feishu): route /btw through out-of-band lanes * fix(feishu): bound btw out-of-band lanes * fix: route feishu btw out-of-band (#64324) (thanks @ngutman)
This commit is contained in:
64
extensions/feishu/src/sequential-queue.test.ts
Normal file
64
extensions/feishu/src/sequential-queue.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createSequentialQueue } from "./sequential-queue.js";
|
||||
|
||||
function createDeferred() {
|
||||
let resolve!: () => void;
|
||||
const promise = new Promise<void>((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
describe("createSequentialQueue", () => {
|
||||
it("serializes tasks for the same key", async () => {
|
||||
const enqueue = createSequentialQueue();
|
||||
const gate = createDeferred();
|
||||
const order: string[] = [];
|
||||
|
||||
const first = enqueue("feishu:default:chat-1", async () => {
|
||||
order.push("first:start");
|
||||
await gate.promise;
|
||||
order.push("first:end");
|
||||
});
|
||||
const second = enqueue("feishu:default:chat-1", async () => {
|
||||
order.push("second:start");
|
||||
order.push("second:end");
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
expect(order).toEqual(["first:start"]);
|
||||
|
||||
gate.resolve();
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(order).toEqual(["first:start", "first:end", "second:start", "second:end"]);
|
||||
});
|
||||
|
||||
it("allows different keys to run concurrently", async () => {
|
||||
const enqueue = createSequentialQueue();
|
||||
const gateA = createDeferred();
|
||||
const gateB = createDeferred();
|
||||
const order: string[] = [];
|
||||
|
||||
const first = enqueue("feishu:default:chat-1", async () => {
|
||||
order.push("chat-1:start");
|
||||
await gateA.promise;
|
||||
order.push("chat-1:end");
|
||||
});
|
||||
const second = enqueue("feishu:default:chat-1:btw:om_2", async () => {
|
||||
order.push("btw:start");
|
||||
await gateB.promise;
|
||||
order.push("btw:end");
|
||||
});
|
||||
|
||||
await Promise.resolve();
|
||||
expect(order).toEqual(["chat-1:start", "btw:start"]);
|
||||
|
||||
gateA.resolve();
|
||||
gateB.resolve();
|
||||
await Promise.all([first, second]);
|
||||
|
||||
expect(order).toContain("chat-1:end");
|
||||
expect(order).toContain("btw:end");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user