Test verifies the scenario where there is no matching entry in the data cache, but there is a pending request. So, we expect no RLS request to be sent out. The pick should be queued and not delegated to the default target.
(t *testing.T)
| 173 | // cache, but there is a pending request. So, we expect no RLS request to be |
| 174 | // sent out. The pick should be queued and not delegated to the default target. |
| 175 | func (s) TestPick_DataCacheMiss_PendingEntryExists(t *testing.T) { |
| 176 | tests := []struct { |
| 177 | name string |
| 178 | withDefaultTarget bool |
| 179 | }{ |
| 180 | { |
| 181 | name: "withDefaultTarget", |
| 182 | withDefaultTarget: true, |
| 183 | }, |
| 184 | { |
| 185 | name: "withoutDefaultTarget", |
| 186 | withDefaultTarget: false, |
| 187 | }, |
| 188 | } |
| 189 | |
| 190 | for _, test := range tests { |
| 191 | t.Run(test.name, func(t *testing.T) { |
| 192 | // A unary interceptor which blocks the RouteLookup RPC on the fake |
| 193 | // RLS server until the test is done. The first RPC by the client |
| 194 | // will cause the LB policy to send out an RLS request. This will |
| 195 | // also lead to creation of a pending entry, and further RPCs by the |
| 196 | // client should not result in RLS requests being sent out. |
| 197 | rlsReqCh := make(chan struct{}, 1) |
| 198 | interceptor := func(ctx context.Context, _ any, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (resp any, err error) { |
| 199 | rlsReqCh <- struct{}{} |
| 200 | <-ctx.Done() |
| 201 | return nil, ctx.Err() |
| 202 | } |
| 203 | |
| 204 | // Start an RLS server and set the throttler to never throttle. |
| 205 | rlsServer, _ := rlstest.SetupFakeRLSServer(t, nil, grpc.UnaryInterceptor(interceptor)) |
| 206 | overrideAdaptiveThrottler(t, neverThrottlingThrottler()) |
| 207 | |
| 208 | // Build RLS service config with an optional default target. |
| 209 | rlsConfig := buildBasicRLSConfigWithChildPolicy(t, t.Name(), rlsServer.Address) |
| 210 | if test.withDefaultTarget { |
| 211 | _, defBackendAddress := startBackend(t) |
| 212 | rlsConfig.RouteLookupConfig.DefaultTarget = defBackendAddress |
| 213 | } |
| 214 | |
| 215 | // Register a manual resolver and push the RLS service config |
| 216 | // through it. |
| 217 | r := startManualResolverWithConfig(t, rlsConfig) |
| 218 | |
| 219 | // Create new client. |
| 220 | cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 221 | if err != nil { |
| 222 | t.Fatalf("Failed to create gRPC client: %v", err) |
| 223 | } |
| 224 | defer cc.Close() |
| 225 | |
| 226 | // Make an RPC that results in the RLS request being sent out. And |
| 227 | // since the RLS server is configured to block on the first request, |
| 228 | // this RPC will block until its context expires. This ensures that |
| 229 | // we have a pending cache entry for the duration of the test. |
| 230 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 231 | defer cancel() |
| 232 | go func() { |
nothing calls this directly
no test coverage detected