Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add test for FG simgrid/simgrid#26.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 24 Jun 2019 15:02:29 +0000 (17:02 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 24 Jun 2019 15:02:29 +0000 (17:02 +0200)
teshsuite/s4u/activity-lifecycle/activity-lifecycle.cpp

index f324b17..d5ae2d2 100644 (file)
@@ -394,6 +394,7 @@ static void test_host_off_while_receive()
   
   // Note: If we don't sleep here, we don't "see" the bug
   simgrid::s4u::this_actor::sleep_for(1);
+  receiver->get_host()->turn_on(); // switch host on again
 
   xbt_assert(in_on_exit, 
     "Receiver's on_exit function was never called");
@@ -406,6 +407,38 @@ static void test_host_off_while_receive()
   xbt_assert(send_done, "Sender killed somehow. It shouldn't");
 }
 
+static void test_link_off()
+{
+  XBT_INFO("%s: Launch an actor that waits on a recv, turn communicating link off", __func__);
+  bool sender_got_exception   = false;
+  bool receiver_got_exception = false;
+
+  simgrid::s4u::ActorPtr receiver = simgrid::s4u::Actor::create("receiver", all_hosts[1], [&receiver_got_exception]() {
+    assert_exit(false, 1);
+    try {
+      simgrid::s4u::Mailbox::by_name("mb")->get();
+    } catch (simgrid::NetworkFailureException const&) {
+      receiver_got_exception = true;
+    }
+  });
+
+  simgrid::s4u::ActorPtr sender = simgrid::s4u::Actor::create("sender", all_hosts[2], [&sender_got_exception]() {
+    assert_exit(false, 1);
+    try {
+      int data = 42;
+      simgrid::s4u::Mailbox::by_name("mb")->put(&data, 100000);
+    } catch (simgrid::NetworkFailureException const&) {
+      sender_got_exception = true;
+    }
+  });
+
+  simgrid::s4u::this_actor::sleep_for(1);
+  simgrid::s4u::Link::by_name("link1")->turn_off();
+  simgrid::s4u::Link::by_name("link1")->turn_on();
+  xbt_assert(receiver_got_exception, "Receiver should have caught a NetworkFailureException");
+  xbt_assert(sender_got_exception, "Sender should have caught a NetworkFailureException");
+}
+
 /* We need an extra actor here, so that it can sleep until the end of each test */
 static void main_dispatcher()
 {
@@ -431,6 +464,7 @@ static void main_dispatcher()
   run_test("comm kill sender", test_comm_killsend);
 
   run_test("comm recv and kill", test_host_off_while_receive);
+  run_test("comm turn link off", test_link_off);
 }
 
 int main(int argc, char* argv[])