Commit 58ebb03

Eric Bower  ·  2026-08-30 09:36:14 -0400 EDT
parent d8d0754
fix(pipe): flaky test
1 files changed,  +32, -6
+32, -6
......@@ -2337,7 +2337,25 @@ func TestSSH_WildcardSub(t *testing.T) {
23372337 }
23382338 }()
23392339
2340- time.Sleep(100 * time.Millisecond)
2340+ // Wait for subscriber to be registered in the PubSub broker
2341+ subReady := false
2342+ for i := 0; i < 100; i++ {
2343+ for topic, ch := range server.PipeHandler.PubSub.GetChannels() {
2344+ if topic == "alice/metric-drain*" {
2345+ for range ch.GetClients() {
2346+ subReady = true
2347+ break
2348+ }
2349+ }
2350+ }
2351+ if subReady {
2352+ break
2353+ }
2354+ time.Sleep(10 * time.Millisecond)
2355+ }
2356+ if !subReady {
2357+ t.Fatal("timed out waiting for wildcard subscriber to register")
2358+ }
23412359
23422360 // 2. Publish to "metric-drain-pgs"
23432361 pubClient1, err := user.NewClient()
......@@ -2375,12 +2393,20 @@ func TestSSH_WildcardSub(t *testing.T) {
23752393 }()
23762394 _ = pubSession2.Run("pub metric-drain-prose -b=false")
23772395
2378- time.Sleep(150 * time.Millisecond)
2379- _ = subSession.Close()
2396+ // Wait for both events to be received by the subscriber
2397+ deadline := time.Now().Add(5 * time.Second)
2398+ var output string
2399+ for time.Now().Before(deadline) {
2400+ bufMu.Lock()
2401+ output = buf.String()
2402+ bufMu.Unlock()
2403+ if strings.Contains(output, "pgs-event") && strings.Contains(output, "prose-event") {
2404+ break
2405+ }
2406+ time.Sleep(10 * time.Millisecond)
2407+ }
23802408
2381- bufMu.Lock()
2382- output := buf.String()
2383- bufMu.Unlock()
2409+ _ = subSession.Close()
23842410
23852411 if !strings.Contains(output, "pgs-event") {
23862412 t.Errorf("expected SSH wildcard subscriber output to contain 'pgs-event', got: %q", output)