Skip to content

Commit

Permalink
[chaotic-good] Fix timeout in test suite (grpc#38177)
Browse files Browse the repository at this point in the history
Split the test suite into multiple tests (one per fixture) to avoid a timeout

Closes grpc#38177

COPYBARA_INTEGRATE_REVIEW=grpc#38177 from ctiller:timeout 2371f5d
PiperOrigin-RevId: 699518935
  • Loading branch information
ctiller authored and copybara-github committed Nov 23, 2024
1 parent cfda657 commit d1035ba
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 100 deletions.
74 changes: 74 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 41 additions & 2 deletions test/core/transport/test_suite/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ grpc_cc_library(
)

grpc_cc_library(
name = "chaotic_good_fixture",
name = "chaotic_good_fixture_helpers",
testonly = 1,
srcs = ["chaotic_good_fixture.cc"],
srcs = ["chaotic_good_fixture_helpers.cc"],
hdrs = ["chaotic_good_fixture_helpers.h"],
external_deps = [
"absl/log:check",
"gtest",
Expand All @@ -49,6 +50,33 @@ grpc_cc_library(
"//src/core:grpc_promise_endpoint",
"//src/core:resource_quota",
],
)

grpc_cc_library(
name = "chaotic_good_fixture",
testonly = 1,
srcs = ["chaotic_good_fixture.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [
"chaotic_good_fixture_helpers",
],
alwayslink = 1,
)

grpc_cc_library(
name = "chaotic_good_single_connection_fixture",
testonly = 1,
srcs = ["chaotic_good_single_connection_fixture.cc"],
external_deps = [
"absl/log:check",
"gtest",
],
deps = [
"chaotic_good_fixture_helpers",
],
alwayslink = 1,
)

Expand Down Expand Up @@ -123,3 +151,14 @@ grpc_transport_test(
":stress",
],
)

grpc_transport_test(
name = "chaotic_good_single_connection",
deps = [
":call_content",
":call_shapes",
":chaotic_good_single_connection_fixture",
":no_op",
":stress",
],
)
101 changes: 3 additions & 98 deletions test/core/transport/test_suite/chaotic_good_fixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,91 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>
#include "test/core/transport/test_suite/chaotic_good_fixture_helpers.h"

#include "absl/log/check.h"
#include "gmock/gmock.h"
#include "src/core/ext/transport/chaotic_good/client_transport.h"
#include "src/core/ext/transport/chaotic_good/server_transport.h"
#include "src/core/lib/event_engine/memory_allocator_factory.h"
#include "src/core/lib/event_engine/tcp_socket_utils.h"
#include "src/core/lib/resource_quota/resource_quota.h"
#include "src/core/lib/transport/promise_endpoint.h"
#include "test/core/transport/test_suite/transport_test.h"

using grpc_event_engine::experimental::EndpointConfig;
using grpc_event_engine::experimental::EventEngine;
using grpc_event_engine::experimental::FuzzingEventEngine;
using grpc_event_engine::experimental::MemoryQuotaBasedMemoryAllocatorFactory;
using grpc_event_engine::experimental::URIToResolvedAddress;

namespace grpc_core {

namespace {

class MockEndpointConfig : public EndpointConfig {
public:
MOCK_METHOD(absl::optional<int>, GetInt, (absl::string_view key),
(const, override));
MOCK_METHOD(absl::optional<absl::string_view>, GetString,
(absl::string_view key), (const, override));
MOCK_METHOD(void*, GetVoidPointer, (absl::string_view key),
(const, override));
};

struct EndpointPair {
PromiseEndpoint client;
PromiseEndpoint server;
};

EndpointPair CreateEndpointPair(
grpc_event_engine::experimental::FuzzingEventEngine* event_engine,
ResourceQuotaRefPtr resource_quota, int port) {
std::unique_ptr<EventEngine::Endpoint> client_endpoint;
std::unique_ptr<EventEngine::Endpoint> server_endpoint;

const auto resolved_address =
URIToResolvedAddress(absl::StrCat("ipv4:127.0.0.1:", port)).value();

::testing::StrictMock<MockEndpointConfig> endpoint_config;
auto listener = *event_engine->CreateListener(
[&server_endpoint](std::unique_ptr<EventEngine::Endpoint> endpoint,
MemoryAllocator) {
server_endpoint = std::move(endpoint);
},
[](absl::Status) {}, endpoint_config,
std::make_unique<MemoryQuotaBasedMemoryAllocatorFactory>(
resource_quota->memory_quota()));
CHECK_OK(listener->Bind(resolved_address));
CHECK_OK(listener->Start());

event_engine->Connect(
[&client_endpoint](
absl::StatusOr<std::unique_ptr<EventEngine::Endpoint>> endpoint) {
CHECK_OK(endpoint);
client_endpoint = std::move(endpoint).value();
},
resolved_address, endpoint_config,
resource_quota->memory_quota()->CreateMemoryAllocator("client"),
Duration::Hours(3));

while (client_endpoint == nullptr || server_endpoint == nullptr) {
event_engine->Tick();
}

return EndpointPair{
PromiseEndpoint(std::move(client_endpoint), SliceBuffer()),
PromiseEndpoint(std::move(server_endpoint), SliceBuffer())};
}

} // namespace

TRANSPORT_FIXTURE(ChaoticGood) {
auto resource_quota = MakeResourceQuota("test");
EndpointPair control_endpoints =
CreateEndpointPair(event_engine.get(), resource_quota, 1234);
CreateEndpointPair(event_engine.get(), resource_quota.get(), 1234);
EndpointPair data_endpoints =
CreateEndpointPair(event_engine.get(), resource_quota, 4321);
CreateEndpointPair(event_engine.get(), resource_quota.get(), 4321);
auto channel_args =
ChannelArgs()
.SetObject(resource_quota)
Expand All @@ -115,26 +42,4 @@ TRANSPORT_FIXTURE(ChaoticGood) {
std::move(server_transport)};
}

TRANSPORT_FIXTURE(ChaoticGoodSingleConnection) {
auto resource_quota = MakeResourceQuota("test");
EndpointPair control_endpoints =
CreateEndpointPair(event_engine.get(), resource_quota, 1234);
EndpointPair data_endpoints =
CreateEndpointPair(event_engine.get(), resource_quota, 4321);
auto channel_args =
ChannelArgs()
.SetObject(resource_quota)
.SetObject(std::static_pointer_cast<EventEngine>(event_engine));
auto client_transport =
MakeOrphanable<chaotic_good::ChaoticGoodClientTransport>(
std::move(control_endpoints.client), std::vector<PromiseEndpoint>{},
ChannelArgs().SetObject(resource_quota), event_engine);
auto server_transport =
MakeOrphanable<chaotic_good::ChaoticGoodServerTransport>(
channel_args, std::move(control_endpoints.server),
std::vector<PromiseEndpoint>{}, event_engine);
return ClientAndServerTransportPair{std::move(client_transport),
std::move(server_transport)};
}

} // namespace grpc_core
Loading

0 comments on commit d1035ba

Please sign in to comment.