Skip to content

Commit

Permalink
renaming d as dialer and removing sync.waitgroup()
Browse files Browse the repository at this point in the history
  • Loading branch information
pvsravani committed Dec 27, 2024
1 parent a623c8a commit 61374bc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions test/gracefulstop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"fmt"
"net"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -110,7 +109,6 @@ func (s) TestGracefulStop(t *testing.T) {
closeCalled: make(chan struct{}),
allowCloseCh: make(chan struct{}),
}
d := func(ctx context.Context, _ string) (net.Conn, error) { return dlis.Dial(ctx) }

ss := &stubserver.StubServer{
Listener: dlis,
Expand All @@ -126,17 +124,16 @@ func (s) TestGracefulStop(t *testing.T) {
stubserver.StartTestService(t, ss)

// 1. Start Server
wg := sync.WaitGroup{}

// 2. GracefulStop() Server after listener's Accept is called, but don't
// allow Accept() to exit when Close() is called on it.
<-dlis.acceptCalled
wg.Add(1)
done := make(chan struct{})
go func() {
<-dlis.acceptCalled
ss.S.GracefulStop()
wg.Done()
close(done)
}()

// 2. GracefulStop() Server after listener's Accept is called, but don't
// allow Accept() to exit when Close() is called on it.

// 3. Create a new connection to the server after listener.Close() is called.
// Server should close this connection immediately, before handshaking.

Expand All @@ -146,7 +143,8 @@ func (s) TestGracefulStop(t *testing.T) {
// even though GracefulStop has closed the listener.
ctx, dialCancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer dialCancel()
cc, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d))
dialer := func(ctx context.Context, _ string) (net.Conn, error) { return dlis.Dial(ctx) }
cc, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialer))
if err != nil {
t.Fatalf("grpc.DialContext(_, %q, _) = %v", lis.Addr().String(), err)
}
Expand All @@ -161,7 +159,7 @@ func (s) TestGracefulStop(t *testing.T) {
t.Fatalf("FullDuplexCall= _, %v; want _, <status code Unavailable>", err)
}
cancel()
wg.Wait()
<-done
}

// TestGracefulStopClosesConnAfterLastStream ensures that a server closes the
Expand Down

0 comments on commit 61374bc

Please sign in to comment.