@@ -47,6 +47,22 @@ struct bad_actor_t : public r::actor_base_t {
4747 }
4848};
4949
50+ struct timer_actor_t : r::actor_base_t {
51+ using r::actor_base_t ::actor_base_t ;
52+ void on_start () noexcept override {
53+ r::actor_base_t::on_start ();
54+ auto timeout = r::pt::time_duration{r::pt::seconds{-1 }};
55+ auto req_id = start_timer (timeout, *this , &timer_actor_t ::on_timer);
56+ }
57+
58+ void on_timer (r::request_id_t req, bool cancelled){
59+ timer_triggered = true ;
60+ do_shutdown ();
61+ }
62+
63+ bool timer_triggered = false ;
64+ };
65+
5066TEST_CASE (" timer" , " [supervisor][asio]" ) {
5167 asio::io_context io_context{1 };
5268 auto timeout = r::pt::milliseconds{10 };
@@ -68,3 +84,24 @@ TEST_CASE("timer", "[supervisor][asio]") {
6884 REQUIRE (sup->get_leader_queue ().size () == 0 );
6985 CHECK (rt::empty (sup->get_subscription ()));
7086}
87+
88+ TEST_CASE (" zero timeout" , " [supervisor][asio]" ) {
89+ asio::io_context io_context{1 };
90+ auto timeout = r::pt::milliseconds{10 };
91+ auto system_context = ra::system_context_asio_t ::ptr_t {new ra::system_context_asio_t (io_context)};
92+ auto strand = std::make_shared<asio::io_context::strand>(io_context);
93+
94+ auto sup = system_context->create_supervisor <rt::supervisor_asio_test_t >().strand (strand).timeout (timeout).finish ();
95+ auto actor = sup->create_actor <timer_actor_t >().timeout (timeout).autoshutdown_supervisor ().finish ();
96+
97+ sup->start ();
98+ io_context.run ();
99+
100+ CHECK (actor->timer_triggered );
101+
102+ REQUIRE (static_cast <r::actor_base_t *>(actor.get ())->access <rt::to::state>() == r::state_t ::SHUT_DOWN);
103+
104+ REQUIRE (sup->get_state () == r::state_t ::SHUT_DOWN);
105+ REQUIRE (sup->get_leader_queue ().size () == 0 );
106+ CHECK (rt::empty (sup->get_subscription ()));
107+ }
0 commit comments