[EventEngine] Add Listener Bind-after-Start test (#32502)

This also alters changes the PosixEventEngine to return a failure status
instead of crashing.

cc @yijiem
pull/32493/head
AJ Heller 2 years ago committed by GitHub
parent 193a3f88ae
commit e164ef7460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/lib/event_engine/posix_engine/posix_engine_listener.cc
  2. 4
      test/core/event_engine/test_suite/posix/oracle_event_engine_posix.cc
  3. 20
      test/core/event_engine/test_suite/tests/server_test.cc

@ -64,11 +64,14 @@ PosixEngineListenerImpl::PosixEngineListenerImpl(
absl::StatusOr<int> PosixEngineListenerImpl::Bind(
const EventEngine::ResolvedAddress& addr,
PosixListenerWithFdSupport::OnPosixBindNewFdCallback on_bind_new_fd) {
absl::MutexLock lock(&this->mu_);
if (this->started_) {
return absl::FailedPreconditionError(
"Listener is already started, ports can no longer be bound");
}
EventEngine::ResolvedAddress res_addr = addr;
EventEngine::ResolvedAddress addr6_v4mapped;
int requested_port = ResolvedAddressGetPort(res_addr);
absl::MutexLock lock(&this->mu_);
GPR_ASSERT(!this->started_);
GPR_ASSERT(addr.size() <= EventEngine::ResolvedAddress::MAX_SIZE_BYTES);
UnlinkIfUnixDomainSocket(addr);

@ -388,6 +388,10 @@ void PosixOracleListener::HandleIncomingConnections() {
absl::StatusOr<int> PosixOracleListener::Bind(
const EventEngine::ResolvedAddress& addr) {
grpc_core::MutexLock lock(&mu_);
if (is_started_) {
return absl::FailedPreconditionError(
"Listener is already started, ports can no longer be bound");
}
int new_socket;
int opt = -1;
grpc_resolved_address address = CreateGRPCResolvedAddress(addr);

@ -74,6 +74,26 @@ constexpr int kNumExchangedMessages = 100;
} // namespace
TEST_F(EventEngineServerTest, CannotBindAfterStarted) {
std::shared_ptr<EventEngine> engine(this->NewEventEngine());
ChannelArgsEndpointConfig config;
auto listener = engine->CreateListener(
[](std::unique_ptr<Endpoint>, grpc_core::MemoryAllocator) {},
[](absl::Status) {}, config,
std::make_unique<grpc_core::MemoryQuota>("foo"));
// Bind an initial port to ensure normal listener startup
auto resolved_addr = URIToResolvedAddress(absl::StrCat(
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())));
ASSERT_TRUE(resolved_addr.ok());
ASSERT_TRUE((*listener)->Bind(*resolved_addr).ok());
ASSERT_TRUE((*listener)->Start().ok());
// A subsequent bind, which should fail
auto resolved_addr2 = URIToResolvedAddress(absl::StrCat(
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())));
ASSERT_TRUE(resolved_addr2.ok());
ASSERT_FALSE((*listener)->Bind(*resolved_addr2).ok());
}
// Create a connection using the oracle EventEngine to a listener created
// by the Test EventEngine and exchange bi-di data over the connection.
// For each data transfer, verify that data written at one end of the stream

Loading…
Cancel
Save