#include #include #include #include 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}); }