mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-14 19:55:05 +00:00
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user