6#include <mp/test/foo.capnp.h>
7#include <mp/test/foo.capnp.proxy.h>
10#include <capnp/capability.h>
28 std::promise<std::unique_ptr<ProxyClient<messages::FooInterface>>> foo_promise;
29 std::function<void()> disconnect_client;
30 std::thread thread([&]() {
31 EventLoop loop(
"mptest", [](
bool raise,
const std::string& log) {
32 std::cout <<
"LOG" << raise <<
": " << log <<
"\n";
36 auto connection_client = std::make_unique<Connection>(loop, kj::mv(pipe.ends[0]));
37 auto foo_client = std::make_unique<ProxyClient<messages::FooInterface>>(
38 connection_client->m_rpc_system->bootstrap(
ServerVatId().vat_id).castAs<messages::FooInterface>(),
39 connection_client.get(),
false);
40 foo_promise.set_value(std::move(foo_client));
41 disconnect_client = [&] { loop.sync([&] { connection_client.reset(); }); };
43 auto connection_server = std::make_unique<Connection>(loop, kj::mv(pipe.ends[1]), [&](
Connection& connection) {
44 auto foo_server = kj::heap<ProxyServer<messages::FooInterface>>(std::make_shared<FooImplementation>(), connection);
45 return capnp::Capability::Client(kj::mv(foo_server));
47 connection_server->onDisconnect([&] { connection_server.reset(); });
51 auto foo = foo_promise.get_future().get();
52 KJ_EXPECT(foo->add(1, 2) == 3);
58 in.
vbool.push_back(
false);
59 in.
vbool.push_back(
true);
60 in.
vbool.push_back(
false);
63 KJ_EXPECT(in.
setint.size() ==
out.setint.size());
65 KJ_EXPECT(*
init == *outit);
67 KJ_EXPECT(in.
vbool.size() ==
out.vbool.size());
68 for (
size_t i = 0; i < in.
vbool.size(); ++i) {
69 KJ_EXPECT(in.
vbool[i] ==
out.vbool[i]);
84 int call(
int arg)
override
86 KJ_EXPECT(arg == m_expect);
89 int callExtended(
int arg)
override
91 KJ_EXPECT(arg == m_expect + 10);
98 Callback callback(1, 2);
99 KJ_EXPECT(foo->callback(callback, 1) == 2);
100 KJ_EXPECT(foo->callbackUnique(std::make_unique<Callback>(3, 4), 3) == 4);
101 KJ_EXPECT(foo->callbackShared(std::make_shared<Callback>(5, 6), 5) == 6);
102 auto saved = std::make_shared<Callback>(7, 8);
103 KJ_EXPECT(saved.use_count() == 1);
104 foo->saveCallback(saved);
105 KJ_EXPECT(saved.use_count() == 2);
106 foo->callbackSaved(7);
107 KJ_EXPECT(foo->callbackSaved(7) == 8);
108 foo->saveCallback(
nullptr);
109 KJ_EXPECT(saved.use_count() == 1);
110 KJ_EXPECT(foo->callbackExtended(callback, 11) == 12);
115 FooCustom custom_out = foo->passCustom(custom_in);
116 KJ_EXPECT(custom_in.
v1 == custom_out.
v1);
117 KJ_EXPECT(custom_in.
v2 == custom_out.
v2);
123 FooMessage message2{foo->passMessage(message1)};
124 KJ_EXPECT(message2.message ==
"init build read call build read");
128 foo->passMutable(mut);
129 KJ_EXPECT(mut.
message ==
"init build pass call return read");
134 bool destroyed =
false;
135 foo->m_context.cleanup_fns.emplace_front([&destroyed]{ destroyed =
true; });
137 KJ_EXPECT(destroyed);
Object holding network & rpc state associated with either an incoming server connection,...
Event loop implementation.
kj::AsyncIoContext m_io_context
Capnp IO context.
KJ_TEST("Call FooInterface methods")
Functions to serialize / deserialize common bitcoin types.
Vat id for server side of connection.
std::vector< bool > vbool