Hi Jens,

Sorry for the slow reply.

Usually when I write tests, I don't actually use the RPC system, but rather
have the client call the server directly running in the same thread.
Remember that you can implicitly turn an `Own<MyInterface::Server>` into a
`MyInterface::Client`, and then call it like a client:

    MyInterface::Client client = kj::heap<MyServerImpl>();

In theory, whether or not you have an actual RPC connection in between
should be transparent.

-Kenton

On Mon, Feb 21, 2022 at 11:47 AM Jens Alfke <j...@mooseyard.com> wrote:

> Does anyone have advice on writing C++ automated tests for RPC-based code?
> (FWIW, I use the Catch2 unit-test framework, but I don’t restrict it to
> true ‘unit’ tests.) Say I’ve got an interface file, a class `Client` built
> atop classes generated from that interface, and a class `Server` that
> accepts TCP connections from a `Client`. I want to write a test that
> creates a Client and Server, connects them to each other, and then invokes
> some operations on the Client and asserts the correct results.
>
> The first step of course is creating a connection. It looks like the
> simplest supported mechanism is to open a POSIX pipe and then create kj
> AsyncStreams on its two file descriptors. That means I’ll need an
> alternative Client constructor that takes a file descriptor or stream
> instead of a hostname/port…
>
> I’d love to take a look at anyone’s test code that does stuff like this.
>
> —Jens
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to capnproto+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/CED5FAAE-EC6B-47E7-BDE3-58F3C1DD001F%40mooseyard.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQ%3DgXqjV4rV6-eX28aZqL%2BOuvGOu5hnc54vsVTq5_-Z%2BGA%40mail.gmail.com.

Reply via email to