From 7d35b8ece0131eb23b5069de26ca067fd76e4da2 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Wed, 23 Aug 2023 08:53:38 -0700 Subject: [PATCH] test: speed up TestServiceConfigTimeoutTD from 1.8s to 0.03s (#6571) --- test/service_config_deprecated_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/service_config_deprecated_test.go b/test/service_config_deprecated_test.go index 6277380d72d1..a1fd44d853d9 100644 --- a/test/service_config_deprecated_test.go +++ b/test/service_config_deprecated_test.go @@ -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), } @@ -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 @@ -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 @@ -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) } }