Waits for a state update from the DNS resolver.
(ctx context.Context, t *testing.T, stateCh chan resolver.State, want resolverUpdate)
| 177 | |
| 178 | // Waits for a state update from the DNS resolver. |
| 179 | func verifyUpdateFromResolver(ctx context.Context, t *testing.T, stateCh chan resolver.State, want resolverUpdate) { |
| 180 | t.Helper() |
| 181 | |
| 182 | var state resolver.State |
| 183 | select { |
| 184 | case <-ctx.Done(): |
| 185 | t.Fatal("Timeout when waiting for a state update from the resolver") |
| 186 | case state = <-stateCh: |
| 187 | } |
| 188 | |
| 189 | wantResolverState := resolver.State{ |
| 190 | Addresses: want.addrs, |
| 191 | Endpoints: want.endpoints, |
| 192 | ServiceConfig: &serviceconfig.ParseResult{ |
| 193 | Config: want.serviceConfig, |
| 194 | }, |
| 195 | } |
| 196 | if len(want.balancerAddrs) > 0 { |
| 197 | wantResolverState = grpclbstate.Set(wantResolverState, &grpclbstate.State{ |
| 198 | BalancerAddresses: want.balancerAddrs, |
| 199 | }) |
| 200 | } |
| 201 | |
| 202 | scComparer := cmp.Comparer(func(a, b *serviceconfig.ParseResult) bool { |
| 203 | var scA serviceconfig.Config |
| 204 | var scB serviceconfig.Config |
| 205 | if a != nil { |
| 206 | scA = a.Config |
| 207 | } |
| 208 | if b != nil { |
| 209 | scB = b.Config |
| 210 | } |
| 211 | return internal.EqualServiceConfigForTesting(scA, scB) |
| 212 | }) |
| 213 | attrComparer := cmp.Comparer(func(a, b *attributes.Attributes) bool { |
| 214 | if a == nil && b == nil { |
| 215 | return true |
| 216 | } |
| 217 | if a == nil || b == nil { |
| 218 | return false |
| 219 | } |
| 220 | gA := grpclbstate.Get(resolver.State{Attributes: a}) |
| 221 | gB := grpclbstate.Get(resolver.State{Attributes: b}) |
| 222 | return cmp.Equal(gA.BalancerAddresses, gB.BalancerAddresses) |
| 223 | }) |
| 224 | if diff := cmp.Diff(wantResolverState, state, cmpopts.EquateEmpty(), scComparer, attrComparer); diff != "" { |
| 225 | t.Fatalf("Got unexpected resolver.State (-want +got):\n%s", diff) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // This is the service config used by the fake net.Resolver in its TXT record. |
| 230 | // - it contains an array of 5 entries |
no test coverage detected