From 61374bc3276efbd1023a4c98062511cbf07a87ca Mon Sep 17 00:00:00 2001 From: Pasupuleti Sravani Date: Fri, 27 Dec 2024 10:17:29 +0000 Subject: [PATCH] renaming d as dialer and removing sync.waitgroup() --- test/gracefulstop_test.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/gracefulstop_test.go b/test/gracefulstop_test.go index 798882ee297d..4c4ea1f3abff 100644 --- a/test/gracefulstop_test.go +++ b/test/gracefulstop_test.go @@ -22,7 +22,6 @@ import ( "context" "fmt" "net" - "sync" "testing" "time" @@ -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, @@ -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. @@ -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) } @@ -161,7 +159,7 @@ func (s) TestGracefulStop(t *testing.T) { t.Fatalf("FullDuplexCall= _, %v; want _, ", err) } cancel() - wg.Wait() + <-done } // TestGracefulStopClosesConnAfterLastStream ensures that a server closes the