- simgrid::s4u::ActorPtr sender = simgrid::s4u::Actor::create("sender", all_hosts[2], [&start]() {
- assert_exit(false, 9);
- int data = 42;
- double milestone[5] = {1.5, 2.5, 5.5, 6.5, 9.0};
- for (int i = 0; i < 5; i++)
- milestone[i] += start;
- for (int i = 0; i < 2; i++) {
- simgrid::s4u::this_actor::sleep_until(milestone[i]);
- XBT_VERB("dsend(%c)", 'A' + i);
- simgrid::s4u::Mailbox::by_name("mb")->put_init(&data, 100000)->detach();
- }
- for (int i = 2; i < 4; i++) {
- simgrid::s4u::this_actor::sleep_until(milestone[i]);
- try {
- XBT_VERB("put(%c)", 'A' + i);
- simgrid::s4u::Mailbox::by_name("mb")->put(&data, 100000);
- return;
- } catch (simgrid::NetworkFailureException const&) {
- XBT_VERB("got expected NetworkFailureException");
+ BEGIN_SECTION("comm recv and kill")
+ {
+ XBT_INFO("Launch an actor that waits on a recv, kill its host");
+ bool in_on_exit = false;
+ bool returned_from_main = false;
+ bool in_catch_before_on_exit = false;
+ bool in_catch_after_on_exit = false;
+ bool send_done = false;
+
+ simgrid::s4u::ActorPtr receiver =
+ simgrid::s4u::Actor::create("receiver", all_hosts[1], [&in_on_exit, &returned_from_main,
+ &in_catch_before_on_exit, &in_catch_after_on_exit]() {
+ assert_exit(false, 1);
+ try {
+ simgrid::s4u::Mailbox::by_name("mb")->get();
+ } catch (simgrid::NetworkFailureException const&) {
+ // Shouldn't get in here
+ in_catch_before_on_exit = not in_on_exit;
+ in_catch_after_on_exit = in_on_exit;
+ }
+ returned_from_main = true;
+ });
+
+ receiver->on_exit([&in_on_exit](bool) { in_on_exit = true; });
+
+ simgrid::s4u::ActorPtr sender = simgrid::s4u::Actor::create("sender", all_hosts[2], [&send_done]() {
+ assert_exit(true, 1);
+ int data = 42;
+ REQUIRE_THROWS_AS(simgrid::s4u::Mailbox::by_name("mb")->put(&data, 100000), simgrid::NetworkFailureException);
+ send_done = true;
+ });
+
+ simgrid::s4u::this_actor::sleep_for(1);
+ receiver->get_host()->turn_off();
+
+ // Note: If we don't sleep here, we don't "see" the bug
+ simgrid::s4u::this_actor::sleep_for(1);
+
+ INFO("Receiver's on_exit function was never called");
+ REQUIRE(in_on_exit);
+ INFO("or receiver mistakenly went to catch clause (before the on_exit function was called)");
+ REQUIRE(not in_catch_before_on_exit);
+ INFO("or receiver mistakenly went to catch clause (after the on_exit function was called)");
+ REQUIRE(not in_catch_after_on_exit);
+ INFO("or receiver returned from main normally even though its host was killed");
+ REQUIRE(not returned_from_main);
+ INFO("or sender killed somehow, and it shouldn't");
+ REQUIRE(send_done);
+ receiver->get_host()->turn_on();
+
+ END_SECTION;
+ }
+
+ static auto test_link_off_helper = [](double delay) {
+ const double start = simgrid::s4u::Engine::get_clock();
+
+ simgrid::s4u::ActorPtr receiver = simgrid::s4u::Actor::create("receiver", all_hosts[1], [&start]() {
+ assert_exit(true, 9);
+ double milestone[5] = {0.5, 3.5, 4.5, 7.5, 9.0};
+ for (int i = 0; i < 5; i++)
+ milestone[i] += start;
+ for (int i = 0; i < 4; i++) {
+ simgrid::s4u::this_actor::sleep_until(milestone[i]);
+ try {
+ XBT_VERB("get(%c)", 'A' + i);
+ simgrid::s4u::Mailbox::by_name("mb")->get();
+ return;
+ } catch (simgrid::NetworkFailureException const&) {
+ XBT_VERB("got expected NetworkFailureException");
+ }
+ }
+ simgrid::s4u::this_actor::sleep_until(milestone[4]);
+ });
+
+ simgrid::s4u::ActorPtr sender = simgrid::s4u::Actor::create("sender", all_hosts[2], [&start]() {
+ assert_exit(true, 9);
+ int data = 42;
+ double milestone[5] = {1.5, 2.5, 5.5, 6.5, 9.0};
+ for (int i = 0; i < 5; i++)
+ milestone[i] += start;
+ for (int i = 0; i < 2; i++) {
+ simgrid::s4u::this_actor::sleep_until(milestone[i]);
+ XBT_VERB("dsend(%c)", 'A' + i);
+ simgrid::s4u::Mailbox::by_name("mb")->put_init(&data, 100000)->detach();