README.md
1A reusable test suite for EventEngine implementations.
2
3# Customizing tests for your EventEngine implementation
4
5To exercise a custom EventEngine, create a new bazel test target that links
6against some set of targets in the `//test/core/event_engine/test_suite/tests/...`
7folder, and provide a testing `main` function that sets a custom EventEngine factory.
8
9Your custom test target will look something like:
10
11```
12grpc_cc_test(
13 name = "my_custom_event_engine_test",
14 srcs = ["my_custom_event_engine_test.cc"],
15 uses_polling = False,
16 deps = ["//test/core/event_engine/test_suite/tests:timer"],
17)
18```
19
20And the main function will be similar to:
21
22```
23#include "path/to/my_custom_event_engine.h"
24#include "test/core/event_engine/test_suite/event_engine_test_framework.h"
25
26int main(int argc, char** argv) {
27 testing::InitGoogleTest(&argc, argv);
28 SetEventEngineFactory(
29 []() { return absl::make_unique<MyCustomEventEngine>(); });
30 auto result = RUN_ALL_TESTS();
31 return result;
32}
33```
34
35Alternatively, if you only want to exercise a subset of the conformance tests,
36you could depend on any subset of the following:
37
38* `//test/core/event_engine/test_suite/tests:timer`
39* `//test/core/event_engine/test_suite/tests:dns`
40* `//test/core/event_engine/test_suite/tests:client`
41* `//test/core/event_engine/test_suite/tests:server`
42
43# Useful testing tools
44
45The suite also provides [tools](tools/) that let you exercise your custom EventEngine in other ways.
46For example, the `echo_client` library allows you to prop up a TCP echo client based on your EventEngine::Connect and ::Endpoint implementations, and communicate with a remote TCP listener of your choosing.
47
48You'll need to provide the following code
49
50```
51# tools/BUILD:
52grpc_cc_binary(
53 name = "my_event_engine_echo_client",
54 srcs = ["my_event_engine_factory.cc"],
55 deps = ["echo_client"],
56)
57
58# tools/my_event_engine_factory.cc: an implementation of CustomEventEngineFactory
59absl::AnyInvocable<
60 std::unique_ptr<grpc_event_engine::experimental::EventEngine>(void)>
61CustomEventEngineFactory() {
62 return []() {
63 return std::make_unique<
64 grpc_event_engine::experimental::WindowsEventEngine>();
65 };
66}
67```
68
69To exercise the echo client, run `bazel run //test/core/event_engine/test_suite/tools:my_event_engine_echo_client`, and in a separate terminal, open something like netcat to run a TCP listener and communicate with the client.
70
71Each tool is documented more fully in its source file.
72