Skip to content

Commit 7d35b8e

Browse files
authored
test: speed up TestServiceConfigTimeoutTD from 1.8s to 0.03s (#6571)
1 parent d51b3f4 commit 7d35b8e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/service_config_deprecated_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
177177
te, ch := testServiceConfigSetupTD(t, e)
178178
defer te.tearDown()
179179

180-
// Case1: Client API sets timeout to be 1ns and ServiceConfig sets timeout to be 1hr. Timeout should be 1ns (min of 1ns and 1hr) and the rpc will wait until deadline exceeds.
180+
// Case1: Client API sets timeout to be 1ns and ServiceConfig sets timeout
181+
// to be 1hr. Timeout should be 1ns (min of 1ns and 1hr) and the rpc will
182+
// wait until deadline exceeds.
181183
mc := grpc.MethodConfig{
182184
Timeout: newDuration(time.Hour),
183185
}
@@ -192,19 +194,21 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
192194
cc := te.clientConn()
193195
tc := testgrpc.NewTestServiceClient(cc)
194196
// The following RPCs are expected to become non-fail-fast ones with 1ns deadline.
195-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
197+
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
196198
if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
197199
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded)
198200
}
199201
cancel()
200-
ctx, cancel = context.WithTimeout(context.Background(), defaultTestShortTimeout)
202+
ctx, cancel = context.WithTimeout(context.Background(), time.Nanosecond)
201203
if _, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
202204
t.Fatalf("TestService/FullDuplexCall(_) = _, %v, want %s", err, codes.DeadlineExceeded)
203205
}
204206
cancel()
205207

206208
// Generate a service config update.
207-
// Case2: Client API sets timeout to be 1hr and ServiceConfig sets timeout to be 1ns. Timeout should be 1ns (min of 1ns and 1hr) and the rpc will wait until deadline exceeds.
209+
// Case2: Client API sets timeout to be the default and ServiceConfig sets
210+
// timeout to be 1ns. Timeout should be 1ns (min of 1ns and the default)
211+
// and the rpc will wait until deadline exceeds.
208212
mc.Timeout = newDuration(time.Nanosecond)
209213
m = make(map[string]grpc.MethodConfig)
210214
m["/grpc.testing.TestService/EmptyCall"] = mc
@@ -217,7 +221,7 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
217221
// Wait for the new service config to take effect.
218222
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
219223
defer cancel()
220-
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
224+
for ; ctx.Err() == nil; <-time.After(time.Millisecond) {
221225
mc = cc.GetMethodConfig("/grpc.testing.TestService/FullDuplexCall")
222226
if *mc.Timeout == time.Nanosecond {
223227
break
@@ -229,12 +233,12 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
229233

230234
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
231235
defer cancel()
232-
if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
233-
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded)
236+
if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded || ctx.Err() != nil {
237+
t.Fatalf("TestService/EmptyCall(_, _) = _, %v and ctx.Err() = %v; want _, %s and ctx.Err() = nil", err, ctx.Err(), codes.DeadlineExceeded)
234238
}
235239

236-
if _, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
237-
t.Fatalf("TestService/FullDuplexCall(_) = _, %v, want %s", err, codes.DeadlineExceeded)
240+
if _, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded || ctx.Err() != nil {
241+
t.Fatalf("TestService/FullDuplexCall(_) = _, %v and ctx.Err() = %v; want _, %s and ctx.Err() = nil", err, ctx.Err(), codes.DeadlineExceeded)
238242
}
239243
}
240244

0 commit comments

Comments
 (0)