Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw_rpc2
  5. Testing
  6. pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes > Class Template Reference
Loading...
Searching...
No Matches
pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes > Class Template Reference

Overview

template<typename ServiceImpl, size_t kAllocatorSizeBytes = 16384>
class pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >

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)
 

Member Function Documentation

◆ allocator()

template<typename ServiceImpl , size_t kAllocatorSizeBytes = 16384>
pw::Allocator & pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >::allocator ( )
inline

Returns the test allocator (which also implicitly converts to pw::async2::CoroContext).

◆ pwpb_client()

template<typename ServiceImpl , size_t kAllocatorSizeBytes = 16384>
PwpbClient pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >::pwpb_client ( ) const
inline

Returns a generated pwpb service client bound to the connected Client. Requires the .pwpb.rpc2.h header for this service to be included.

◆ raw_client()

template<typename ServiceImpl , size_t kAllocatorSizeBytes = 16384>
RawClient pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >::raw_client ( ) const
inline

Returns a generated raw service client bound to the connected Client. Requires the .raw.rpc2.h header for this service to be included.

◆ RunInTaskUntilStalled()

template<typename ServiceImpl , size_t kAllocatorSizeBytes = 16384>
template<typename Fut >
auto pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >::RunInTaskUntilStalled ( Fut &  future)
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.

◆ RunToCompletion()

template<typename ServiceImpl , size_t kAllocatorSizeBytes = 16384>
template<typename T >
auto pw::rpc2::test::TestHarness< ServiceImpl, kAllocatorSizeBytes >::RunToCompletion ( T &&  runnable)
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:

  1. Any pw::async2::Future (e.g. tester.pwpb_client().MyUnary(req) or a pw::async2::Coro<T>).
  2. Any pw::async2::Task lvalue.
  3. A coroutine callable (pw::async2::CoroContext) -> pw::async2::Coro<T>.

The documentation for this class was generated from the following file: