@@ -2569,31 +2569,35 @@ TEST_F(TokenFetcherCredentialsTest, FetchFails) {
2569
2569
run_after_duration = duration;
2570
2570
});
2571
2571
ExecCtx exec_ctx;
2572
- creds_->AddResult (kExpectedError );
2573
2572
// First request will trigger a fetch, which will fail.
2573
+ LOG (INFO) << " Sending first RPC." ;
2574
+ creds_->AddResult (kExpectedError );
2574
2575
auto state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2575
2576
/* expect_delay=*/ true );
2576
2577
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2577
2578
kTestPath );
2578
2579
EXPECT_EQ (creds_->num_fetches (), 1 );
2579
2580
while (!run_after_duration.has_value ()) event_engine_->Tick ();
2580
2581
// Make sure backoff was set for the right period.
2581
- // This is 1 second (initial backoff) minus 1ms for the tick needed above.
2582
2582
EXPECT_EQ (run_after_duration, std::chrono::seconds (1 ));
2583
2583
run_after_duration.reset ();
2584
- // Start a new call now, which will be queued and then eventually
2585
- // resumed when the next fetch happens.
2584
+ // Start a new call now, which will fail because we're in backoff.
2585
+ LOG (INFO) << " Sending second RPC. " ;
2586
2586
state = RequestMetadataState::NewInstance (
2587
- absl::OkStatus () , " authorization: foo" , /* expect_delay=*/ true );
2587
+ kExpectedError , " authorization: foo" , /* expect_delay=*/ false );
2588
2588
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2589
2589
kTestPath );
2590
- // Tick until the next fetch starts.
2591
- creds_->AddResult (MakeToken (" foo" ));
2590
+ EXPECT_EQ (creds_->num_fetches (), 1 );
2591
+ // Tick until backoff expires.
2592
+ LOG (INFO) << " Waiting for backoff." ;
2592
2593
event_engine_->TickUntilIdle ();
2593
- EXPECT_EQ (creds_->num_fetches (), 2 );
2594
- // A call started now should use the new cached data.
2594
+ EXPECT_EQ (creds_->num_fetches (), 1 );
2595
+ // Starting another call should trigger a new fetch, which will
2596
+ // succeed this time.
2597
+ LOG (INFO) << " Sending third RPC." ;
2598
+ creds_->AddResult (MakeToken (" foo" ));
2595
2599
state = RequestMetadataState::NewInstance (
2596
- absl::OkStatus (), " authorization: foo" , /* expect_delay=*/ false );
2600
+ absl::OkStatus (), " authorization: foo" , /* expect_delay=*/ true );
2597
2601
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2598
2602
kTestPath );
2599
2603
EXPECT_EQ (creds_->num_fetches (), 2 );
@@ -2607,8 +2611,9 @@ TEST_F(TokenFetcherCredentialsTest, Backoff) {
2607
2611
run_after_duration = duration;
2608
2612
});
2609
2613
ExecCtx exec_ctx;
2610
- creds_->AddResult (kExpectedError );
2611
2614
// First request will trigger a fetch, which will fail.
2615
+ LOG (INFO) << " Sending first RPC." ;
2616
+ creds_->AddResult (kExpectedError );
2612
2617
auto state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2613
2618
/* expect_delay=*/ true );
2614
2619
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
@@ -2618,64 +2623,53 @@ TEST_F(TokenFetcherCredentialsTest, Backoff) {
2618
2623
// Make sure backoff was set for the right period.
2619
2624
EXPECT_EQ (run_after_duration, std::chrono::seconds (1 ));
2620
2625
run_after_duration.reset ();
2621
- // Start a new call now, which will be queued and then eventually
2622
- // resumed when the next fetch happens.
2626
+ // Start a new call now, which will fail because we're in backoff.
2627
+ LOG (INFO) << " Sending second RPC. " ;
2623
2628
state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2624
- /* expect_delay=*/ true );
2629
+ /* expect_delay=*/ false );
2625
2630
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2626
2631
kTestPath );
2627
- // Tick until the next fetch fails and the backoff timer starts again.
2632
+ EXPECT_EQ (creds_->num_fetches (), 1 );
2633
+ // Tick until backoff expires.
2634
+ LOG (INFO) << " Waiting for backoff." ;
2635
+ event_engine_->TickUntilIdle ();
2636
+ EXPECT_EQ (creds_->num_fetches (), 1 );
2637
+ // Starting another call should trigger a new fetch, which will again fail.
2638
+ LOG (INFO) << " Sending third RPC." ;
2628
2639
creds_->AddResult (kExpectedError );
2629
- while (!run_after_duration.has_value ()) event_engine_->Tick ();
2630
- EXPECT_EQ (creds_->num_fetches (), 2 );
2631
- // The backoff time should be longer now. We account for jitter here.
2632
- EXPECT_EQ (run_after_duration, std::chrono::milliseconds (1600 ))
2633
- << " actual: " << run_after_duration->count ();
2634
- run_after_duration.reset ();
2635
- // Start another new call to trigger another new fetch once the
2636
- // backoff expires.
2637
2640
state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2638
2641
/* expect_delay=*/ true );
2639
2642
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2640
2643
kTestPath );
2641
- // Tick until the next fetch starts.
2642
- creds_->AddResult (kExpectedError );
2644
+ EXPECT_EQ (creds_->num_fetches (), 2 );
2643
2645
while (!run_after_duration.has_value ()) event_engine_->Tick ();
2644
- EXPECT_EQ (creds_->num_fetches (), 3 );
2645
- // Check backoff time again.
2646
- EXPECT_EQ (run_after_duration, std::chrono::milliseconds (2560 ))
2646
+ // The backoff time should be longer now.
2647
+ EXPECT_EQ (run_after_duration, std::chrono::milliseconds (1600 ))
2647
2648
<< " actual: " << run_after_duration->count ();
2648
- }
2649
-
2650
- TEST_F (TokenFetcherCredentialsTest, FetchNotStartedAfterBackoffWithoutRpc) {
2651
- const absl::Status kExpectedError = absl::UnavailableError (" bummer, dude" );
2652
- absl::optional<FuzzingEventEngine::Duration > run_after_duration;
2653
- event_engine_->SetRunAfterDurationCallback (
2654
- [&](FuzzingEventEngine::Duration duration) {
2655
- run_after_duration = duration;
2656
- });
2657
- ExecCtx exec_ctx;
2658
- creds_->AddResult (kExpectedError );
2659
- // First request will trigger a fetch, which will fail.
2660
- auto state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2661
- /* expect_delay=*/ true );
2649
+ run_after_duration.reset ();
2650
+ // Start a new call now, which will fail because we're in backoff.
2651
+ LOG (INFO) << " Sending fourth RPC." ;
2652
+ state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2653
+ /* expect_delay=*/ false );
2662
2654
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2663
2655
kTestPath );
2664
- EXPECT_EQ (creds_->num_fetches (), 1 );
2665
- while (!run_after_duration.has_value ()) event_engine_->Tick ();
2666
- // Make sure backoff was set for the right period.
2667
- EXPECT_EQ (run_after_duration, std::chrono::seconds (1 ));
2668
- run_after_duration.reset ();
2669
- // Tick until the backoff expires. No new fetch should be started.
2656
+ EXPECT_EQ (creds_->num_fetches (), 2 );
2657
+ // Tick until backoff expires.
2658
+ LOG (INFO) << " Waiting for backoff." ;
2670
2659
event_engine_->TickUntilIdle ();
2671
- EXPECT_EQ (creds_->num_fetches (), 1 );
2672
- // Now start a new request, which will trigger a new fetch.
2673
- creds_->AddResult (MakeToken (" foo" ));
2674
- state = RequestMetadataState::NewInstance (
2675
- absl::OkStatus (), " authorization: foo" , /* expect_delay=*/ true );
2660
+ EXPECT_EQ (creds_->num_fetches (), 2 );
2661
+ // Starting another call should trigger a new fetch, which will again fail.
2662
+ LOG (INFO) << " Sending fifth RPC." ;
2663
+ creds_->AddResult (kExpectedError );
2664
+ state = RequestMetadataState::NewInstance (kExpectedError , " " ,
2665
+ /* expect_delay=*/ true );
2676
2666
state->RunRequestMetadataTest (creds_.get (), kTestUrlScheme , kTestAuthority ,
2677
2667
kTestPath );
2678
- EXPECT_EQ (creds_->num_fetches (), 2 );
2668
+ EXPECT_EQ (creds_->num_fetches (), 3 );
2669
+ while (!run_after_duration.has_value ()) event_engine_->Tick ();
2670
+ // The backoff time should be longer now.
2671
+ EXPECT_EQ (run_after_duration, std::chrono::milliseconds (2560 ))
2672
+ << " actual: " << run_after_duration->count ();
2679
2673
}
2680
2674
2681
2675
TEST_F (TokenFetcherCredentialsTest, ShutdownWhileBackoffTimerPending) {
0 commit comments