diff --git a/pkg/xtcp/destinations_tcp_test.go b/pkg/xtcp/destinations_tcp_test.go index 78df5ef54..898b75019 100644 --- a/pkg/xtcp/destinations_tcp_test.go +++ b/pkg/xtcp/destinations_tcp_test.go @@ -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)