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) { | |
| 701 | 701 | t.Fatalf("failed to start pub: %v", err) | |
| 702 | 702 | } | |
| 703 | 703 | ||
| 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) | |
| 709 | 730 | } | |
| 710 | - | output := string(initialOutput[:n]) | |
| 731 | + | ||
| 711 | 732 | if !strings.Contains(output, "waiting") { | |
| 712 | 733 | t.Errorf("expected 'waiting' message for blocking pub, got: %q", output) | |
| 713 | 734 | } |
| ... | ... | @@ -740,13 +761,13 @@ func TestPubSub_BlockingWaitsForSubscriber(t *testing.T) { | |
| 740 | 761 | ||
| 741 | 762 | // Subscriber should receive the message | |
| 742 | 763 | received := make([]byte, 100) | |
| 743 | - | n, err = subStdout.Read(received) | |
| 764 | + | nRead, err := subStdout.Read(received) | |
| 744 | 765 | if err != nil && err != io.EOF { | |
| 745 | 766 | t.Logf("read error: %v", err) | |
| 746 | 767 | } | |
| 747 | 768 | ||
| 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) | |
| 750 | 771 | } | |
| 751 | 772 | } | |
| 752 | 773 |