|
|
@ -20,17 +20,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
|
|
|
#include "gtest/gtest.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <grpc/event_engine/event_engine.h> |
|
|
|
#include <grpc/event_engine/event_engine.h> |
|
|
|
#include <grpc/event_engine/memory_allocator.h> |
|
|
|
#include <grpc/event_engine/memory_allocator.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/lib/address_utils/parse_address.h" |
|
|
|
|
|
|
|
#include "src/core/lib/event_engine/channel_args_endpoint_config.h" |
|
|
|
#include "src/core/lib/event_engine/channel_args_endpoint_config.h" |
|
|
|
#include "src/core/lib/event_engine/promise.h" |
|
|
|
#include "src/core/lib/gprpp/notification.h" |
|
|
|
#include "src/core/lib/gprpp/sync.h" |
|
|
|
#include "src/core/lib/gprpp/sync.h" |
|
|
|
#include "src/core/lib/iomgr/exec_ctx.h" |
|
|
|
#include "src/core/lib/iomgr/exec_ctx.h" |
|
|
|
#include "src/core/lib/uri/uri_parser.h" |
|
|
|
|
|
|
|
#include "test/core/event_engine/test_suite/event_engine_test.h" |
|
|
|
#include "test/core/event_engine/test_suite/event_engine_test.h" |
|
|
|
#include "test/core/event_engine/test_suite/event_engine_test_utils.h" |
|
|
|
#include "test/core/event_engine/test_suite/event_engine_test_utils.h" |
|
|
|
#include "test/core/util/port.h" |
|
|
|
#include "test/core/util/port.h" |
|
|
@ -43,7 +42,6 @@ namespace { |
|
|
|
|
|
|
|
|
|
|
|
using ::grpc_event_engine::experimental::ChannelArgsEndpointConfig; |
|
|
|
using ::grpc_event_engine::experimental::ChannelArgsEndpointConfig; |
|
|
|
using ::grpc_event_engine::experimental::EventEngine; |
|
|
|
using ::grpc_event_engine::experimental::EventEngine; |
|
|
|
using ::grpc_event_engine::experimental::Promise; |
|
|
|
|
|
|
|
using ::grpc_event_engine::experimental::URIToResolvedAddress; |
|
|
|
using ::grpc_event_engine::experimental::URIToResolvedAddress; |
|
|
|
using Endpoint = ::grpc_event_engine::experimental::EventEngine::Endpoint; |
|
|
|
using Endpoint = ::grpc_event_engine::experimental::EventEngine::Endpoint; |
|
|
|
using Listener = ::grpc_event_engine::experimental::EventEngine::Listener; |
|
|
|
using Listener = ::grpc_event_engine::experimental::EventEngine::Listener; |
|
|
@ -83,7 +81,7 @@ std::string GetNextSendMessage() { |
|
|
|
TEST_F(EventEngineClientTest, ConnectToNonExistentListenerTest) { |
|
|
|
TEST_F(EventEngineClientTest, ConnectToNonExistentListenerTest) { |
|
|
|
grpc_core::ExecCtx ctx; |
|
|
|
grpc_core::ExecCtx ctx; |
|
|
|
auto test_ee = this->NewEventEngine(); |
|
|
|
auto test_ee = this->NewEventEngine(); |
|
|
|
Promise<std::unique_ptr<EventEngine::Endpoint>> client_endpoint_promise; |
|
|
|
grpc_core::Notification signal; |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
std::string target_addr = absl::StrCat( |
|
|
|
std::string target_addr = absl::StrCat( |
|
|
|
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())); |
|
|
|
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())); |
|
|
@ -91,17 +89,14 @@ TEST_F(EventEngineClientTest, ConnectToNonExistentListenerTest) { |
|
|
|
// listener.
|
|
|
|
// listener.
|
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
test_ee->Connect( |
|
|
|
test_ee->Connect( |
|
|
|
[&client_endpoint_promise]( |
|
|
|
[&signal](absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
|
|
|
|
// Connect should fail.
|
|
|
|
// Connect should fail.
|
|
|
|
EXPECT_FALSE(status.ok()); |
|
|
|
EXPECT_FALSE(status.ok()); |
|
|
|
client_endpoint_promise.Set(nullptr); |
|
|
|
signal.Notify(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
URIToResolvedAddress(target_addr), config, |
|
|
|
URIToResolvedAddress(target_addr), config, |
|
|
|
memory_quota->CreateMemoryAllocator("conn-1"), 24h); |
|
|
|
memory_quota->CreateMemoryAllocator("conn-1"), 24h); |
|
|
|
|
|
|
|
signal.WaitForNotification(); |
|
|
|
auto client_endpoint = std::move(client_endpoint_promise.Get()); |
|
|
|
|
|
|
|
EXPECT_EQ(client_endpoint, nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create a connection using the test EventEngine to a listener created
|
|
|
|
// Create a connection using the test EventEngine to a listener created
|
|
|
@ -115,14 +110,17 @@ TEST_F(EventEngineClientTest, ConnectExchangeBidiDataTransferTest) { |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
std::string target_addr = absl::StrCat( |
|
|
|
std::string target_addr = absl::StrCat( |
|
|
|
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())); |
|
|
|
"ipv6:[::1]:", std::to_string(grpc_pick_unused_port_or_die())); |
|
|
|
Promise<std::unique_ptr<EventEngine::Endpoint>> client_endpoint_promise; |
|
|
|
std::unique_ptr<EventEngine::Endpoint> client_endpoint; |
|
|
|
Promise<std::unique_ptr<EventEngine::Endpoint>> server_endpoint_promise; |
|
|
|
std::unique_ptr<EventEngine::Endpoint> server_endpoint; |
|
|
|
|
|
|
|
grpc_core::Notification client_signal; |
|
|
|
|
|
|
|
grpc_core::Notification server_signal; |
|
|
|
|
|
|
|
|
|
|
|
Listener::AcceptCallback accept_cb = |
|
|
|
Listener::AcceptCallback accept_cb = |
|
|
|
[&server_endpoint_promise]( |
|
|
|
[&server_endpoint, &server_signal]( |
|
|
|
std::unique_ptr<Endpoint> ep, |
|
|
|
std::unique_ptr<Endpoint> ep, |
|
|
|
grpc_core::MemoryAllocator /*memory_allocator*/) { |
|
|
|
grpc_core::MemoryAllocator /*memory_allocator*/) { |
|
|
|
server_endpoint_promise.Set(std::move(ep)); |
|
|
|
server_endpoint = std::move(ep); |
|
|
|
|
|
|
|
server_signal.Notify(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
ChannelArgsEndpointConfig config; |
|
|
@ -137,21 +135,22 @@ TEST_F(EventEngineClientTest, ConnectExchangeBidiDataTransferTest) { |
|
|
|
EXPECT_TRUE(listener->Start().ok()); |
|
|
|
EXPECT_TRUE(listener->Start().ok()); |
|
|
|
|
|
|
|
|
|
|
|
test_ee->Connect( |
|
|
|
test_ee->Connect( |
|
|
|
[&client_endpoint_promise]( |
|
|
|
[&client_endpoint, |
|
|
|
absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
&client_signal](absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
if (!status.ok()) { |
|
|
|
if (!status.ok()) { |
|
|
|
gpr_log(GPR_ERROR, "Connect failed: %s", |
|
|
|
gpr_log(GPR_ERROR, "Connect failed: %s", |
|
|
|
status.status().ToString().c_str()); |
|
|
|
status.status().ToString().c_str()); |
|
|
|
client_endpoint_promise.Set(nullptr); |
|
|
|
client_endpoint = nullptr; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
client_endpoint_promise.Set(std::move(*status)); |
|
|
|
client_endpoint = std::move(*status); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
client_signal.Notify(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
URIToResolvedAddress(target_addr), config, |
|
|
|
URIToResolvedAddress(target_addr), config, |
|
|
|
memory_quota->CreateMemoryAllocator("conn-1"), 24h); |
|
|
|
memory_quota->CreateMemoryAllocator("conn-1"), 24h); |
|
|
|
|
|
|
|
|
|
|
|
auto client_endpoint = std::move(client_endpoint_promise.Get()); |
|
|
|
client_signal.WaitForNotification(); |
|
|
|
auto server_endpoint = std::move(server_endpoint_promise.Get()); |
|
|
|
server_signal.WaitForNotification(); |
|
|
|
EXPECT_TRUE(client_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(client_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(server_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(server_endpoint != nullptr); |
|
|
|
|
|
|
|
|
|
|
@ -178,17 +177,19 @@ TEST_F(EventEngineClientTest, MultipleIPv6ConnectionsToOneOracleListenerTest) { |
|
|
|
auto oracle_ee = this->NewOracleEventEngine(); |
|
|
|
auto oracle_ee = this->NewOracleEventEngine(); |
|
|
|
auto test_ee = this->NewEventEngine(); |
|
|
|
auto test_ee = this->NewEventEngine(); |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
auto memory_quota = absl::make_unique<grpc_core::MemoryQuota>("bar"); |
|
|
|
Promise<std::unique_ptr<EventEngine::Endpoint>> client_endpoint_promise; |
|
|
|
std::unique_ptr<EventEngine::Endpoint> server_endpoint; |
|
|
|
Promise<std::unique_ptr<EventEngine::Endpoint>> server_endpoint_promise; |
|
|
|
// Notifications can only be fired once, so they are newed every loop
|
|
|
|
|
|
|
|
grpc_core::Notification* server_signal = new grpc_core::Notification(); |
|
|
|
std::vector<std::string> target_addrs; |
|
|
|
std::vector<std::string> target_addrs; |
|
|
|
std::vector<std::tuple<std::unique_ptr<Endpoint>, std::unique_ptr<Endpoint>>> |
|
|
|
std::vector<std::tuple<std::unique_ptr<Endpoint>, std::unique_ptr<Endpoint>>> |
|
|
|
connections; |
|
|
|
connections; |
|
|
|
|
|
|
|
|
|
|
|
Listener::AcceptCallback accept_cb = |
|
|
|
Listener::AcceptCallback accept_cb = |
|
|
|
[&server_endpoint_promise]( |
|
|
|
[&server_endpoint, &server_signal]( |
|
|
|
std::unique_ptr<Endpoint> ep, |
|
|
|
std::unique_ptr<Endpoint> ep, |
|
|
|
grpc_core::MemoryAllocator /*memory_allocator*/) { |
|
|
|
grpc_core::MemoryAllocator /*memory_allocator*/) { |
|
|
|
server_endpoint_promise.Set(std::move(ep)); |
|
|
|
server_endpoint = std::move(ep); |
|
|
|
|
|
|
|
server_signal->Notify(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
auto status = oracle_ee->CreateListener( |
|
|
|
auto status = oracle_ee->CreateListener( |
|
|
@ -208,35 +209,39 @@ TEST_F(EventEngineClientTest, MultipleIPv6ConnectionsToOneOracleListenerTest) { |
|
|
|
EXPECT_TRUE(listener->Start().ok()); |
|
|
|
EXPECT_TRUE(listener->Start().ok()); |
|
|
|
absl::SleepFor(absl::Milliseconds(500)); |
|
|
|
absl::SleepFor(absl::Milliseconds(500)); |
|
|
|
for (int i = 0; i < kNumConnections; i++) { |
|
|
|
for (int i = 0; i < kNumConnections; i++) { |
|
|
|
|
|
|
|
std::unique_ptr<EventEngine::Endpoint> client_endpoint; |
|
|
|
|
|
|
|
grpc_core::Notification client_signal; |
|
|
|
// Create a test EventEngine client endpoint and connect to a one of the
|
|
|
|
// Create a test EventEngine client endpoint and connect to a one of the
|
|
|
|
// addresses bound to the oracle listener. Verify that the connection
|
|
|
|
// addresses bound to the oracle listener. Verify that the connection
|
|
|
|
// succeeds.
|
|
|
|
// succeeds.
|
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
ChannelArgsEndpointConfig config; |
|
|
|
test_ee->Connect( |
|
|
|
test_ee->Connect( |
|
|
|
[&client_endpoint_promise]( |
|
|
|
[&client_endpoint, |
|
|
|
absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
&client_signal](absl::StatusOr<std::unique_ptr<Endpoint>> status) { |
|
|
|
if (!status.ok()) { |
|
|
|
if (!status.ok()) { |
|
|
|
gpr_log(GPR_ERROR, "Connect failed: %s", |
|
|
|
gpr_log(GPR_ERROR, "Connect failed: %s", |
|
|
|
status.status().ToString().c_str()); |
|
|
|
status.status().ToString().c_str()); |
|
|
|
client_endpoint_promise.Set(nullptr); |
|
|
|
client_endpoint = nullptr; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
client_endpoint_promise.Set(std::move(*status)); |
|
|
|
client_endpoint = std::move(*status); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
client_signal.Notify(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
URIToResolvedAddress(target_addrs[i % kNumListenerAddresses]), config, |
|
|
|
URIToResolvedAddress(target_addrs[i % kNumListenerAddresses]), config, |
|
|
|
memory_quota->CreateMemoryAllocator( |
|
|
|
memory_quota->CreateMemoryAllocator( |
|
|
|
absl::StrCat("conn-", std::to_string(i))), |
|
|
|
absl::StrCat("conn-", std::to_string(i))), |
|
|
|
24h); |
|
|
|
24h); |
|
|
|
|
|
|
|
|
|
|
|
auto client_endpoint = std::move(client_endpoint_promise.Get()); |
|
|
|
client_signal.WaitForNotification(); |
|
|
|
auto server_endpoint = std::move(server_endpoint_promise.Get()); |
|
|
|
server_signal->WaitForNotification(); |
|
|
|
EXPECT_TRUE(client_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(client_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(server_endpoint != nullptr); |
|
|
|
EXPECT_TRUE(server_endpoint != nullptr); |
|
|
|
connections.push_back(std::make_tuple(std::move(client_endpoint), |
|
|
|
connections.push_back(std::make_tuple(std::move(client_endpoint), |
|
|
|
std::move(server_endpoint))); |
|
|
|
std::move(server_endpoint))); |
|
|
|
client_endpoint_promise.Reset(); |
|
|
|
delete server_signal; |
|
|
|
server_endpoint_promise.Reset(); |
|
|
|
server_signal = new grpc_core::Notification(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
delete server_signal; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::thread> threads; |
|
|
|
std::vector<std::thread> threads; |
|
|
|
// Create one thread for each connection. For each connection, create
|
|
|
|
// Create one thread for each connection. For each connection, create
|
|
|
|