Fix flake caused by sampling signal counter too early.

TestFlowControlSignal has been flaking occasionally (somewhere around
0.5% on my machine using golang.org/x/tools/cmd/stress with -p
20). The intent was to sample the number of times the signal fired at
the moment a backend receives a connection from the proxy as an
alternative to test doubles, but the signal count was being
sampled (and recorded) immediately on calls to (net.Listener).Accept()
-- before blocking -- instead of immediately after unblocking.

The flake no longer occurs on my machine (again, using stress -p 20)
with this patch.
This commit is contained in:
Ben Luddy 2021-11-10 16:48:49 -05:00
parent b56dc43458
commit c2654a6851
No known key found for this signature in database
GPG Key ID: E01DF04B82AF03C0

View File

@ -921,8 +921,11 @@ type hookedListener struct {
}
func (wl *hookedListener) Accept() (net.Conn, error) {
wl.onAccept()
return wl.l.Accept()
conn, err := wl.l.Accept()
if err == nil {
wl.onAccept()
}
return conn, err
}
func (wl *hookedListener) Close() error {
@ -1015,10 +1018,13 @@ func TestFlowControlSignal(t *testing.T) {
req := tc.Request
req.URL = surl
_, err = server.Client().Do(&req)
res, err := server.Client().Do(&req)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if err := res.Body.Close(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if fired := (atomic.LoadInt32(&signalCountOnAccept) > 0); tc.SignalExpected && !fired {
t.Errorf("flow control signal expected but not fired")