Files
gohoarder/pkg/app/workers_test.go
T
lukaszraczylo 6f604367da fix(websocket): start the event loop and throttle drop warnings
The app built the websocket server but never called Start, so nothing read the 256-slot broadcast channel. After the first 256 events every event was dropped with a warning, and dashboard clients blocked forever on the unbuffered register channel, leaking a goroutine per connection and never receiving events. Run now starts the loop with the other workers. Dropped events are counted in gohoarder_websocket_events_dropped_total and warned about at most once a minute.
2026-11-23 12:56:32 +00:00

31 lines
758 B
Go

package app
import (
"context"
"testing"
"time"
)
// TestWorkersDrainTheBroadcastChannel pins that the app starts the websocket
// event loop: without it the 256-slot broadcast channel fills and every later
// event is dropped.
func TestWorkersDrainTheBroadcastChannel(t *testing.T) {
a := newTestApp(t, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
a.startWorkers(ctx)
const events = 1000
for i := 0; i < events; i++ {
a.wsServer.BroadcastEvent("cache_hit", map[string]interface{}{"i": i})
if i%200 == 0 {
time.Sleep(5 * time.Millisecond)
}
}
if dropped := a.wsServer.Dropped(); dropped != 0 {
t.Fatalf("dropped %d of %d events; the broadcast loop is not draining the channel", dropped, events)
}
}