Fixes a flake with the LoadReporter end2end test. (#29383)

* Fixes a flake with the LoadReporter end2end test.

I *believe* the test is wrong, based on the .proto description of the
LoadReporter.

The protocol described in src/proto/grpc/lb/v1/load_reporter.proto has
the ReportLoad rpc returns a stream of LoadReportResponse, which itself
has a repeated field of Load messages. The comment before it states:

"It is not strictly necessary to aggregate all entries into one entry
per <tag, user_id> tuple, although it is preferred to do so."

Debugging the issue shows we are in fact properly getting all 3 expected
load report types, just in two separate messages instead of a single
one.

This new test codepath will coalesce the load report responses, and also
addresses the fact the original test wasn't verifying that we were
getting the 3 expected types.

* Automated change: Fix sanity tests

* Renaming variables.

* ASSERT_ -> EXPECT_

* Automated change: Fix sanity tests
pull/29405/head
Nicolas Noble 3 years ago committed by GitHub
parent 55b0405c86
commit e9cf2894da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 71
      test/cpp/end2end/server_load_reporting_end2end_test.cc

@ -142,41 +142,52 @@ TEST_F(ServerLoadReportingEnd2endTest, BasicReport) {
const std::string& lb_id = response.initial_response().load_balancer_id();
gpr_log(GPR_INFO, "Initial response received (lb_id: %s).", lb_id.c_str());
ClientMakeEchoCalls(lb_id, "LB_TAG", kOkMessage, 1);
while (true) {
unsigned load_count = 0;
bool got_in_progress = false;
bool got_orphaned = false;
bool got_calls = false;
while (load_count < 3) {
stream->Read(&response);
if (!response.load().empty()) {
ASSERT_EQ(response.load().size(), 3) << response.DebugString();
for (const auto& load : response.load()) {
if (load.in_progress_report_case()) {
// The special load record that reports the number of in-progress
// calls.
ASSERT_EQ(load.num_calls_in_progress(), 1);
} else if (load.orphaned_load_case()) {
// The call from the balancer doesn't have any valid LB token.
ASSERT_EQ(load.orphaned_load_case(), load.kLoadKeyUnknown);
ASSERT_EQ(load.num_calls_started(), 1);
ASSERT_EQ(load.num_calls_finished_without_error(), 0);
ASSERT_EQ(load.num_calls_finished_with_error(), 0);
} else {
// This corresponds to the calls from the client.
ASSERT_EQ(load.num_calls_started(), 1);
ASSERT_EQ(load.num_calls_finished_without_error(), 1);
ASSERT_EQ(load.num_calls_finished_with_error(), 0);
ASSERT_GE(load.total_bytes_received(), sizeof(kOkMessage));
ASSERT_GE(load.total_bytes_sent(), sizeof(kOkMessage));
ASSERT_EQ(load.metric_data().size(), 1);
ASSERT_EQ(load.metric_data().Get(0).metric_name(), kMetricName);
ASSERT_EQ(load.metric_data().Get(0).num_calls_finished_with_metric(),
1);
ASSERT_EQ(load.metric_data().Get(0).total_metric_value(),
kMetricValue);
}
for (const auto& load : response.load()) {
load_count++;
if (load.in_progress_report_case()) {
// The special load record that reports the number of in-progress
// calls.
EXPECT_EQ(load.num_calls_in_progress(), 1);
EXPECT_FALSE(got_in_progress);
got_in_progress = true;
} else if (load.orphaned_load_case()) {
// The call from the balancer doesn't have any valid LB token.
EXPECT_EQ(load.orphaned_load_case(), load.kLoadKeyUnknown);
EXPECT_EQ(load.num_calls_started(), 1);
EXPECT_EQ(load.num_calls_finished_without_error(), 0);
EXPECT_EQ(load.num_calls_finished_with_error(), 0);
EXPECT_FALSE(got_orphaned);
got_orphaned = true;
} else {
// This corresponds to the calls from the client.
EXPECT_EQ(load.num_calls_started(), 1);
EXPECT_EQ(load.num_calls_finished_without_error(), 1);
EXPECT_EQ(load.num_calls_finished_with_error(), 0);
EXPECT_GE(load.total_bytes_received(), sizeof(kOkMessage));
EXPECT_GE(load.total_bytes_sent(), sizeof(kOkMessage));
EXPECT_EQ(load.metric_data().size(), 1);
EXPECT_EQ(load.metric_data().Get(0).metric_name(), kMetricName);
EXPECT_EQ(load.metric_data().Get(0).num_calls_finished_with_metric(),
1);
EXPECT_EQ(load.metric_data().Get(0).total_metric_value(), kMetricValue);
EXPECT_FALSE(got_calls);
got_calls = true;
}
break;
}
}
EXPECT_EQ(load_count, 3);
EXPECT_TRUE(got_in_progress);
EXPECT_TRUE(got_orphaned);
EXPECT_TRUE(got_calls);
stream->WritesDone();
ASSERT_EQ(stream->Finish().error_code(), StatusCode::CANCELLED);
EXPECT_EQ(stream->Finish().error_code(), StatusCode::CANCELLED);
}
// TODO(juanlishen): Add more tests.

Loading…
Cancel
Save