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

Method TestProducerBackoff

orca/producer_test.go:273–398  ·  view source on GitHub ↗

TestProducerBackoff verifies that the ORCA producer applies the proper backoff after stream failures.

(t *testing.T)

Source from the content-addressed store, hash-verified

271// TestProducerBackoff verifies that the ORCA producer applies the proper
272// backoff after stream failures.
273func (s) TestProducerBackoff(t *testing.T) {
274 grpctest.ExpectErrorN("injected error", 4)
275
276 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
277 defer cancel()
278
279 // Provide a convenient way to expect backoff calls and return a minimal
280 // value.
281 const backoffShouldNotBeCalled = 9999 // Use to assert backoff function is not called.
282 const backoffAllowAny = -1 // Use to ignore any backoff calls.
283 expectedBackoff := atomic.Int32{}
284 expectedBackoff.Store(backoffAllowAny)
285 oldBackoff := internal.DefaultBackoffFunc
286 internal.DefaultBackoffFunc = func(got int) time.Duration {
287 if expectedBackoff.Load() == backoffShouldNotBeCalled {
288 t.Errorf("Unexpected backoff call; parameter = %v", got)
289 } else if expectedBackoff.Load() != backoffAllowAny {
290 if got != int(expectedBackoff.Load()) {
291 t.Errorf("Unexpected backoff received; got %v want %v", got, expectedBackoff.Load())
292 }
293 }
294 return time.Millisecond
295 }
296 defer func() { internal.DefaultBackoffFunc = oldBackoff }()
297
298 // Initialize listener for our ORCA server.
299 lis, err := testutils.LocalTCPListener()
300 if err != nil {
301 t.Fatal(err)
302 }
303
304 // Register our fake ORCA service.
305 s := grpc.NewServer()
306 fake := newFakeORCAService()
307 defer fake.close()
308 v3orcaservicegrpc.RegisterOpenRcaServiceServer(s, fake)
309 go s.Serve(lis)
310 defer s.Stop()
311
312 // Define the report interval and a function to wait for it to be sent to
313 // the server.
314 const reportInterval = 123 * time.Second
315 awaitRequest := func(interval time.Duration) {
316 select {
317 case req := <-fake.reqCh:
318 if got := req.GetReportInterval().AsDuration(); got != interval {
319 t.Errorf("Unexpected report interval; got %v want %v", got, interval)
320 }
321 case <-ctx.Done():
322 t.Fatalf("Did not receive client request")
323 }
324 }
325
326 // Create our client with an OOB listener in the LB policy it selects.
327 r := manual.NewBuilderWithScheme("whatever")
328 oobLis := newTestOOBListener()
329
330 lisOpts := orca.OOBListenerOptions{ReportInterval: reportInterval}

Callers

nothing calls this directly

Calls 15

ExpectErrorNFunction · 0.92
LocalTCPListenerFunction · 0.92
NewServerFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
NewClientFunction · 0.92
ErrorfFunction · 0.92
newFakeORCAServiceFunction · 0.85
newTestOOBListenerFunction · 0.85

Tested by

no test coverage detected