Tests the case where the DNS resolver is asked to re-resolve by invoking the ResolveNow method.
(t *testing.T)
| 685 | // Tests the case where the DNS resolver is asked to re-resolve by invoking the |
| 686 | // ResolveNow method. |
| 687 | func (s) TestDNSResolver_ResolveNow(t *testing.T) { |
| 688 | const target = "foo.bar.com" |
| 689 | |
| 690 | overrideResolutionInterval(t, 0) |
| 691 | overrideTimeAfterFunc(t, 0) |
| 692 | tr := &testNetResolver{ |
| 693 | hostLookupTable: map[string][]string{ |
| 694 | "foo.bar.com": {"1.2.3.4", "5.6.7.8"}, |
| 695 | }, |
| 696 | txtLookupTable: map[string][]string{ |
| 697 | "_grpc_config.foo.bar.com": txtRecordServiceConfig(txtRecordGood), |
| 698 | }, |
| 699 | } |
| 700 | overrideNetResolver(t, tr) |
| 701 | |
| 702 | r, stateCh, _ := buildResolverWithTestClientConn(t, target) |
| 703 | |
| 704 | // Verify that the first update pushed by the resolver matches expectations. |
| 705 | wantAddrs := []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}, {Addr: "5.6.7.8" + colonDefaultPort}} |
| 706 | wantSC := mustParseServiceConfig(t, scJSON) |
| 707 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 708 | defer cancel() |
| 709 | verifyUpdateFromResolver(ctx, t, stateCh, resolverUpdate{ |
| 710 | addrs: wantAddrs, |
| 711 | endpoints: []resolver.Endpoint{ |
| 712 | {Addresses: []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}}}, |
| 713 | {Addresses: []resolver.Address{{Addr: "5.6.7.8" + colonDefaultPort}}}, |
| 714 | }, |
| 715 | serviceConfig: wantSC, |
| 716 | }) |
| 717 | |
| 718 | // Update state in the fake net.Resolver to return only one address and a |
| 719 | // new service config. |
| 720 | tr.UpdateHostLookupTable(map[string][]string{target: {"1.2.3.4"}}) |
| 721 | tr.UpdateTXTLookupTable(map[string][]string{ |
| 722 | "_grpc_config.foo.bar.com": txtRecordServiceConfig(`[{"serviceConfig":{"loadBalancingPolicy": "grpclb"}}]`), |
| 723 | }) |
| 724 | |
| 725 | // Ask the resolver to re-resolve and verify that the new update matches |
| 726 | // expectations. |
| 727 | r.ResolveNow(resolver.ResolveNowOptions{}) |
| 728 | wantAddrs = []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}} |
| 729 | wantSC = mustParseServiceConfig(t, `{"loadBalancingPolicy": "grpclb"}`) |
| 730 | verifyUpdateFromResolver(ctx, t, stateCh, resolverUpdate{ |
| 731 | addrs: wantAddrs, |
| 732 | endpoints: []resolver.Endpoint{{Addresses: []resolver.Address{{Addr: "1.2.3.4" + colonDefaultPort}}}}, |
| 733 | serviceConfig: wantSC, |
| 734 | }) |
| 735 | |
| 736 | // Update state in the fake resolver to return no addresses and the same |
| 737 | // service config as before. |
| 738 | tr.UpdateHostLookupTable(map[string][]string{target: nil}) |
| 739 | |
| 740 | // Ask the resolver to re-resolve and verify that the new update matches |
| 741 | // expectations. |
| 742 | r.ResolveNow(resolver.ResolveNowOptions{}) |
| 743 | verifyUpdateFromResolver(ctx, t, stateCh, resolverUpdate{serviceConfig: wantSC}) |
| 744 | } |
nothing calls this directly
no test coverage detected