MCPcopy
hub / github.com/grpc/grpc-go / TestServiceConfigWaitForReady

Method TestServiceConfigWaitForReady

test/end2end_test.go:1200–1287  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1198}
1199
1200func (s) TestServiceConfigWaitForReady(t *testing.T) {
1201 te := testServiceConfigSetup(t, tcpClearRREnv)
1202 defer te.tearDown()
1203 r := manual.NewBuilderWithScheme("whatever")
1204
1205 // Case1: Client API set failfast to be false, and service config set wait_for_ready to be false, Client API should win, and the rpc will wait until deadline exceeds.
1206 te.resolverScheme = r.Scheme()
1207 cc := te.clientConn(grpc.WithResolvers(r))
1208 addrs := []resolver.Address{{Addr: te.srvAddr}}
1209 r.UpdateState(resolver.State{
1210 Addresses: addrs,
1211 ServiceConfig: parseServiceConfig(t, r, `{
1212 "methodConfig": [
1213 {
1214 "name": [
1215 {
1216 "service": "grpc.testing.TestService",
1217 "method": "EmptyCall"
1218 },
1219 {
1220 "service": "grpc.testing.TestService",
1221 "method": "FullDuplexCall"
1222 }
1223 ],
1224 "waitForReady": false,
1225 "timeout": ".001s"
1226 }
1227 ]
1228}`)})
1229
1230 tc := testgrpc.NewTestServiceClient(cc)
1231
1232 // Make sure service config has been processed by grpc.
1233 for {
1234 if cc.GetMethodConfig("/grpc.testing.TestService/FullDuplexCall").WaitForReady != nil {
1235 break
1236 }
1237 time.Sleep(time.Millisecond)
1238 }
1239 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1240 defer cancel()
1241 // The following RPCs are expected to become non-fail-fast ones with 1ms deadline.
1242 var err error
1243 if _, err = tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
1244 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded)
1245 }
1246 if _, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true)); status.Code(err) != codes.DeadlineExceeded {
1247 t.Fatalf("TestService/FullDuplexCall(_) = _, %v, want %s", err, codes.DeadlineExceeded)
1248 }
1249
1250 // Generate a service config update.
1251 // Case2:Client API set failfast to be false, and service config set wait_for_ready to be true, and the rpc will wait until deadline exceeds.
1252 r.UpdateState(resolver.State{
1253 Addresses: addrs,
1254 ServiceConfig: parseServiceConfig(t, r, `{
1255 "methodConfig": [
1256 {
1257 "name": [

Callers

nothing calls this directly

Calls 14

EmptyCallMethod · 0.95
FullDuplexCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
WaitForReadyFunction · 0.92
testServiceConfigSetupFunction · 0.85
GetMethodConfigMethod · 0.80
CodeMethod · 0.80
parseServiceConfigFunction · 0.70
SchemeMethod · 0.65
UpdateStateMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected