[testing] Update orca-* tests for better compatibility (#32630)

1. Make channel creation lazy. This allows test cases to update the
configuration before the connection is made.
2. Pass load reports tracker when creating the policy. This way other
test cases do not see any changes to ChannelArguments.

Using grpc_core::CoreConfiguration::RunWithSpecialConfiguration was
considered but did not work as it removes other builders setup prior to
starting the test cases.
pull/32640/head
Eugene Ostroukhov 2 years ago committed by GitHub
parent a70fd8e5e2
commit 65fa0f605a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      test/cpp/interop/interop_client.cc
  2. 2
      test/cpp/interop/interop_client.h

@ -29,6 +29,7 @@
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/types/optional.h"
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
@ -84,22 +85,6 @@ void UnaryCompressionChecks(const InteropClientContextInspector& inspector,
} }
} }
void InitializeCustomLbPolicyIfNeeded() {
// Load balancing policy builder is global. For now, all instances of the
// LB policy will store data in the same collection. All interop_clients in
// the same process will also share the collection
// Realistically, we do not yet need synchronization as only a single test is
// running at a time.
static bool initialized = false;
if (!initialized) {
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
RegisterBackendMetricsLbPolicy(builder);
});
initialized = true;
}
}
absl::optional<std::string> ValuesDiff(absl::string_view field, double expected, absl::optional<std::string> ValuesDiff(absl::string_view field, double expected,
double actual) { double actual) {
if (expected != actual) { if (expected != actual) {
@ -160,44 +145,39 @@ absl::optional<std::string> OrcaLoadReportsDiff(const TestOrcaReport& expected,
InteropClient::ServiceStub::ServiceStub( InteropClient::ServiceStub::ServiceStub(
ChannelCreationFunc channel_creation_func, bool new_stub_every_call) ChannelCreationFunc channel_creation_func, bool new_stub_every_call)
: channel_creation_func_(std::move(channel_creation_func)), : channel_creation_func_(std::move(channel_creation_func)),
channel_(channel_creation_func_()), new_stub_every_call_(new_stub_every_call) {}
new_stub_every_call_(new_stub_every_call) {
// If new_stub_every_call is false, then this is our chance to initialize
// stub_. (see Get())
if (!new_stub_every_call) {
stub_ = TestService::NewStub(channel_);
}
}
TestService::Stub* InteropClient::ServiceStub::Get() { TestService::Stub* InteropClient::ServiceStub::Get() {
if (new_stub_every_call_) { if (new_stub_every_call_ || stub_ == nullptr) {
if (channel_ == nullptr) {
channel_ = channel_creation_func_();
}
stub_ = TestService::NewStub(channel_); stub_ = TestService::NewStub(channel_);
} }
return stub_.get(); return stub_.get();
} }
UnimplementedService::Stub* UnimplementedService::Stub*
InteropClient::ServiceStub::GetUnimplementedServiceStub() { InteropClient::ServiceStub::GetUnimplementedServiceStub() {
if (unimplemented_service_stub_ == nullptr) { if (unimplemented_service_stub_ == nullptr) {
if (channel_ == nullptr) {
channel_ = channel_creation_func_();
}
unimplemented_service_stub_ = UnimplementedService::NewStub(channel_); unimplemented_service_stub_ = UnimplementedService::NewStub(channel_);
} }
return unimplemented_service_stub_.get(); return unimplemented_service_stub_.get();
} }
void InteropClient::ServiceStub::ResetChannel() { void InteropClient::ServiceStub::ResetChannel() {
channel_ = channel_creation_func_(); channel_.reset();
if (!new_stub_every_call_) { stub_.reset();
stub_ = TestService::NewStub(channel_);
}
} }
InteropClient::InteropClient(ChannelCreationFunc channel_creation_func, InteropClient::InteropClient(ChannelCreationFunc channel_creation_func,
bool new_stub_every_test_case, bool new_stub_every_test_case,
bool do_not_abort_on_transient_failures) bool do_not_abort_on_transient_failures)
: serviceStub_( : serviceStub_(
[&]() { [channel_creation_func = std::move(channel_creation_func), this]() {
InitializeCustomLbPolicyIfNeeded();
return channel_creation_func( return channel_creation_func(
load_report_tracker_.GetChannelArguments()); load_report_tracker_.GetChannelArguments());
}, },
@ -1014,6 +994,7 @@ bool InteropClient::DoPickFirstUnary() {
bool InteropClient::DoOrcaPerRpc() { bool InteropClient::DoOrcaPerRpc() {
load_report_tracker_.ResetCollectedLoadReports(); load_report_tracker_.ResetCollectedLoadReports();
grpc_core::CoreConfiguration::RegisterBuilder(RegisterBackendMetricsLbPolicy);
gpr_log(GPR_DEBUG, "testing orca per rpc"); gpr_log(GPR_DEBUG, "testing orca per rpc");
SimpleRequest request; SimpleRequest request;
SimpleResponse response; SimpleResponse response;
@ -1041,6 +1022,8 @@ bool InteropClient::DoOrcaPerRpc() {
bool InteropClient::DoOrcaOob() { bool InteropClient::DoOrcaOob() {
gpr_log(GPR_DEBUG, "testing orca oob"); gpr_log(GPR_DEBUG, "testing orca oob");
load_report_tracker_.ResetCollectedLoadReports();
grpc_core::CoreConfiguration::RegisterBuilder(RegisterBackendMetricsLbPolicy);
ClientContext context; ClientContext context;
std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest, std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest,
StreamingOutputCallResponse>> StreamingOutputCallResponse>>

@ -21,8 +21,6 @@
#include <memory> #include <memory>
#include "absl/types/optional.h"
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpcpp/channel.h> #include <grpcpp/channel.h>

Loading…
Cancel
Save