RPC: host adapter boundary for embedded and managed modes (S-RPC-05)

This commit is contained in:
faumaray committed 2026-12-03 20:10:11 +03:00
1 parent 1f92dd054e
commit c6c0303ef8
3 files changed
+201

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
#include <Void/RPC/HostAdapter.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <cstddef>
namespace
{
using namespace Void::RPC;
} // namespace
Void::Testing::Test rpc_inline_host_runs_work_immediately()
{
InlineHostAdapter host;
int ran = 0;
Void::Testing::expect(host.post([&ran] { ++ran; }));
Void::Testing::expect_eq(ran, 1);
Void::Testing::expect(host.drains_automatically());
Void::Testing::expect(!host.post({}));
}
Void::Testing::Test rpc_deferred_host_is_bounded_and_externally_driven()
{
DeferredHostAdapter host{HostLimits{.max_pending_tasks = 2}};
int ran = 0;
Void::Testing::expect(host.post([&ran] { ++ran; }));
Void::Testing::expect(host.post([&ran] { ++ran; }));
// At capacity: the caller must apply backpressure.
Void::Testing::expect(!host.post([&ran] { ++ran; }));
Void::Testing::expect(!host.post({}));
Void::Testing::expect_eq(host.pending(), std::size_t{2});
Void::Testing::expect_eq(host.capacity(), std::size_t{2});
Void::Testing::expect(!host.drains_automatically());
Void::Testing::expect_eq(ran, 0);
// Budgeted pump.
Void::Testing::expect_eq(host.run_ready(1), std::size_t{1});
Void::Testing::expect_eq(ran, 1);
Void::Testing::expect_eq(host.pending(), std::size_t{1});
// Zero budget drains everything that is ready.
Void::Testing::expect_eq(host.run_ready(0), std::size_t{1});
Void::Testing::expect_eq(ran, 2);
Void::Testing::expect_eq(host.pending(), std::size_t{0});
}
Void::Testing::Test rpc_deferred_host_runs_nested_posts_in_same_pump()
{
DeferredHostAdapter host;
int ran = 0;
Void::Testing::expect(host.post([&] {
++ran;
Void::Testing::expect(host.post([&] { ++ran; }));
}));
Void::Testing::expect_eq(host.run_ready(0), std::size_t{2});
Void::Testing::expect_eq(ran, 2);
Void::Testing::expect_eq(host.pending(), std::size_t{0});
}