mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(durable): release the second slow call when the first finished, not after 200 polls
The code mode ordering test released call 1 from an eventually() poll with a turn limit; on a loaded CI runner the sandbox worker took more turns and the test hung until its timeout.
This commit is contained in:
parent
0b102787cd
commit
e17e2e1055
1 changed files with 11 additions and 6 deletions
|
|
@ -115,21 +115,26 @@ function codemodeChat(globals: CodemodeGlobal[] = [], namespaces: CodemodeNamesp
|
|||
),
|
||||
);
|
||||
const gates = new Map<number, Deferred>();
|
||||
const done = new Map<number, Deferred>();
|
||||
const finished: number[] = [];
|
||||
const once = (map: Map<number, Deferred>, id: number) => {
|
||||
const found = map.get(id) ?? deferred();
|
||||
map.set(id, found);
|
||||
return found;
|
||||
};
|
||||
const slows = {
|
||||
finished,
|
||||
gate: (id: number) => {
|
||||
const gate = gates.get(id) ?? deferred();
|
||||
gates.set(id, gate);
|
||||
return gate;
|
||||
},
|
||||
gate: (id: number) => once(gates, id),
|
||||
release: (id: number) => slows.gate(id).resolve(),
|
||||
/** Resolves once call `id` has finished. */
|
||||
finishedCall: (id: number) => once(done, id).promise,
|
||||
};
|
||||
addTool(
|
||||
setup.registry,
|
||||
tool("slow", async (args) => {
|
||||
await slows.gate(args.id ?? 0).promise;
|
||||
finished.push(args.id ?? 0);
|
||||
once(done, args.id ?? 0).resolve();
|
||||
return { output: [{ type: "text", text: `slow ${args.id}` }] };
|
||||
}),
|
||||
);
|
||||
|
|
@ -230,7 +235,7 @@ describe("durable code mode", () => {
|
|||
return order;`;
|
||||
// 2 finishes first, then 1.
|
||||
chat.slows.release(2);
|
||||
void eventually(() => chat.slows.finished.includes(2)).then(() => chat.slows.release(1));
|
||||
void chat.slows.finishedCall(2).then(() => chat.slows.release(1));
|
||||
const { harness, result } = await restart(chat, code);
|
||||
expect(result).toEqual({ text: "[2,1]", isError: false });
|
||||
expect(Object.fromEntries(chat.echo)).toEqual({ "2,1": 1 });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue