Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test ClientSendsAGoAway #7224

Merged
merged 3 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 17 additions & 22 deletions test/goaway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,36 +770,20 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
if err != nil {
t.Fatalf("error listening: %v", err)
}
ctCh := testutils.NewChannel()
defer lis.Close()
goAwayReceived := make(chan struct{})
errCh := make(chan error)
go func() {
conn, err := lis.Accept()
if err != nil {
t.Errorf("error in lis.Accept(): %v", err)
}
ct := newClientTester(t, conn)
ctCh.Send(ct)
}()
defer lis.Close()

cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("error dialing: %v", err)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

val, err := ctCh.Receive(ctx)
if err != nil {
t.Fatalf("timeout waiting for client transport (should be given after http2 creation)")
}
ct := val.(*clientTester)
goAwayReceived := make(chan struct{})
errCh := make(chan error)
go func() {
defer ct.conn.Close()
for {
dfawley marked this conversation as resolved.
Show resolved Hide resolved
f, err := ct.fr.ReadFrame()
if err != nil {
errCh <- fmt.Errorf("error reading frame: %v", err)
return
}
switch fr := f.(type) {
Expand All @@ -808,6 +792,7 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
if fr.ErrCode == http2.ErrCodeNo {
t.Logf("GoAway received from client")
close(goAwayReceived)
return
}
default:
t.Errorf("server tester received unexpected frame type %T", f)
Expand All @@ -816,8 +801,18 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
}
}
}()

cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("error dialing: %v", err)
}
cc.Connect()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

testutils.AwaitState(ctx, t, cc, connectivity.Ready)
cc.Close()
defer ct.conn.Close()
select {
case <-goAwayReceived:
case err := <-errCh:
Expand Down