Provide coroutine process interface for handler (#521)

Fixes #522
This commit is contained in:
cyan317
2023-02-23 16:35:01 +00:00
committed by GitHub
parent d74ca4940b
commit f6c2008540
5 changed files with 107 additions and 16 deletions

View File

@@ -50,6 +50,24 @@ TEST_F(RPCTestHandlerTest, HandlerSuccess)
EXPECT_EQ(val.as_object().at("computed").as_string(), "world_10");
}
TEST_F(RPCTestHandlerTest, CoroutineHandlerSuccess)
{
auto const handler = AnyHandler{CoroutineHandlerFake{}};
auto const input = json::parse(R"({
"hello": "world",
"limit": 10
})");
boost::asio::io_context ctx;
boost::asio::spawn(ctx, [&](boost::asio::yield_context yield) {
auto const output = handler.process(input, yield);
ASSERT_TRUE(output);
auto const val = output.value();
EXPECT_EQ(val.as_object().at("computed").as_string(), "world_10");
});
ctx.run();
}
TEST_F(RPCTestHandlerTest, NoInputHandlerSuccess)
{
auto const handler = AnyHandler{NoInputHandlerFake{}};