Skip to content

Commit

Permalink
admission_control_filter: consume TestUtility::waitForCounterEq retur…
Browse files Browse the repository at this point in the history
…n value (envoyproxy#34834)

add expect_true to waitfor

Signed-off-by: Boteng Yao <[email protected]>
  • Loading branch information
botengyao authored Jun 21, 2024
1 parent 6652b2e commit 90c6cfb
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST_F(AdmissionControlTest, HttpFailureBehavior) {
setupFilter(config);

// We expect rejection counter to increment upon failure.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 0)));
EXPECT_CALL(*evaluator_, isHttpSuccess(500)).WillRepeatedly(Return(false));
Expand All @@ -221,7 +221,7 @@ TEST_F(AdmissionControlTest, HttpFailureBehavior) {
filter_->decodeHeaders(request_headers, true));
sampleHttpRequest("500");

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_));
}

// Validate simple HTTP success case.
Expand All @@ -230,7 +230,7 @@ TEST_F(AdmissionControlTest, HttpSuccessBehavior) {
setupFilter(config);

// We expect rejection counter to NOT increment upon success.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 100)));
EXPECT_CALL(*evaluator_, isHttpSuccess(200)).WillRepeatedly(Return(true));
Expand All @@ -240,15 +240,15 @@ TEST_F(AdmissionControlTest, HttpSuccessBehavior) {
EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(request_headers, true));
sampleHttpRequest("200");

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));
}

// Validate simple gRPC failure case.
TEST_F(AdmissionControlTest, GrpcFailureBehavior) {
auto config = makeConfig(default_yaml_);
setupFilter(config);

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 0)));
EXPECT_CALL(*evaluator_, isGrpcSuccess(7)).WillRepeatedly(Return(false));
Expand All @@ -260,15 +260,15 @@ TEST_F(AdmissionControlTest, GrpcFailureBehavior) {
sampleGrpcRequest(Grpc::Status::WellKnownGrpcStatus::PermissionDenied);

// We expect rejection counter to increment upon failure.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_));
}

// Validate simple gRPC success case with status in the trailer.
TEST_F(AdmissionControlTest, GrpcSuccessBehaviorTrailer) {
auto config = makeConfig(default_yaml_);
setupFilter(config);

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 100)));
EXPECT_CALL(*evaluator_, isGrpcSuccess(0)).WillRepeatedly(Return(true));
Expand All @@ -279,15 +279,15 @@ TEST_F(AdmissionControlTest, GrpcSuccessBehaviorTrailer) {
sampleGrpcRequestTrailer(Grpc::Status::WellKnownGrpcStatus::Ok);

// We expect rejection counter to NOT increment upon success.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));
}

// Validate simple gRPC failure case with status in the trailer.
TEST_F(AdmissionControlTest, GrpcFailureBehaviorTrailer) {
auto config = makeConfig(default_yaml_);
setupFilter(config);

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 0)));
EXPECT_CALL(*evaluator_, isGrpcSuccess(7)).WillRepeatedly(Return(false));
Expand All @@ -299,15 +299,15 @@ TEST_F(AdmissionControlTest, GrpcFailureBehaviorTrailer) {
sampleGrpcRequestTrailer(Grpc::Status::WellKnownGrpcStatus::PermissionDenied);

// We expect rejection counter to increment upon failure.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_));
}

// Validate simple gRPC success case.
TEST_F(AdmissionControlTest, GrpcSuccessBehavior) {
auto config = makeConfig(default_yaml_);
setupFilter(config);

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 100)));
EXPECT_CALL(*evaluator_, isGrpcSuccess(0)).WillRepeatedly(Return(true));
Expand All @@ -318,7 +318,7 @@ TEST_F(AdmissionControlTest, GrpcSuccessBehavior) {
sampleGrpcRequest(Grpc::Status::WellKnownGrpcStatus::Ok);

// We expect rejection counter to NOT increment upon success.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));
}

// Validate rejection probabilities.
Expand Down Expand Up @@ -422,7 +422,7 @@ sampling_window: 10s
EXPECT_CALL(controller_, averageRps()).WillRepeatedly(Return(100));

// We expect rejection counter to increment upon failure.
TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 0, time_system_));

EXPECT_CALL(controller_, requestCounts()).WillRepeatedly(Return(RequestData(100, 0)));
EXPECT_CALL(*evaluator_, isHttpSuccess(500)).WillRepeatedly(Return(false));
Expand All @@ -432,7 +432,7 @@ sampling_window: 10s
filter_->decodeHeaders(request_headers, true));
sampleHttpRequest("500");

TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_);
EXPECT_TRUE(TestUtility::waitForCounterEq(store_, "test_prefix.rq_rejected", 1, time_system_));
}

// Validate max rejection probability.
Expand Down

0 comments on commit 90c6cfb

Please sign in to comment.