End-to-end dependency-injection test fixture for a pw_rpc2 service or client.
Instantiates and connects a real Server (hosting ServiceImpl) and a Client over an in-memory PairedConnection on a single DispatcherForTest. Tests drive RPCs through the generated raw or pwpb client API using RunToCompletion(), RunInTaskUntilStalled(), or dispatcher().
Public Types | |
| using | RawClient = typename ::pw::rpc2::internal::ServiceInfo< ServiceImpl >::RawClient |
| using | PwpbClient = typename ::pw::rpc2::internal::ServiceInfo< ServiceImpl >::PwpbClient |
Public Member Functions | |
| template<typename... Args, typename = std::enable_if_t<std::is_constructible_v<ServiceImpl, Args...>>> | |
| TestHarness (Args &&... service_args) | |
| TestHarness (const TestHarness &)=delete | |
| TestHarness & | operator= (const TestHarness &)=delete |
| TestHarness (TestHarness &&)=delete | |
| TestHarness & | operator= (TestHarness &&)=delete |
| const Client & | client () const |
Returns the connected pw::rpc2::Client. | |
| RawClient | raw_client () const |
| PwpbClient | pwpb_client () const |
| ServiceImpl & | service () |
| Returns the service instance under test. | |
| const ServiceImpl & | service () const |
| pw::async2::DispatcherForTest & | dispatcher () |
| Returns the shared test dispatcher driving both client and server. | |
| pw::Allocator & | allocator () |
| bool | RunUntilStalled () |
| Advances the dispatcher until all ready tasks have stalled. | |
| template<typename Fut > | |
| auto | RunInTaskUntilStalled (Fut &future) |
| template<typename T > | |
| auto | RunToCompletion (T &&runnable) |
|
inline |
Returns the test allocator (which also implicitly converts to pw::async2::CoroContext).
|
inline |
Returns a generated pwpb service client bound to the connected Client. Requires the .pwpb.rpc2.h header for this service to be included.
|
inline |
Returns a generated raw service client bound to the connected Client. Requires the .raw.rpc2.h header for this service to be included.
|
inline |
Runs a persistent future or coroutine in a task until no further progress can be made, returning its Poll state without destroying the future.
|
inline |
Drives runnable to completion on the test dispatcher and returns its result (or void). Crashes with PW_CHECK if the dispatcher stalls before runnable completes.
Accepts:
pw::async2::Future (e.g. tester.pwpb_client().MyUnary(req) or a pw::async2::Coro<T>).pw::async2::Task lvalue.(pw::async2::CoroContext) -> pw::async2::Coro<T>.