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

Code before:
  retry_policy.set_retry_on("5xx,reset");
  retry_policy.mutable_retry_back_off()->mutable_base_interval()->set_seconds(1);
  retry_policy.mutable_retry_back_off()->mutable_max_interval()->set_seconds(10);
  retry_policy.mutable_num_retries()->set_value(5);

  testing::NiceMock<Server::Configuration::MockServerFactoryContext> server_factory_context_;
  auto parsed_retry_policy = Router::RetryPolicyImpl::create(
      retry_policy, ProtobufMessage::getNullValidationVisitor(), server_factory_context_);

  client_ =
      std::make_shared<OAuth2ClientImpl>(cm_, uri, std::move(parsed_retry_policy.value()), 2000s);

  EXPECT_CALL(cm_.thread_local_cluster_.async_client_, send_(_, _, _))
      .WillOnce(Invoke(
          [&](Http::RequestMessagePtr&, Http::AsyncClient::Callbacks&,
              const Http::AsyncClient::RequestOptions& options) -> Http::AsyncClient::Request* {
            EXPECT_TRUE(options.parsed_retry_policy != nullptr);
            EXPECT_TRUE(options.buffer_body_for_retry);
            EXPECT_EQ(options.parsed_retry_policy->numRetries(), 5);
            EXPECT_TRUE(options.parsed_retry_policy->baseInterval().has_value());
            EXPECT_TRUE(options.parsed_retry_policy->maxInterval().has_value());
            EXPECT_EQ(options.parsed_retry_policy->baseInterval().value().count(), 1 * 1000);
            EXPECT_EQ(options.parsed_retry_policy->maxInterval().value().count(), 10 * 1000);
            const auto retry_on = options.parsed_retry_policy->retryOn();
            EXPECT_TRUE(retry_on | Router::RetryPolicy::RETRY_ON_5XX);
            EXPECT_TRUE(retry_on | Router::RetryPolicy::RETRY_ON_RESET);
            return nullptr;
          }));

  client_->setCallbacks(*mock_callbacks_);
  client_->asyncGetAccessToken("a", "b", "c", "d", "e");
}

} // namespace Oauth2
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy


Review comment (suggestion):
i think this should be AND(`&`) here and not OR (`|`).

Code after:
  retry_policy.set_retry_on("5xx,reset");
  retry_policy.mutable_retry_back_off()->mutable_base_interval()->set_seconds(1);
  retry_policy.mutable_retry_back_off()->mutable_max_interval()->set_seconds(10);
  retry_policy.mutable_num_retries()->set_value(5);

  testing::NiceMock<Server::Configuration::MockServerFactoryContext> server_factory_context;
  auto parsed_retry_policy = Router::RetryPolicyImpl::create(
      retry_policy, ProtobufMessage::getNullValidationVisitor(), server_factory_context);

  client_ =
      std::make_shared<OAuth2ClientImpl>(cm_, uri, std::move(parsed_retry_policy.value()), 2000s);

  EXPECT_CALL(cm_.thread_local_cluster_.async_client_, send_(_, _, _))
      .WillOnce(Invoke(
          [&](Http::RequestMessagePtr&, Http::AsyncClient::Callbacks&,
              const Http::AsyncClient::RequestOptions& options) -> Http::AsyncClient::Request* {
            EXPECT_TRUE(options.parsed_retry_policy != nullptr);
            EXPECT_TRUE(options.buffer_body_for_retry);
            EXPECT_EQ(options.parsed_retry_policy->numRetries(), 5);
            EXPECT_TRUE(options.parsed_retry_policy->baseInterval().has_value());
            EXPECT_TRUE(options.parsed_retry_policy->maxInterval().has_value());
            EXPECT_EQ(options.parsed_retry_policy->baseInterval().value().count(), 1 * 1000);
            EXPECT_EQ(options.parsed_retry_policy->maxInterval().value().count(), 10 * 1000);
            const auto retry_on = options.parsed_retry_policy->retryOn();
            EXPECT_TRUE(retry_on & Router::RetryPolicy::RETRY_ON_5XX);
            EXPECT_TRUE(retry_on & Router::RetryPolicy::RETRY_ON_RESET);
            return nullptr;
          }));

  client_->setCallbacks(*mock_callbacks_);
  client_->asyncGetAccessToken("a", "b", "c", "d", "e");
}

} // namespace Oauth2
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy