Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pkg/xtcp/destinations_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,27 @@ func TestTCPDest_writeTimeout(t *testing.T) {
t.Fatalf("Send: %v", err)
}

// The write must fail within ~attempts*timeout, not park for the
// retransmit window. Poll the write-error counter.
// The envelope must be dropped within ~attempts*timeout, not park for
// the retransmit window. Poll the drop, the worker's last step: the
// first write error is counted when the deadline fires, the second
// attempt fails at once on the closed pipe, and only then is the drop
// counted, so polling the write-error counter and then reading the
// drop raced the second attempt.
deadline := time.After(5 * time.Second)
for {
if got := testutil.ToFloat64(x.pC.WithLabelValues("destTCP", "Write", "error")); got >= 1 {
if got := testutil.ToFloat64(x.pC.WithLabelValues("destTCP", "dropped", "error")); got >= 1 {
break
}
select {
case <-deadline:
t.Fatalf("the blocked write never errored (elapsed %v)", time.Since(started))
t.Fatalf("the blocked write was never dropped (elapsed %v, write errors %v)",
time.Since(started), testutil.ToFloat64(x.pC.WithLabelValues("destTCP", "Write", "error")))
default:
time.Sleep(20 * time.Millisecond)
}
}
if got := testutil.ToFloat64(x.pC.WithLabelValues("destTCP", "dropped", "error")); got < 1 {
t.Errorf("destTCP dropped counter = %v, want >= 1 (attempts exhausted)", got)
if got := testutil.ToFloat64(x.pC.WithLabelValues("destTCP", "Write", "error")); got != float64(td.attempts) {
t.Errorf("destTCP write errors = %v, want %d (one per attempt)", got, td.attempts)
}
if err := dest.Close(); err != nil {
t.Errorf("Close: %v", err)
Expand Down