Commit 85e157e

Eric Bower  ·  2025-12-26 11:21:06 -0500 EST
parent aed3af6
fix(pipe): tests timing issue
1 files changed,  +30, -9
+30, -9
......@@ -701,13 +701,34 @@ func TestPubSub_BlockingWaitsForSubscriber(t *testing.T) {
701701 t.Fatalf("failed to start pub: %v", err)
702702 }
703703
704- // Read initial output - should indicate waiting for subscribers
705- initialOutput := make([]byte, 500)
706- n, err := pubStdout.Read(initialOutput)
707- if err != nil && err != io.EOF {
708- t.Fatalf("failed to read initial output: %v", err)
704+ // Read output until we see "waiting" message or timeout
705+ // Need to read in a loop because Read() may return partial data
706+ var output string
707+ readDone := make(chan struct{})
708+ go func() {
709+ buf := make([]byte, 1024)
710+ for {
711+ n, err := pubStdout.Read(buf)
712+ if n > 0 {
713+ output += string(buf[:n])
714+ if strings.Contains(output, "waiting") {
715+ close(readDone)
716+ return
717+ }
718+ }
719+ if err != nil {
720+ close(readDone)
721+ return
722+ }
723+ }
724+ }()
725+
726+ select {
727+ case <-readDone:
728+ case <-time.After(2 * time.Second):
729+ t.Fatalf("timeout waiting for 'waiting' message, got: %q", output)
709730 }
710- output := string(initialOutput[:n])
731+
711732 if !strings.Contains(output, "waiting") {
712733 t.Errorf("expected 'waiting' message for blocking pub, got: %q", output)
713734 }
......@@ -740,13 +761,13 @@ func TestPubSub_BlockingWaitsForSubscriber(t *testing.T) {
740761
741762 // Subscriber should receive the message
742763 received := make([]byte, 100)
743- n, err = subStdout.Read(received)
764+ nRead, err := subStdout.Read(received)
744765 if err != nil && err != io.EOF {
745766 t.Logf("read error: %v", err)
746767 }
747768
748- if !strings.Contains(string(received[:n]), testMessage) {
749- t.Errorf("subscriber did not receive blocking message, got: %q, want: %q", string(received[:n]), testMessage)
769+ if !strings.Contains(string(received[:nRead]), testMessage) {
770+ t.Errorf("subscriber did not receive blocking message, got: %q, want: %q", string(received[:nRead]), testMessage)
750771 }
751772 }
752773