Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed May 17, 2024
1 parent 5740160 commit 705bdc7
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions test/goaway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,33 +770,16 @@ 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 {
f, err := ct.fr.ReadFrame()
if err != nil {
Expand All @@ -818,9 +801,17 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
}
}
}()

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()

cc.WaitForStateChange(ctx, connectivity.Connecting)
cc.Close()
defer ct.conn.Close()
select {
case <-goAwayReceived:
case err := <-errCh:
Expand Down

0 comments on commit 705bdc7

Please sign in to comment.