()
| 416 | } |
| 417 | |
| 418 | func (s *proxyTestSuite) TestResiliencyUnary() { |
| 419 | const message = "Ciao mamma guarda come mi diverto" |
| 420 | |
| 421 | // Set the resiliency policy and the number of simulated failures in a row |
| 422 | s.setupResiliency() |
| 423 | defer func() { |
| 424 | s.policyDef = nil |
| 425 | }() |
| 426 | |
| 427 | s.T().Run("retries", func(t *testing.T) { |
| 428 | s.service.simulatePingFailures.Store(2) |
| 429 | defer func() { |
| 430 | s.service.simulatePingFailures.Store(0) |
| 431 | }() |
| 432 | |
| 433 | meter := setupMetrics(s) |
| 434 | t.Cleanup(func() { |
| 435 | meter.Stop() |
| 436 | }) |
| 437 | |
| 438 | ctx, cancel := s.ctx() |
| 439 | defer cancel() |
| 440 | ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(diagConsts.GRPCProxyAppIDKey, testAppID)) |
| 441 | |
| 442 | // Reset callCount before this test |
| 443 | s.service.pingCallCount.Store(0) |
| 444 | |
| 445 | res, err := s.testClient.Ping(ctx, &pb.PingRequest{Value: message}) |
| 446 | require.NoError(t, err, "Ping should succeed after retrying") |
| 447 | require.NotNil(t, res, "Response should not be nil") |
| 448 | require.Equal(t, int32(3), s.service.pingCallCount.Load()) |
| 449 | require.Equal(t, message, res.GetValue()) |
| 450 | |
| 451 | assertRequestSentMetrics(t, meter, "unary", 3, nil) |
| 452 | |
| 453 | rows, err := meter.RetrieveData(serviceInvocationResponseRecvName) |
| 454 | require.NoError(t, err) |
| 455 | assert.Len(t, rows, 2) |
| 456 | // 2 Ping failures |
| 457 | assert.Equal(t, int64(2), diag.GetCountValueForObservationWithTagSet( |
| 458 | rows, map[tag.Tag]bool{diag.NewTag("status", strconv.Itoa(int(codes.Internal))): true})) |
| 459 | // 1 success |
| 460 | assert.Equal(t, int64(1), diag.GetCountValueForObservationWithTagSet( |
| 461 | rows, map[tag.Tag]bool{diag.NewTag("status", strconv.Itoa(int(codes.OK))): true})) |
| 462 | }) |
| 463 | |
| 464 | s.T().Run("timeouts", func(t *testing.T) { |
| 465 | // The delay is longer than the timeout set in the resiliency policy (500ms) |
| 466 | s.service.simulateDelay.Store(800) |
| 467 | defer func() { |
| 468 | s.service.simulateDelay.Store(0) |
| 469 | }() |
| 470 | |
| 471 | // Reset callCount before this test |
| 472 | s.service.pingCallCount.Store(0) |
| 473 | |
| 474 | meter := setupMetrics(s) |
| 475 | t.Cleanup(func() { |
nothing calls this directly
no test coverage detected