From 8cee2da2e135fee60ea541a6823c20f69439ba99 Mon Sep 17 00:00:00 2001 From: you Date: Sun, 29 Mar 2026 15:01:39 +0000 Subject: [PATCH] fix: add sleep before poller data insert to prevent race condition in tests The poller's Start() calls GetMaxTransmissionID() to initialize its cursor. When the test goroutine inserts data between go poller.Start() and the actual GetMaxTransmissionID() call, the poller's cursor skips past the test data and never broadcasts it, causing a timeout. Adding a 100ms sleep after go poller.Start() ensures the poller has initialized its cursors before the test inserts new data. --- cmd/server/parity_test.go | 5 +++++ cmd/server/websocket_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/cmd/server/parity_test.go b/cmd/server/parity_test.go index e36decd5..497d2ea8 100644 --- a/cmd/server/parity_test.go +++ b/cmd/server/parity_test.go @@ -424,6 +424,11 @@ func TestParityWSMultiObserverGolden(t *testing.T) { go poller.Start() defer poller.Stop() + // Wait for poller to initialize its lastID/lastObsID cursors before + // inserting new data; otherwise the poller may snapshot a lastID that + // already includes the test data and never broadcast it. + time.Sleep(100 * time.Millisecond) + now := time.Now().UTC().Format(time.RFC3339) if _, err := db.conn.Exec(`INSERT INTO transmissions (raw_hex, hash, first_seen, route_type, payload_type, decoded_json) VALUES ('BEEF', 'goldenstarburst237', ?, 1, 4, '{"pubKey":"aabbccdd11223344","type":"ADVERT"}')`, now); err != nil { diff --git a/cmd/server/websocket_test.go b/cmd/server/websocket_test.go index fa883d2a..22b68d82 100644 --- a/cmd/server/websocket_test.go +++ b/cmd/server/websocket_test.go @@ -278,6 +278,11 @@ func TestPollerBroadcastsMultipleObservations(t *testing.T) { go poller.Start() defer poller.Stop() + // Wait for poller to initialize its lastID/lastObsID cursors before + // inserting new data; otherwise the poller may snapshot a lastID that + // already includes the test data and never broadcast it. + time.Sleep(100 * time.Millisecond) + now := time.Now().UTC().Format(time.RFC3339) if _, err := db.conn.Exec(`INSERT INTO transmissions (raw_hex, hash, first_seen, route_type, payload_type, decoded_json) VALUES ('FACE', 'starbursthash237a', ?, 1, 4, '{"pubKey":"aabbccdd11223344","type":"ADVERT"}')`, now); err != nil {