[logging_test] Fix timeout

pull/37874/head
Yash Tibrewal 2 months ago
parent dbb5164ac7
commit fa5d67230c
  1. 10
      test/cpp/ext/filters/logging/library.h
  2. 10
      test/cpp/ext/filters/logging/logging_test.cc

@ -83,13 +83,19 @@ class TestLoggingSink : public grpc_core::LoggingSink {
}
// Waits for \a duration till we have \a num_entries in the log.
void WaitForNumEntries(size_t num_entries, absl::Duration duration) {
bool WaitForNumEntries(size_t num_entries, absl::Duration duration) {
absl::Time deadline = absl::Now() + duration * grpc_test_slowdown_factor();
grpc_core::MutexLock lock(&mu_);
while (entries_.size() != num_entries) {
cv_.WaitWithDeadline(&mu_, deadline);
if (cv_.WaitWithDeadline(&mu_, deadline)) {
LOG(ERROR) << "\nDeadline expired while waiting on logging "
"entries\nExpected number: "
<< num_entries << "\nActual number: " << entries_.size();
return false;
}
}
return true;
}
private:
grpc_core::Mutex mu_;

@ -62,7 +62,7 @@ TEST_F(LoggingTest, SimpleRpc) {
context.AddMetadata("key", "value");
grpc::Status status = stub_->Echo(&context, request, &response);
EXPECT_TRUE(status.ok());
g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5));
ASSERT_TRUE(g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5)));
EXPECT_THAT(
g_test_logging_sink->entries(),
::testing::UnorderedElementsAre(
@ -246,7 +246,7 @@ TEST_F(LoggingTest, SimpleRpcNoMetadata) {
grpc::ClientContext context;
grpc::Status status = stub_->Echo(&context, request, &response);
EXPECT_TRUE(status.ok());
g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5));
ASSERT_TRUE(g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5)));
EXPECT_THAT(
g_test_logging_sink->entries(),
::testing::UnorderedElementsAre(
@ -447,7 +447,7 @@ TEST_F(LoggingTest, MetadataTruncated) {
context.AddMetadata("key-2", "value-2");
grpc::Status status = stub_->Echo(&context, request, &response);
EXPECT_TRUE(status.ok());
g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5));
ASSERT_TRUE(g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5)));
EXPECT_THAT(
g_test_logging_sink->entries(),
::testing::UnorderedElementsAre(
@ -630,7 +630,7 @@ TEST_F(LoggingTest, PayloadTruncated) {
grpc::ClientContext context;
grpc::Status status = stub_->Echo(&context, request, &response);
EXPECT_TRUE(status.ok());
g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5));
ASSERT_TRUE(g_test_logging_sink->WaitForNumEntries(12, absl::Seconds(5)));
EXPECT_THAT(
g_test_logging_sink->entries(),
::testing::UnorderedElementsAre(
@ -861,7 +861,7 @@ TEST_F(LoggingTest, ServerCancelsRpc) {
EXPECT_EQ(status.error_code(), 25);
EXPECT_EQ(status.error_message(), "error message");
EXPECT_EQ(status.error_details(), "binary error details");
g_test_logging_sink->WaitForNumEntries(9, absl::Seconds(5));
ASSERT_TRUE(g_test_logging_sink->WaitForNumEntries(9, absl::Seconds(5)));
EXPECT_THAT(
g_test_logging_sink->entries(),
::testing::UnorderedElementsAre(

Loading…
Cancel
Save