Commit ef96bb17 authored by Joseph Noir's avatar Joseph Noir

Add non-overriding receive timouts to actor clock

parent 5418edea
...@@ -56,7 +56,11 @@ public: ...@@ -56,7 +56,11 @@ public:
/// Schedules a `timeout_msg` for `self` at time point `t`, overriding any /// Schedules a `timeout_msg` for `self` at time point `t`, overriding any
/// previous receive timeout. /// previous receive timeout.
virtual void set_ordinary_timeout(time_point t, abstract_actor* self, virtual void set_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) = 0; atom_value type, uint64_t id) = 0;
/// Schedules a `timeout_msg` for `self` at time point `t`.
virtual void add_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) = 0;
/// Schedules a `sec::request_timeout` for `self` at time point `t`. /// Schedules a `sec::request_timeout` for `self` at time point `t`.
virtual void set_request_timeout(time_point t, abstract_actor* self, virtual void set_request_timeout(time_point t, abstract_actor* self,
......
...@@ -91,7 +91,10 @@ public: ...@@ -91,7 +91,10 @@ public:
}; };
void set_ordinary_timeout(time_point t, abstract_actor* self, void set_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) override; atom_value type, uint64_t id) override;
void add_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) override;
void set_request_timeout(time_point t, abstract_actor* self, void set_request_timeout(time_point t, abstract_actor* self,
message_id id) override; message_id id) override;
......
...@@ -62,7 +62,7 @@ void simple_actor_clock::visitor::operator()(group_msg& x) { ...@@ -62,7 +62,7 @@ void simple_actor_clock::visitor::operator()(group_msg& x) {
} }
void simple_actor_clock::set_ordinary_timeout(time_point t, abstract_actor* self, void simple_actor_clock::set_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) { atom_value type, uint64_t id) {
ordinary_predicate pred{type}; ordinary_predicate pred{type};
auto i = lookup(self, pred); auto i = lookup(self, pred);
auto sptr = actor_cast<strong_actor_ptr>(self); auto sptr = actor_cast<strong_actor_ptr>(self);
...@@ -76,6 +76,14 @@ void simple_actor_clock::set_ordinary_timeout(time_point t, abstract_actor* self ...@@ -76,6 +76,14 @@ void simple_actor_clock::set_ordinary_timeout(time_point t, abstract_actor* self
} }
} }
void simple_actor_clock::add_ordinary_timeout(time_point t, abstract_actor* self,
atom_value type, uint64_t id) {
auto sptr = actor_cast<strong_actor_ptr>(self);
ordinary_timeout tmp{std::move(sptr), type, id};
auto j = schedule_.emplace(t, std::move(tmp));
actor_lookup_.emplace(self, j);
}
void simple_actor_clock::set_request_timeout(time_point t, abstract_actor* self, void simple_actor_clock::set_request_timeout(time_point t, abstract_actor* self,
message_id id) { message_id id) {
request_predicate pred{id}; request_predicate pred{id};
......
...@@ -47,6 +47,11 @@ behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self, ...@@ -47,6 +47,11 @@ behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self,
t->set_ordinary_timeout(n, self, atom(""), self->state.timeout_id); t->set_ordinary_timeout(n, self, atom(""), self->state.timeout_id);
}, },
[=](add_atom) { [=](add_atom) {
auto n = t->now() + seconds(10);
self->state.timeout_id += 1;
t->add_ordinary_timeout(n, self, atom(""), self->state.timeout_id);
},
[=](put_atom) {
auto n = t->now() + seconds(10); auto n = t->now() + seconds(10);
self->state.timeout_id += 1; self->state.timeout_id += 1;
auto mid = make_message_id(self->state.timeout_id).response_id(); auto mid = make_message_id(self->state.timeout_id).response_id();
...@@ -124,12 +129,39 @@ CAF_TEST(override_receive_timeout) { ...@@ -124,12 +129,39 @@ CAF_TEST(override_receive_timeout) {
expect((timeout_msg), from(aut).to(aut).with(tid{43})); expect((timeout_msg), from(aut).to(aut).with(tid{43}));
} }
CAF_TEST(single_request_timeout) { CAF_TEST(add_receive_timeout) {
// Have AUT call t.set_request_timeout(). // Have AUT call t.set_receive_timeout().
self->send(aut, add_atom::value); self->send(aut, add_atom::value);
expect((add_atom), from(self).to(aut).with(_)); expect((add_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 1u); CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u); CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time just a little bit.
t.advance_time(seconds(5));
// Have AUT call t.set_timeout() again.
self->send(aut, add_atom::value);
expect((add_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 2u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u);
// Advance time to send timeout message.
t.advance_time(seconds(5));
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{42}));
// Advance time to send second timeout message.
t.advance_time(seconds(5));
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{43}));
}
CAF_TEST(single_request_timeout) {
// Have AUT call t.set_request_timeout().
self->send(aut, put_atom::value);
expect((put_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time to send timeout message. // Advance time to send timeout message.
t.advance_time(seconds(10)); t.advance_time(seconds(10));
CAF_CHECK_EQUAL(t.schedule().size(), 0u); CAF_CHECK_EQUAL(t.schedule().size(), 0u);
...@@ -147,8 +179,8 @@ CAF_TEST(mixed_receive_and_request_timeouts) { ...@@ -147,8 +179,8 @@ CAF_TEST(mixed_receive_and_request_timeouts) {
// Cause the request timeout to arrive later. // Cause the request timeout to arrive later.
t.advance_time(seconds(5)); t.advance_time(seconds(5));
// Have AUT call t.set_request_timeout(). // Have AUT call t.set_request_timeout().
self->send(aut, add_atom::value); self->send(aut, put_atom::value);
expect((add_atom), from(self).to(aut).with(_)); expect((put_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 2u); CAF_CHECK_EQUAL(t.schedule().size(), 2u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u); CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u);
// Advance time to send receive timeout message. // Advance time to send receive timeout message.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment