|
|
@ -2569,8 +2569,9 @@ TEST_F(TokenFetcherCredentialsTest, FetchFails) { |
|
|
|
run_after_duration = duration; |
|
|
|
run_after_duration = duration; |
|
|
|
}); |
|
|
|
}); |
|
|
|
ExecCtx exec_ctx; |
|
|
|
ExecCtx exec_ctx; |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
|
|
|
|
// First request will trigger a fetch, which will fail.
|
|
|
|
// First request will trigger a fetch, which will fail.
|
|
|
|
|
|
|
|
LOG(INFO) << "Sending first RPC."; |
|
|
|
|
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
auto state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
auto state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
/*expect_delay=*/true); |
|
|
|
/*expect_delay=*/true); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
@ -2578,22 +2579,25 @@ TEST_F(TokenFetcherCredentialsTest, FetchFails) { |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
// Make sure backoff was set for the right period.
|
|
|
|
// Make sure backoff was set for the right period.
|
|
|
|
// This is 1 second (initial backoff) minus 1ms for the tick needed above.
|
|
|
|
|
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::seconds(1)); |
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::seconds(1)); |
|
|
|
run_after_duration.reset(); |
|
|
|
run_after_duration.reset(); |
|
|
|
// Start a new call now, which will be queued and then eventually
|
|
|
|
// Start a new call now, which will fail because we're in backoff.
|
|
|
|
// resumed when the next fetch happens.
|
|
|
|
LOG(INFO) << "Sending second RPC."; |
|
|
|
state = RequestMetadataState::NewInstance( |
|
|
|
state = RequestMetadataState::NewInstance( |
|
|
|
absl::OkStatus(), "authorization: foo", /*expect_delay=*/true); |
|
|
|
kExpectedError, "authorization: foo", /*expect_delay=*/false); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
// Tick until the next fetch starts.
|
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
creds_->AddResult(MakeToken("foo")); |
|
|
|
// Tick until backoff expires.
|
|
|
|
|
|
|
|
LOG(INFO) << "Waiting for backoff."; |
|
|
|
event_engine_->TickUntilIdle(); |
|
|
|
event_engine_->TickUntilIdle(); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
// A call started now should use the new cached data.
|
|
|
|
// Starting another call should trigger a new fetch, which will
|
|
|
|
|
|
|
|
// succeed this time.
|
|
|
|
|
|
|
|
LOG(INFO) << "Sending third RPC."; |
|
|
|
|
|
|
|
creds_->AddResult(MakeToken("foo")); |
|
|
|
state = RequestMetadataState::NewInstance( |
|
|
|
state = RequestMetadataState::NewInstance( |
|
|
|
absl::OkStatus(), "authorization: foo", /*expect_delay=*/false); |
|
|
|
absl::OkStatus(), "authorization: foo", /*expect_delay=*/true); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
@ -2607,8 +2611,9 @@ TEST_F(TokenFetcherCredentialsTest, Backoff) { |
|
|
|
run_after_duration = duration; |
|
|
|
run_after_duration = duration; |
|
|
|
}); |
|
|
|
}); |
|
|
|
ExecCtx exec_ctx; |
|
|
|
ExecCtx exec_ctx; |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
|
|
|
|
// First request will trigger a fetch, which will fail.
|
|
|
|
// First request will trigger a fetch, which will fail.
|
|
|
|
|
|
|
|
LOG(INFO) << "Sending first RPC."; |
|
|
|
|
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
auto state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
auto state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
/*expect_delay=*/true); |
|
|
|
/*expect_delay=*/true); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
@ -2618,64 +2623,53 @@ TEST_F(TokenFetcherCredentialsTest, Backoff) { |
|
|
|
// Make sure backoff was set for the right period.
|
|
|
|
// Make sure backoff was set for the right period.
|
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::seconds(1)); |
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::seconds(1)); |
|
|
|
run_after_duration.reset(); |
|
|
|
run_after_duration.reset(); |
|
|
|
// Start a new call now, which will be queued and then eventually
|
|
|
|
// Start a new call now, which will fail because we're in backoff.
|
|
|
|
// resumed when the next fetch happens.
|
|
|
|
LOG(INFO) << "Sending second RPC."; |
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
/*expect_delay=*/true); |
|
|
|
/*expect_delay=*/false); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
// Tick until the next fetch fails and the backoff timer starts again.
|
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
|
|
|
|
// Tick until backoff expires.
|
|
|
|
|
|
|
|
LOG(INFO) << "Waiting for backoff."; |
|
|
|
|
|
|
|
event_engine_->TickUntilIdle(); |
|
|
|
|
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
|
|
|
|
// Starting another call should trigger a new fetch, which will again fail.
|
|
|
|
|
|
|
|
LOG(INFO) << "Sending third RPC."; |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
|
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
|
|
|
|
// The backoff time should be longer now. We account for jitter here.
|
|
|
|
|
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::milliseconds(1600)) |
|
|
|
|
|
|
|
<< "actual: " << run_after_duration->count(); |
|
|
|
|
|
|
|
run_after_duration.reset(); |
|
|
|
|
|
|
|
// Start another new call to trigger another new fetch once the
|
|
|
|
|
|
|
|
// backoff expires.
|
|
|
|
|
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
/*expect_delay=*/true); |
|
|
|
/*expect_delay=*/true); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
// Tick until the next fetch starts.
|
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
|
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 3); |
|
|
|
// The backoff time should be longer now.
|
|
|
|
// Check backoff time again.
|
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::milliseconds(1600)) |
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::milliseconds(2560)) |
|
|
|
|
|
|
|
<< "actual: " << run_after_duration->count(); |
|
|
|
<< "actual: " << run_after_duration->count(); |
|
|
|
} |
|
|
|
run_after_duration.reset(); |
|
|
|
|
|
|
|
// Start a new call now, which will fail because we're in backoff.
|
|
|
|
TEST_F(TokenFetcherCredentialsTest, FetchNotStartedAfterBackoffWithoutRpc) { |
|
|
|
LOG(INFO) << "Sending fourth RPC."; |
|
|
|
const absl::Status kExpectedError = absl::UnavailableError("bummer, dude"); |
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
absl::optional<FuzzingEventEngine::Duration> run_after_duration; |
|
|
|
/*expect_delay=*/false); |
|
|
|
event_engine_->SetRunAfterDurationCallback( |
|
|
|
|
|
|
|
[&](FuzzingEventEngine::Duration duration) { |
|
|
|
|
|
|
|
run_after_duration = duration; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
ExecCtx exec_ctx; |
|
|
|
|
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
|
|
|
|
// First request will trigger a fetch, which will fail.
|
|
|
|
|
|
|
|
auto state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
|
|
|
|
/*expect_delay=*/true); |
|
|
|
|
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
// Tick until backoff expires.
|
|
|
|
// Make sure backoff was set for the right period.
|
|
|
|
LOG(INFO) << "Waiting for backoff."; |
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::seconds(1)); |
|
|
|
|
|
|
|
run_after_duration.reset(); |
|
|
|
|
|
|
|
// Tick until the backoff expires. No new fetch should be started.
|
|
|
|
|
|
|
|
event_engine_->TickUntilIdle(); |
|
|
|
event_engine_->TickUntilIdle(); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 1); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
// Now start a new request, which will trigger a new fetch.
|
|
|
|
// Starting another call should trigger a new fetch, which will again fail.
|
|
|
|
creds_->AddResult(MakeToken("foo")); |
|
|
|
LOG(INFO) << "Sending fifth RPC."; |
|
|
|
state = RequestMetadataState::NewInstance( |
|
|
|
creds_->AddResult(kExpectedError); |
|
|
|
absl::OkStatus(), "authorization: foo", /*expect_delay=*/true); |
|
|
|
state = RequestMetadataState::NewInstance(kExpectedError, "", |
|
|
|
|
|
|
|
/*expect_delay=*/true); |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
state->RunRequestMetadataTest(creds_.get(), kTestUrlScheme, kTestAuthority, |
|
|
|
kTestPath); |
|
|
|
kTestPath); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 2); |
|
|
|
EXPECT_EQ(creds_->num_fetches(), 3); |
|
|
|
|
|
|
|
while (!run_after_duration.has_value()) event_engine_->Tick(); |
|
|
|
|
|
|
|
// The backoff time should be longer now.
|
|
|
|
|
|
|
|
EXPECT_EQ(run_after_duration, std::chrono::milliseconds(2560)) |
|
|
|
|
|
|
|
<< "actual: " << run_after_duration->count(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(TokenFetcherCredentialsTest, ShutdownWhileBackoffTimerPending) { |
|
|
|
TEST_F(TokenFetcherCredentialsTest, ShutdownWhileBackoffTimerPending) { |
|
|
|