Skip to content

Commit

Permalink
test: speed up TestServiceConfigTimeoutTD from 1.8s to 0.03s (#6571)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Aug 23, 2023
1 parent d51b3f4 commit 7d35b8e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/service_config_deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
te, ch := testServiceConfigSetupTD(t, e)
defer te.tearDown()

// 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.
// 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.
mc := grpc.MethodConfig{
Timeout: newDuration(time.Hour),
}
Expand All @@ -192,19 +194,21 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
cc := te.clientConn()
tc := testgrpc.NewTestServiceClient(cc)
// The following RPCs are expected to become non-fail-fast ones with 1ns deadline.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded)
}
cancel()
ctx, cancel = context.WithTimeout(context.Background(), defaultTestShortTimeout)
ctx, cancel = context.WithTimeout(context.Background(), time.Nanosecond)
if _, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
t.Fatalf("TestService/FullDuplexCall(_) = _, %v, want %s", err, codes.DeadlineExceeded)
}
cancel()

// Generate a service config update.
// 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.
// Case2: Client API sets timeout to be the default and ServiceConfig sets
// timeout to be 1ns. Timeout should be 1ns (min of 1ns and the default)
// and the rpc will wait until deadline exceeds.
mc.Timeout = newDuration(time.Nanosecond)
m = make(map[string]grpc.MethodConfig)
m["/grpc.testing.TestService/EmptyCall"] = mc
Expand All @@ -217,7 +221,7 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {
// Wait for the new service config to take effect.
ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
for ; ctx.Err() == nil; <-time.After(time.Millisecond) {
mc = cc.GetMethodConfig("/grpc.testing.TestService/FullDuplexCall")
if *mc.Timeout == time.Nanosecond {
break
Expand All @@ -229,12 +233,12 @@ func testServiceConfigTimeoutTD(t *testing.T, e env) {

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

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

Expand Down

0 comments on commit 7d35b8e

Please sign in to comment.