From d78c8519e0b0d6b354efc11d899eaec94f6dcb70 Mon Sep 17 00:00:00 2001 From: Joseph Mearman Date: Tue, 27 Oct 2026 20:24:25 +0000 Subject: [PATCH] test: count only packet-handling errors in the malformed-packet test The presence reports its own failed broadcast sends through onError, so on a host with no broadcast route the malformed-packet test saw EHOSTUNREACH errors that have nothing to do with the packets it sends. Closes #466 --- src/test/first-contact.unit.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/first-contact.unit.test.ts b/src/test/first-contact.unit.test.ts index cc68d3d4..81b3e18f 100644 --- a/src/test/first-contact.unit.test.ts +++ b/src/test/first-contact.unit.test.ts @@ -51,6 +51,11 @@ function send(socket: dgram.Socket, payload: unknown, port: number): void { socket.send(JSON.stringify(payload), port, "127.0.0.1"); } +/** The presence reports its own failed sends through onError (a host with no broadcast route fails every limited-broadcast send with EHOSTUNREACH), which says nothing about how it handled a received packet. */ +function isOwnSendFailure(error: Error): boolean { + return "syscall" in error && error.syscall === "send"; +} + async function settle(): Promise { return new Promise((resolve) => { setTimeout(resolve, SETTLE_MS); @@ -222,7 +227,7 @@ describe("FirstContact", () => { await settle(); expect(discovered).toEqual([]); - expect(errors).toEqual([]); + expect(errors.filter((error) => !isOwnSendFailure(error))).toEqual([]); presence.stop(); });