ssh: synchronize unexpected response test
Wait for an ordered channel request after sending the unsolicited response flood. This ensures that the client mux has discarded the entire flood before SendRequest opens its response gate, avoiding confusion between an in-flight unsolicited response and the expected reply. This fixes TestChannelUnexpectedResponsesDiscarded from flaking, where otherwise running 1000000 iterations of the test with GOMAXPROCS=16 produced ~15 distinct failures of the form "expected success reply". Change-Id: Ic1125c1f44bd919a5cf32b889d331bbc94c06c25 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/817140 Reviewed-by: Neal Patel <neal@golang.org> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Neal Patel <nealpatel@google.com> Reviewed-by: Nicola Murino <nicola.murino@gmail.com> Auto-Submit: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
c757c9851f
commit
82adefa711
+16
-1
@@ -1181,6 +1181,13 @@ func TestChannelUnexpectedResponsesDiscarded(t *testing.T) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// Follow the flood with a request so the client can synchronize with
|
||||
// its mux loop. Once the client receives this request, the mux loop has
|
||||
// necessarily processed (and discarded) all the preceding responses.
|
||||
if _, err := serverCh.SendRequest("sync", false, nil); err != nil {
|
||||
done <- fmt.Errorf("send sync request: %w", err)
|
||||
return
|
||||
}
|
||||
// Echo any legitimate request back.
|
||||
for req := range serverCh.incomingRequests {
|
||||
if req.WantReply {
|
||||
@@ -1193,9 +1200,17 @@ func TestChannelUnexpectedResponsesDiscarded(t *testing.T) {
|
||||
done <- nil
|
||||
}()
|
||||
|
||||
req, ok := <-clientCh.incomingRequests
|
||||
if !ok {
|
||||
t.Fatal("channel closed before sync request")
|
||||
}
|
||||
if req.Type != "sync" {
|
||||
t.Fatalf("unexpected sync request type %q", req.Type)
|
||||
}
|
||||
|
||||
// If the flood had wedged the mux loop, this SendRequest would never
|
||||
// receive a reply.
|
||||
ok, err := clientCh.SendRequest("ping", true, []byte("hello"))
|
||||
ok, err = clientCh.SendRequest("ping", true, []byte("hello"))
|
||||
if err != nil {
|
||||
t.Fatalf("SendRequest: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user