-
Notifications
You must be signed in to change notification settings - Fork 4.5k
test/gracefulstop: use stubserver instead of testservice implementation #7907
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
Changes from all commits
6da62e6
a73e23c
0bfd0f6
3d059c2
a623c8a
61374bc
1df0441
f976afd
2190f99
3259912
7c28584
a7699ba
c70a990
29216bd
fddce60
fe24361
b415690
d38ed6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ import ( | |
"context" | ||
"fmt" | ||
"net" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -110,62 +109,56 @@ 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, | ||
FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error { | ||
_, err := stream.Recv() | ||
if err != nil { | ||
if _, err := stream.Recv(); err != nil { | ||
return err | ||
} | ||
return stream.Send(&testpb.StreamingOutputCallResponse{}) | ||
}, | ||
S: grpc.NewServer(), | ||
} | ||
s := grpc.NewServer() | ||
testgrpc.RegisterTestServiceServer(s, ss) | ||
// 1. Start Server and start serving by calling Serve(). | ||
stubserver.StartTestService(t, ss) | ||
purnesh42H marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 1. Start Server | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't revert the step number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
s.Serve(dlis) | ||
wg.Done() | ||
}() | ||
|
||
// 2. GracefulStop() Server after listener's Accept is called, but don't | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't revert the step number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// allow Accept() to exit when Close() is called on it. | ||
// 2. Call GracefulStop from a goroutine. It will trigger Close on the | ||
// listener, but the listener will not actually close until a connection | ||
// is accepted. | ||
gracefulStopDone := make(chan struct{}) | ||
<-dlis.acceptCalled | ||
wg.Add(1) | ||
go func() { | ||
s.GracefulStop() | ||
wg.Done() | ||
ss.S.GracefulStop() | ||
close(gracefulStopDone) | ||
}() | ||
|
||
// 3. Create a new connection to the server after listener.Close() is called. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't revert the step number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
// Server should close this connection immediately, before handshaking. | ||
// Server should close this connection immediately, before handshaking. | ||
|
||
<-dlis.closeCalled // Block until GracefulStop calls dlis.Close() | ||
|
||
// Now dial. The listener's Accept method will return a valid connection, | ||
// even though GracefulStop has closed the listener. | ||
// Dial the server. This will cause a connection to be accepted. This will | ||
// also unblock the Close method . | ||
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) | ||
} | ||
client := testgrpc.NewTestServiceClient(cc) | ||
defer cc.Close() | ||
|
||
// 4. Send an RPC on the new connection. | ||
// 4. Make an RPC. | ||
// The server would send a GOAWAY first, but we are delaying the server's | ||
// writes for now until the client writes more than the preface. | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
if _, err = client.FullDuplexCall(ctx); err == nil || status.Code(err) != codes.Unavailable { | ||
t.Fatalf("FullDuplexCall= _, %v; want _, <status code Unavailable>", err) | ||
} | ||
cancel() | ||
wg.Wait() | ||
<-gracefulStopDone | ||
} | ||
|
||
// TestGracefulStopClosesConnAfterLastStream ensures that a server closes the | ||
|
Uh oh!
There was an error while loading. Please reload this page.