|
|
@ -41,6 +41,7 @@ |
|
|
|
#include "absl/types/optional.h" |
|
|
|
#include "absl/types/optional.h" |
|
|
|
#include "absl/types/span.h" |
|
|
|
#include "absl/types/span.h" |
|
|
|
#include "absl/types/variant.h" |
|
|
|
#include "absl/types/variant.h" |
|
|
|
|
|
|
|
#include "gmock/gmock.h" |
|
|
|
#include "gtest/gtest.h" |
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/event_engine/event_engine.h> |
|
|
|
#include <grpc/event_engine/event_engine.h> |
|
|
@ -160,10 +161,49 @@ class LoadBalancingPolicyTest : public ::testing::Test { |
|
|
|
|
|
|
|
|
|
|
|
const std::string& address() const { return address_; } |
|
|
|
const std::string& address() const { return address_; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AssertValidConnectivityStateTransition( |
|
|
|
|
|
|
|
grpc_connectivity_state from_state, grpc_connectivity_state to_state, |
|
|
|
|
|
|
|
SourceLocation location = SourceLocation()) { |
|
|
|
|
|
|
|
switch (from_state) { |
|
|
|
|
|
|
|
case GRPC_CHANNEL_IDLE: |
|
|
|
|
|
|
|
ASSERT_EQ(to_state, GRPC_CHANNEL_CONNECTING) |
|
|
|
|
|
|
|
<< ConnectivityStateName(from_state) << "=>" |
|
|
|
|
|
|
|
<< ConnectivityStateName(to_state) << "\n" |
|
|
|
|
|
|
|
<< location.file() << ":" << location.line(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case GRPC_CHANNEL_CONNECTING: |
|
|
|
|
|
|
|
ASSERT_THAT(to_state, |
|
|
|
|
|
|
|
::testing::AnyOf(GRPC_CHANNEL_READY, |
|
|
|
|
|
|
|
GRPC_CHANNEL_TRANSIENT_FAILURE)) |
|
|
|
|
|
|
|
<< ConnectivityStateName(from_state) << "=>" |
|
|
|
|
|
|
|
<< ConnectivityStateName(to_state) << "\n" |
|
|
|
|
|
|
|
<< location.file() << ":" << location.line(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case GRPC_CHANNEL_READY: |
|
|
|
|
|
|
|
ASSERT_EQ(to_state, GRPC_CHANNEL_IDLE) |
|
|
|
|
|
|
|
<< ConnectivityStateName(from_state) << "=>" |
|
|
|
|
|
|
|
<< ConnectivityStateName(to_state) << "\n" |
|
|
|
|
|
|
|
<< location.file() << ":" << location.line(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case GRPC_CHANNEL_TRANSIENT_FAILURE: |
|
|
|
|
|
|
|
ASSERT_EQ(to_state, GRPC_CHANNEL_IDLE) |
|
|
|
|
|
|
|
<< ConnectivityStateName(from_state) << "=>" |
|
|
|
|
|
|
|
<< ConnectivityStateName(to_state) << "\n" |
|
|
|
|
|
|
|
<< location.file() << ":" << location.line(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
FAIL() << ConnectivityStateName(from_state) << "=>" |
|
|
|
|
|
|
|
<< ConnectivityStateName(to_state) << "\n" |
|
|
|
|
|
|
|
<< location.file() << ":" << location.line(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sets the connectivity state for this subchannel. The updated state
|
|
|
|
// Sets the connectivity state for this subchannel. The updated state
|
|
|
|
// will be reported to all associated SubchannelInterface objects.
|
|
|
|
// will be reported to all associated SubchannelInterface objects.
|
|
|
|
void SetConnectivityState(grpc_connectivity_state state, |
|
|
|
void SetConnectivityState(grpc_connectivity_state state, |
|
|
|
const absl::Status& status = absl::OkStatus()) { |
|
|
|
const absl::Status& status = absl::OkStatus(), |
|
|
|
|
|
|
|
SourceLocation location = SourceLocation()) { |
|
|
|
if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { |
|
|
|
if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { |
|
|
|
EXPECT_FALSE(status.ok()) |
|
|
|
EXPECT_FALSE(status.ok()) |
|
|
|
<< "bug in test: TRANSIENT_FAILURE must have non-OK status"; |
|
|
|
<< "bug in test: TRANSIENT_FAILURE must have non-OK status"; |
|
|
@ -173,6 +213,8 @@ class LoadBalancingPolicyTest : public ::testing::Test { |
|
|
|
<< " must have OK status: " << status; |
|
|
|
<< " must have OK status: " << status; |
|
|
|
} |
|
|
|
} |
|
|
|
MutexLock lock(&mu_); |
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
|
|
|
AssertValidConnectivityStateTransition(state_tracker_.state(), state, |
|
|
|
|
|
|
|
location); |
|
|
|
state_tracker_.SetState(state, status, "set from test"); |
|
|
|
state_tracker_.SetState(state, status, "set from test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|