|
18 | 18 |
|
19 | 19 | #include "absl/strings/str_cat.h" |
20 | 20 | #include "absl/strings/string_view.h" |
| 21 | +#include "absl/time/clock.h" |
| 22 | +#include "absl/time/time.h" |
21 | 23 | #include "gmock/gmock.h" |
22 | 24 | #include "gtest/gtest.h" |
23 | 25 | #include "include/grpc++/grpc++.h" |
@@ -52,13 +54,14 @@ class StatsPluginEnd2EndTest : public ::testing::Test { |
52 | 54 | // interface. |
53 | 55 | ::grpc::ServerBuilder builder; |
54 | 56 | int port; |
55 | | - builder.AddListeningPort("[::]:0", ::grpc::InsecureServerCredentials(), |
| 57 | + // Use IPv4 here because it's less flaky than IPv6 ("[::]:0") on Travis. |
| 58 | + builder.AddListeningPort("0.0.0.0:0", ::grpc::InsecureServerCredentials(), |
56 | 59 | &port); |
57 | 60 | builder.RegisterService(&service_); |
58 | 61 | server_ = builder.BuildAndStart(); |
59 | 62 | ASSERT_NE(nullptr, server_); |
60 | 63 | ASSERT_NE(0, port); |
61 | | - server_address_ = absl::StrCat("[::]:", port); |
| 64 | + server_address_ = absl::StrCat("0.0.0.0:", port); |
62 | 65 | server_thread_ = std::thread(&StatsPluginEnd2EndTest::RunServerLoop, this); |
63 | 66 |
|
64 | 67 | stub_ = EchoService::NewStub(::grpc::CreateChannel( |
@@ -123,6 +126,7 @@ TEST_F(StatsPluginEnd2EndTest, ErrorCount) { |
123 | 126 | ::grpc::ClientContext context; |
124 | 127 | ::grpc::Status status = stub_->Echo(&context, request, &response); |
125 | 128 | } |
| 129 | + absl::SleepFor(absl::Milliseconds(500)); |
126 | 130 |
|
127 | 131 | EXPECT_THAT(client_method_view.GetData().double_data(), |
128 | 132 | ::testing::UnorderedElementsAre( |
@@ -172,6 +176,7 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseBytes) { |
172 | 176 | ASSERT_TRUE(status.ok()); |
173 | 177 | EXPECT_EQ("foo", response.message()); |
174 | 178 | } |
| 179 | + absl::SleepFor(absl::Milliseconds(500)); |
175 | 180 |
|
176 | 181 | EXPECT_THAT( |
177 | 182 | client_request_bytes_view.GetData().distribution_data(), |
@@ -224,6 +229,8 @@ TEST_F(StatsPluginEnd2EndTest, Latency) { |
224 | 229 | // entire time spent making the RPC. |
225 | 230 | const double max_time = absl::ToDoubleMilliseconds(absl::Now() - start_time); |
226 | 231 |
|
| 232 | + absl::SleepFor(absl::Milliseconds(500)); |
| 233 | + |
227 | 234 | EXPECT_THAT( |
228 | 235 | client_latency_view.GetData().distribution_data(), |
229 | 236 | ::testing::UnorderedElementsAre(::testing::Pair( |
@@ -282,6 +289,7 @@ TEST_F(StatsPluginEnd2EndTest, StartFinishCount) { |
282 | 289 | ASSERT_TRUE(status.ok()); |
283 | 290 | EXPECT_EQ("foo", response.message()); |
284 | 291 | } |
| 292 | + absl::SleepFor(absl::Milliseconds(500)); |
285 | 293 |
|
286 | 294 | EXPECT_THAT(client_started_count_view.GetData().double_data(), |
287 | 295 | ::testing::UnorderedElementsAre(::testing::Pair( |
@@ -316,6 +324,7 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseCount) { |
316 | 324 | ASSERT_TRUE(status.ok()); |
317 | 325 | EXPECT_EQ("foo", response.message()); |
318 | 326 | } |
| 327 | + absl::SleepFor(absl::Milliseconds(500)); |
319 | 328 |
|
320 | 329 | EXPECT_THAT(client_request_count_view.GetData().distribution_data(), |
321 | 330 | ::testing::UnorderedElementsAre(::testing::Pair( |
|
0 commit comments