test(session): preserve live binding after cancelled switches

This commit is contained in:
morluto
2026-10-09 04:43:19 +08:00
parent e44cb45908
commit 1136ea8810
@@ -149,7 +149,7 @@ describe("target-bound provider routing", () => {
});
});
it("cancels a provider switch, closes its old client, and restores the binding", async () => {
it("preserves the active client when a provider switch is cancelled while draining", async () => {
const target = await databaseTarget();
const alpha = deepProvider("alpha");
const beta = deepProvider("beta");
@@ -176,18 +176,18 @@ describe("target-bound provider routing", () => {
ok: false,
error: new AnalysisCancelledError("open_binary"),
});
expect(alpha.clients[0]?.closed).toBe(true);
expect(alpha.clients[0]?.closed).toBe(false);
expect(beta.clients).toHaveLength(0);
expect(bindingStatus(session)).toMatchObject({
analysis_provider_binding: { provider: { id: "alpha" } },
});
alpha.pending = undefined;
const restored = await session.execute("address_name", { address: "0x2" });
expect(restored.ok && restored.value.provider.id).toBe("alpha");
expect(alpha.clients).toHaveLength(2);
const retained = await session.execute("address_name", { address: "0x2" });
expect(retained.ok && retained.value.provider.id).toBe("alpha");
expect(alpha.clients).toHaveLength(1);
await session.close();
expect(alpha.clients[1]?.closed).toBe(true);
expect(alpha.clients[0]?.closed).toBe(true);
});
});