Files
beacon-server/internal/ingest/mqtt_client_test.go
MrAlders0n 52fc3e1e48 fix(ingest): validate topic keys and harden against malformed input
A short topic pubkey panicked a lane worker and killed the process; keys must
now be 32 bytes and lane workers recover. Also reject non-finite radio values
before airtime, strip NULs from advert names and neighbour scopes, guard the
MQTT client pointer, and never stream a broker copy of a hearing as a repeat.
2026-10-02 16:53:32 -04:00

31 lines
789 B
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package ingest
import (
"context"
"testing"
"time"
"github.com/MeshCore-Beacon/beacon-server/internal/hub"
)
// Run with -race: /brokers reads the client while Start creates it.
func TestIsConnectedWhileStarting(t *testing.T) {
w := New(Config{BrokerName: "test", URL: "tcp://127.0.0.1:1"}, &stubDB{}, hub.New(), &stubKeys{}, &stubScopes{})
ctx, cancel := context.WithCancel(context.Background())
stopped := make(chan struct{})
go func() { w.Start(ctx); close(stopped) }()
deadline := time.Now().Add(100 * time.Millisecond)
for time.Now().Before(deadline) {
w.IsConnected()
}
cancel()
select {
case <-stopped:
case <-time.After(5 * time.Second):
t.Fatal("worker did not stop")
}
}