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

Method TestMinResolutionInterval

internal/resolver/dns/dns_resolver_test.go:1411–1445  ·  view source on GitHub ↗

Test verifies that changing [MinResolutionInterval] variable correctly effects the resolution behaviour

(t *testing.T)

Source from the content-addressed store, hash-verified

1409// Test verifies that changing [MinResolutionInterval] variable correctly effects
1410// the resolution behaviour
1411func (s) TestMinResolutionInterval(t *testing.T) {
1412 const target = "foo.bar.com"
1413
1414 overrideResolutionInterval(t, 1*time.Millisecond)
1415 tr := &testNetResolver{
1416 hostLookupTable: map[string][]string{
1417 "foo.bar.com": {"1.2.3.4", "5.6.7.8"},
1418 },
1419 txtLookupTable: map[string][]string{
1420 "_grpc_config.foo.bar.com": txtRecordServiceConfig(txtRecordGood),
1421 },
1422 }
1423 overrideNetResolver(t, tr)
1424
1425 r, stateCh, _ := buildResolverWithTestClientConn(t, target)
1426
1427 wantAddrs := []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}, {Addr: "5.6.7.8" + colonDefaultPort}}
1428 wantSC := mustParseServiceConfig(t, scJSON)
1429
1430 for i := 0; i < 5; i++ {
1431 // set context timeout slightly higher than the min resolution interval to make sure resolutions
1432 // happen successfully
1433 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
1434 defer cancel()
1435
1436 verifyUpdateFromResolver(ctx, t, stateCh, resolverUpdate{
1437 addrs: wantAddrs,
1438 endpoints: []resolver.Endpoint{
1439 {Addresses: []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}}},
1440 {Addresses: []resolver.Address{{Addr: "5.6.7.8" + colonDefaultPort}}},
1441 },
1442 serviceConfig: wantSC})
1443 r.ResolveNow(resolver.ResolveNowOptions{})
1444 }
1445}
1446
1447// TestMinResolutionInterval_NoExtraDelay verifies that there is no extra delay
1448// between two resolution requests apart from [MinResolutionInterval].

Callers

nothing calls this directly

Calls 7

txtRecordServiceConfigFunction · 0.85
overrideNetResolverFunction · 0.85
mustParseServiceConfigFunction · 0.85
verifyUpdateFromResolverFunction · 0.70
ResolveNowMethod · 0.65

Tested by

no test coverage detected