Repository: envoyproxy/envoy
File: test/extensions/filters/http/common/jwks_fetcher_test.cc (C++)

Code before:
struct RetryingParameters {
  RetryingParameters(const std::string& config, uint32_t n, int64_t base_ms, int64_t max_ms)
      : config_(config), expected_num_retries_(n), expected_backoff_base_interval_ms_(base_ms),
        expected_backoff_max_interval_ms_(max_ms) {}

  std::string config_;

  uint32_t expected_num_retries_;
  int64_t expected_backoff_base_interval_ms_;
  int64_t expected_backoff_max_interval_ms_;
};

class JwksFetcherRetryingTest : public testing::TestWithParam<RetryingParameters> {
public:
  void setupFetcher(const std::string& config_str) {
    TestUtility::loadFromYaml(config_str, remote_jwks_);
    mock_factory_ctx_.server_factory_context_.cluster_manager_.initializeThreadLocalClusters(
        {"pubkey_cluster"});

    Router::RetryPolicyConstSharedPtr retry_policy = nullptr;
    if (remote_jwks_.has_retry_policy()) {
      envoy::config::route::v3::RetryPolicy route_retry_policy =
          Http::Utility::convertCoreToRouteRetryPolicy(remote_jwks_.retry_policy(),
                                                       "5xx,gateway-error,connect-failure,reset");
      // Use the null validation visitor because it used by the async client in the previous
      // implementation.
      auto policy_or_error = Router::RetryPolicyImpl::create(
          route_retry_policy, ProtobufMessage::getNullValidationVisitor(),
          mock_factory_ctx_.server_factory_context_);
      THROW_IF_NOT_OK_REF(policy_or_error.status());
      retry_policy = std::move(policy_or_error.value());
    }

    fetcher_ = JwksFetcher::create(mock_factory_ctx_.server_factory_context_.cluster_manager_,
                                   retry_policy, remote_jwks_);
    EXPECT_TRUE(fetcher_ != nullptr);
  }

  RemoteJwks remote_jwks_;
  testing::NiceMock<Server::Configuration::MockFactoryContext> mock_factory_ctx_;
  std::unique_ptr<JwksFetcher> fetcher_;
  NiceMock<Tracing::MockSpan> parent_span_;
};

INSTANTIATE_TEST_SUITE_P(Retrying, JwksFetcherRetryingTest,
                         testing::Values(RetryingParameters{R"(
http_uri:
  uri: https://pubkey_server/pubkey_path
  cluster: pubkey_cluster
  timeout:
    seconds: 5

Review comment (suggestion):
```suggestion
      // Use the null validation visitor because it was used by the async client in the previous
      // implementation.
```

Code after:

  // Act
  fetcher_->fetch(parent_span_, receiver);
}
struct RetryingParameters {
  RetryingParameters(const std::string& config, uint32_t n, int64_t base_ms, int64_t max_ms)
      : config_(config), expected_num_retries_(n), expected_backoff_base_interval_ms_(base_ms),
        expected_backoff_max_interval_ms_(max_ms) {}

  std::string config_;

  uint32_t expected_num_retries_;
  int64_t expected_backoff_base_interval_ms_;
  int64_t expected_backoff_max_interval_ms_;
};

class JwksFetcherRetryingTest : public testing::TestWithParam<RetryingParameters> {
public:
  void setupFetcher(const std::string& config_str) {
    TestUtility::loadFromYaml(config_str, remote_jwks_);
    mock_factory_ctx_.server_factory_context_.cluster_manager_.initializeThreadLocalClusters(
        {"pubkey_cluster"});

    fetcher_ = JwksFetcher::create(
        mock_factory_ctx_.server_factory_context_.cluster_manager_,
        getRetryPolicy(remote_jwks_, mock_factory_ctx_.server_factory_context_), remote_jwks_);
    EXPECT_TRUE(fetcher_ != nullptr);
  }

  RemoteJwks remote_jwks_;
  testing::NiceMock<Server::Configuration::MockFactoryContext> mock_factory_ctx_;
  std::unique_ptr<JwksFetcher> fetcher_;
  NiceMock<Tracing::MockSpan> parent_span_;
};

INSTANTIATE_TEST_SUITE_P(Retrying, JwksFetcherRetryingTest,
                         testing::Values(RetryingParameters{R"(
http_uri:
  uri: https://pubkey_server/pubkey_path
  cluster: pubkey_cluster
  timeout:
    seconds: 5
retry_policy:
  retry_back_off:
    base_interval: 0.1s
    max_interval: 32s
  num_retries: 10
)",
                                                            10, 100, 32000},
                                         RetryingParameters{R"(
http_uri: