fix: JS SDK 传输失败后换 rid 再泵发送队列
This commit is contained in:
@@ -126,6 +126,46 @@ describe("nixmsg sdk", () => {
|
||||
await c.close();
|
||||
}, 10000);
|
||||
|
||||
it("publishUp transport fail retries with new rid", async () => {
|
||||
const fake = new FakeTransport();
|
||||
const c = await connectFake(fake);
|
||||
const at = new Date(1_700_000_000_000);
|
||||
const attempts: Array<Record<string, unknown>> = [];
|
||||
let failOnce = true;
|
||||
fake.publishUpImpl = async (s) => {
|
||||
const m = JSON.parse(s) as Record<string, unknown>;
|
||||
if (m.type !== "send") return;
|
||||
attempts.push(m);
|
||||
if (failOnce) {
|
||||
failOnce = false;
|
||||
throw new Error("transient publish");
|
||||
}
|
||||
};
|
||||
const timer = setInterval(() => {
|
||||
const sends = fake.findUp("send");
|
||||
if (sends.length < 1) return;
|
||||
const last = sends[sends.length - 1]!;
|
||||
fake.replyOK(String(last.rid), {
|
||||
id: last.id,
|
||||
send_at_ms: last.send_at_ms,
|
||||
state: "scheduled",
|
||||
});
|
||||
}, 5);
|
||||
const res = await c.send(
|
||||
{ kind: "endpoint", id: "b" },
|
||||
{ enc: "utf8", data: "hi" },
|
||||
{ sendAt: at },
|
||||
);
|
||||
clearInterval(timer);
|
||||
expect(attempts.length).toBeGreaterThanOrEqual(2);
|
||||
expect(String(attempts[1]!.rid)).not.toBe(String(attempts[0]!.rid));
|
||||
expect(attempts[1]!.id).toBe(attempts[0]!.id);
|
||||
expect(attempts[1]!.send_at_ms).toBe(attempts[0]!.send_at_ms);
|
||||
expect((attempts[1]!.body as { data: string }).data).toBe("hi");
|
||||
expect(res.id).toBe(String(attempts[0]!.id));
|
||||
await c.close();
|
||||
}, 5000);
|
||||
|
||||
it("register HTTP from ws url", async () => {
|
||||
const srv = createServer((req, res) => {
|
||||
expect(req.url).toBe("/api/client/register");
|
||||
|
||||
Reference in New Issue
Block a user