mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
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.
31 lines
758 B
Go
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)
|
|
}
|
|
}
|