From 12cf6458c8d705665dd4b599a0c765bb943f765a Mon Sep 17 00:00:00 2001 From: Jakub Domagala Date: Tue, 11 Aug 2020 15:25:49 +0200 Subject: [PATCH] #955 Clear out uses of addAction in tests --- tests/unit/pipe/test_callback_func.cc | 16 +-- tests/unit/pipe/test_callback_func_ctx.cc | 41 ++++--- tests/unit/pipe/test_callback_send.cc | 70 ++++++----- .../test_callback_send_collection.extended.cc | 110 +++++++++-------- .../unit/sequencer/test_sequencer.extended.cc | 112 ++++++++--------- .../test_sequencer_extensive.extended.cc | 46 +++---- .../sequencer/test_sequencer_for.extended.cc | 22 ++-- .../test_sequencer_nested.extended.cc | 27 +++-- .../test_sequencer_parallel.extended.cc | 51 ++++---- .../sequencer/test_sequencer_vrt.extended.cc | 113 +++++++++--------- 10 files changed, 315 insertions(+), 293 deletions(-) diff --git a/tests/unit/pipe/test_callback_func.cc b/tests/unit/pipe/test_callback_func.cc index 94f726851c..438a9f8e9b 100644 --- a/tests/unit/pipe/test_callback_func.cc +++ b/tests/unit/pipe/test_callback_func.cc @@ -88,14 +88,16 @@ TEST_F(TestCallbackFunc, test_callback_func_2) { called = 0; - if (this_node == 0) { - auto cb = theCB()->makeFunc([]{ called = 400; }); - auto msg = makeMessage(cb); - theMsg()->sendMsg(1, msg.get()); + runInEpochCollective([=] { + if (this_node == 0) { + auto cb = theCB()->makeFunc([] { called = 400; }); + auto msg = makeMessage(cb); + theMsg()->sendMsg(1, msg.get()); + } + }); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 400); - }); + if (this_node == 0) { + EXPECT_EQ(called, 400); } } diff --git a/tests/unit/pipe/test_callback_func_ctx.cc b/tests/unit/pipe/test_callback_func_ctx.cc index 71e50b420b..c91a90c06c 100644 --- a/tests/unit/pipe/test_callback_func_ctx.cc +++ b/tests/unit/pipe/test_callback_func_ctx.cc @@ -115,28 +115,27 @@ TEST_F(TestCallbackFuncCtx, test_callback_func_ctx_2) { return; } - ctx = std::make_unique(); - ctx->val = this_node; - - auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; - auto cb = theCB()->makeFunc( - ctx.get(), [next](DataMsg* msg, Context* my_ctx){ - called = 500; - EXPECT_EQ(my_ctx->val, theContext()->getNode()); - //fmt::print("{}: a={},b={},c={}\n",n,msg->a,msg->b,msg->c); - EXPECT_EQ(msg->a, next+1); - EXPECT_EQ(msg->b, next+2); - EXPECT_EQ(msg->c, next+3); - } - ); - //fmt::print("{}: next={}\n", this_node, next); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); - - theTerm()->addAction([=]{ - //fmt::print("{}: called={}\n", this_node, called); - EXPECT_EQ(called, 500); + runInEpochCollective([=] { + ctx = std::make_unique(); + ctx->val = this_node; + + auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; + auto cb = theCB()->makeFunc( + ctx.get(), [next](DataMsg* msg, Context* my_ctx) { + called = 500; + EXPECT_EQ(my_ctx->val, theContext()->getNode()); + // fmt::print("{}: a={},b={},c={}\n",n,msg->a,msg->b,msg->c); + EXPECT_EQ(msg->a, next + 1); + EXPECT_EQ(msg->b, next + 2); + EXPECT_EQ(msg->c, next + 3); + }); + // fmt::print("{}: next={}\n", this_node, next); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); }); + + // fmt::print("{}: called={}\n", this_node, called); + EXPECT_EQ(called, 500); } }}} // end namespace vt::tests::unit diff --git a/tests/unit/pipe/test_callback_send.cc b/tests/unit/pipe/test_callback_send.cc index 605127e30d..e5798c19ca 100644 --- a/tests/unit/pipe/test_callback_send.cc +++ b/tests/unit/pipe/test_callback_send.cc @@ -114,36 +114,39 @@ TEST_F(TestCallbackSend, test_callback_send_1) { auto const& this_node = theContext()->getNode(); called = 0; - auto cb = theCB()->makeSend(this_node); - auto nmsg = makeMessage(1,2,3); - cb.send(nmsg.get()); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 100); + runInEpochCollective([=] { + auto cb = theCB()->makeSend(this_node); + auto nmsg = makeMessage(1, 2, 3); + cb.send(nmsg.get()); }); + + EXPECT_EQ(called, 100); } TEST_F(TestCallbackSend, test_callback_send_2) { auto const& this_node = theContext()->getNode(); called = 0; - auto cb = theCB()->makeSend(this_node); - auto nmsg = makeMessage(1,2,3); - cb.send(nmsg.get()); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 200); + runInEpochCollective([=] { + auto cb = theCB()->makeSend(this_node); + auto nmsg = makeMessage(1, 2, 3); + cb.send(nmsg.get()); }); + + EXPECT_EQ(called, 200); } TEST_F(TestCallbackSend, test_callback_send_3) { auto const& this_node = theContext()->getNode(); called = 0; - auto cb = theCB()->makeSend(this_node); - cb.send(); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 300); + runInEpochCollective([=] { + auto cb = theCB()->makeSend(this_node); + cb.send(); }); + + EXPECT_EQ(called, 300); } TEST_F(TestCallbackSend, test_callback_send_remote_1) { @@ -151,14 +154,15 @@ TEST_F(TestCallbackSend, test_callback_send_remote_1) { auto const& num_nodes = theContext()->getNumNodes(); called = 0; - auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; - auto cb = theCB()->makeSend(this_node); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 100); + runInEpochCollective([=] { + auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; + auto cb = theCB()->makeSend(this_node); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); }); + + EXPECT_EQ(called, 100); } TEST_F(TestCallbackSend, test_callback_send_remote_2) { @@ -166,14 +170,15 @@ TEST_F(TestCallbackSend, test_callback_send_remote_2) { auto const& num_nodes = theContext()->getNumNodes(); called = 0; - auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; - auto cb = theCB()->makeSend(this_node); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 200); + runInEpochCollective([=] { + auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; + auto cb = theCB()->makeSend(this_node); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); }); + + EXPECT_EQ(called, 200); } TEST_F(TestCallbackSend, test_callback_send_remote_3) { @@ -181,14 +186,15 @@ TEST_F(TestCallbackSend, test_callback_send_remote_3) { auto const& num_nodes = theContext()->getNumNodes(); called = 0; - auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; - auto cb = theCB()->makeSend(this_node); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); - theTerm()->addAction([=]{ - EXPECT_EQ(called, 300); + runInEpochCollective([=] { + auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; + auto cb = theCB()->makeSend(this_node); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); }); + + EXPECT_EQ(called, 300); } diff --git a/tests/unit/pipe/test_callback_send_collection.extended.cc b/tests/unit/pipe/test_callback_send_collection.extended.cc index 7cdc66d9af..a9a02a9144 100644 --- a/tests/unit/pipe/test_callback_send_collection.extended.cc +++ b/tests/unit/pipe/test_callback_send_collection.extended.cc @@ -128,25 +128,29 @@ static void cb3(DataMsg* msg, TestCol* col) { TEST_F(TestCallbackSendCollection, test_callback_send_collection_1) { auto const& this_node = theContext()->getNode(); - if (this_node == 0) { - auto const& range = Index1D(32); - auto proxy = theCollection()->construct(range); - - for (auto i = 0; i < 32; i++) { - if (i % 2 == 0) { - auto cb = theCB()->makeSend(proxy(i)); - auto nmsg = makeMessage(8,9,10); - cb.send(nmsg.get()); - } else { - auto cb = theCB()->makeSend(proxy(i)); - auto nmsg = makeMessage(8,9,10); - cb.send(nmsg.get()); + runInEpochCollective([=] { + if (this_node == 0) { + auto const& range = Index1D(32); + auto proxy = theCollection()->construct(range); + + for (auto i = 0; i < 32; i++) { + if (i % 2 == 0) { + auto cb = + theCB()->makeSend(proxy(i)); + auto nmsg = makeMessage(8, 9, 10); + cb.send(nmsg.get()); + } else { + auto cb = + theCB()->makeSend(proxy(i)); + auto nmsg = makeMessage(8, 9, 10); + cb.send(nmsg.get()); + } } } + }); - theTerm()->addAction([=]{ - proxy.destroy(); - }); + if (this_node == 0) { + theCollection()->destroyCollections(); } } @@ -158,52 +162,58 @@ TEST_F(TestCallbackSendCollection, test_callback_send_collection_2) { return; } - if (this_node == 0) { - auto const& range = Index1D(32); - auto proxy = theCollection()->construct(range); - - for (auto i = 0; i < 32; i++) { - auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; - if (i % 2 == 0) { - auto cb = theCB()->makeSend(proxy(i)); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); - } else { - auto cb = theCB()->makeSend(proxy(i)); - auto msg = makeMessage(cb); - theMsg()->sendMsg(next, msg.get()); + runInEpochCollective([=] { + if (this_node == 0) { + auto const& range = Index1D(32); + auto proxy = theCollection()->construct(range); + + for (auto i = 0; i < 32; i++) { + auto next = this_node + 1 < num_nodes ? this_node + 1 : 0; + if (i % 2 == 0) { + auto cb = + theCB()->makeSend(proxy(i)); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); + } else { + auto cb = + theCB()->makeSend(proxy(i)); + auto msg = makeMessage(cb); + theMsg()->sendMsg(next, msg.get()); + } } } + }); - theTerm()->addAction([=]{ - proxy.destroy(); - }); + if (this_node == 0) { + theCollection()->destroyCollections(); } - } TEST_F(TestCallbackSendCollection, test_callback_send_collection_3) { auto const& this_node = theContext()->getNode(); - if (this_node == 0) { - auto const& range = Index1D(32); - auto proxy = theCollection()->construct(range); - - for (auto i = 0; i < 32; i++) { - if (i % 2 == 0) { - auto cb = theCB()->makeSend(proxy(i)); - auto nmsg = makeMessage(8,9,10); - cb.send(nmsg.get()); - } else { - auto cb = theCB()->makeSend(proxy(i)); - auto nmsg = makeMessage(8,9,10); - cb.send(nmsg.get()); + runInEpochCollective([=] { + if (this_node == 0) { + auto const& range = Index1D(32); + auto proxy = theCollection()->construct(range); + + for (auto i = 0; i < 32; i++) { + if (i % 2 == 0) { + auto cb = + theCB()->makeSend(proxy(i)); + auto nmsg = makeMessage(8, 9, 10); + cb.send(nmsg.get()); + } else { + auto cb = theCB()->makeSend(proxy(i)); + auto nmsg = makeMessage(8, 9, 10); + cb.send(nmsg.get()); + } } } + }); - theTerm()->addAction([=]{ - proxy.destroy(); - }); + if (this_node == 0) { + theCollection()->destroyCollections(); } } diff --git a/tests/unit/sequencer/test_sequencer.extended.cc b/tests/unit/sequencer/test_sequencer.extended.cc index 38f669b805..ce24309acf 100644 --- a/tests/unit/sequencer/test_sequencer.extended.cc +++ b/tests/unit/sequencer/test_sequencer.extended.cc @@ -158,84 +158,88 @@ struct TestSequencer : TestParallelHarness { TEST_F(TestSequencer, test_single_wait) { auto const& my_node = theContext()->getNode(); - #if DEBUG_TEST_HARNESS_PRINT - fmt::print("test_seq_handler: node={}\n", my_node); - #endif +#if DEBUG_TEST_HARNESS_PRINT + fmt::print("test_seq_handler: node={}\n", my_node); +#endif + + runInEpochCollective([=] { + if (my_node == 1) { + auto msg = makeMessage(); + theMsg()->sendMsg(0, msg.get()); + } - if (my_node == 1) { - auto msg = makeMessage(); - theMsg()->sendMsg(0, msg.get()); - } + if (my_node == 0) { - if (my_node == 0) { - SeqType const& seq_id = theSeq()->nextSeq(); - theSeq()->sequenced(seq_id, testSingleWaitFn); + SeqType const& seq_id = theSeq()->nextSeq(); + theSeq()->sequenced(seq_id, testSingleWaitFn); + } + }); - theTerm()->addAction([=]{ - testSingleWaitFn(-1); - }); + if (my_node == 0) { + testSingleWaitFn(-1); } } TEST_F(TestSequencer, test_single_wait_tagged) { auto const& my_node = theContext()->getNode(); - if (my_node == 0) { - SeqType const& seq_id = theSeq()->nextSeq(); - theSeq()->sequenced(seq_id, testSingleTaggedWaitFn); + runInEpochCollective([=] { + if (my_node == 0) { + SeqType const& seq_id = theSeq()->nextSeq(); + theSeq()->sequenced(seq_id, testSingleTaggedWaitFn); + } else if (my_node == 1) { + auto msg = makeMessage(); + theMsg()->sendMsg( + 0, msg.get(), single_tag); + } + }); - theTerm()->addAction([=]{ - testSingleTaggedWaitFn(-1); - }); - } else if (my_node == 1) { - auto msg = makeMessage(); - theMsg()->sendMsg( - 0, msg.get(), single_tag - ); + if (my_node == 0) { + testSingleTaggedWaitFn(-1); } } TEST_F(TestSequencer, test_multi_wait) { auto const& my_node = theContext()->getNode(); - if (my_node == 0) { - SeqType const& seq_id = theSeq()->nextSeq(); - theSeq()->sequenced(seq_id, testMultiWaitFn); + runInEpochCollective([=] { + if (my_node == 0) { + SeqType const& seq_id = theSeq()->nextSeq(); + theSeq()->sequenced(seq_id, testMultiWaitFn); + } else if (my_node == 1) { + auto msg1 = makeMessage(); + theMsg()->sendMsg( + 0, msg1.get()); + auto msg2 = makeMessage(); + theMsg()->sendMsg( + 0, msg2.get()); + } + }); - theTerm()->addAction([=]{ - testMultiWaitFn(-1); - }); - } else if (my_node == 1) { - auto msg1 = makeMessage(); - theMsg()->sendMsg( - 0, msg1.get() - ); - auto msg2 = makeMessage(); - theMsg()->sendMsg( - 0, msg2.get() - ); + if (my_node == 0) { + testMultiWaitFn(-1); } } TEST_F(TestSequencer, test_multi_wait_tagged) { auto const& my_node = theContext()->getNode(); - if (my_node == 0) { - SeqType const& seq_id = theSeq()->nextSeq(); - theSeq()->sequenced(seq_id, testMultiTaggedWaitFn); + runInEpochCollective([=] { + if (my_node == 0) { + SeqType const& seq_id = theSeq()->nextSeq(); + theSeq()->sequenced(seq_id, testMultiTaggedWaitFn); + } else if (my_node == 1) { + auto msg1 = makeMessage(); + theMsg()->sendMsg( + 0, msg1.get(), single_tag); + auto msg2 = makeMessage(); + theMsg()->sendMsg( + 0, msg2.get(), single_tag_2); + } + }); - theTerm()->addAction([=]{ - testMultiTaggedWaitFn(-1); - }); - } else if (my_node == 1) { - auto msg1 = makeMessage(); - theMsg()->sendMsg( - 0, msg1.get(), single_tag - ); - auto msg2 = makeMessage(); - theMsg()->sendMsg( - 0, msg2.get(), single_tag_2 - ); + if (my_node == 0) { + testMultiTaggedWaitFn(-1); } } diff --git a/tests/unit/sequencer/test_sequencer_extensive.extended.cc b/tests/unit/sequencer/test_sequencer_extensive.extended.cc index 8b26d013a7..015072716d 100644 --- a/tests/unit/sequencer/test_sequencer_extensive.extended.cc +++ b/tests/unit/sequencer/test_sequencer_extensive.extended.cc @@ -98,31 +98,33 @@ static constexpr CountType const max_seq_depth = 8; CountType const& wait_post = std::get<2>(param); \ CountType const& seg_cnt = std::get<3>(param); \ CountType const& depth = std::get<4>(param); \ - if (node == (NODE)) { \ - SeqType const& seq_id = theSeq()->nextSeq(); \ - SEQ_FN(ResetAtomicValue); \ - theSeq()->sequenced(seq_id, (SEQ_FN)); \ - theTerm()->addAction([=]{ \ - SEQ_FN(FinalizeAtomicValue); \ - }); \ - } else if (node == 1) { \ - CountType in[param_size] = { \ - wait_cnt, wait_pre, wait_post, seg_cnt, depth \ - }; \ - auto msg = makeMessage(in); \ - theMsg()->sendMsg( \ - (NODE), msg.get() \ - ); \ - auto const total = (wait_cnt * seg_cnt) + wait_pre + wait_post; \ - for (CountType i = 0; i < total; i++) { \ - TagType const tag = (IS_TAG) ? i+1 : no_tag; \ - auto nmsg = makeMessage(); \ - theMsg()->sendMsg( \ - (NODE), nmsg.get(), tag \ + runInEpochCollective([=]{ \ + if (node == (NODE)) { \ + SeqType const& seq_id = theSeq()->nextSeq(); \ + SEQ_FN(ResetAtomicValue); \ + theSeq()->sequenced(seq_id, (SEQ_FN)); \ + } else if (node == 1) { \ + CountType in[param_size] = { \ + wait_cnt, wait_pre, wait_post, seg_cnt, depth \ + }; \ + auto msg = makeMessage(in); \ + theMsg()->sendMsg( \ + (NODE), msg.get() \ ); \ + auto const total = (wait_cnt * seg_cnt) + wait_pre + wait_post; \ + for (CountType i = 0; i < total; i++) { \ + TagType const tag = (IS_TAG) ? i+1 : no_tag; \ + auto nmsg = makeMessage(); \ + theMsg()->sendMsg( \ + (NODE), nmsg.get(), tag \ + ); \ + } \ } \ + }); \ + if (node == (NODE)) { \ + SEQ_FN(FinalizeAtomicValue); \ } \ - } while (false); + } while (false); \ #define FN_APPLY(SEQ_HAN, SEQ_FN, NODE, MSG_TYPE, ___, IS_TAG) \ static void SEQ_FN(SeqType const& seq_id) { \ diff --git a/tests/unit/sequencer/test_sequencer_for.extended.cc b/tests/unit/sequencer/test_sequencer_for.extended.cc index d3360034fa..7dd75410f4 100644 --- a/tests/unit/sequencer/test_sequencer_for.extended.cc +++ b/tests/unit/sequencer/test_sequencer_for.extended.cc @@ -99,21 +99,21 @@ TEST_F(TestSequencerFor, test_for) { SeqType const& seq_id = theSeq()->nextSeq(); - if (my_node == 0) { - theSeq()->sequenced(seq_id, testSeqForFn); - } + runInEpochCollective([=] { + if (my_node == 0) { + theSeq()->sequenced(seq_id, testSeqForFn); + } - for (int i = 0; i < end_range; i++) { - if (my_node == 1) { - auto msg = makeMessage(); - theMsg()->sendMsg(0, msg.get()); + for (int i = 0; i < end_range; i++) { + if (my_node == 1) { + auto msg = makeMessage(); + theMsg()->sendMsg(0, msg.get()); + } } - } + }); if (my_node == 0) { - theTerm()->addAction([=]{ - testSeqForFn(-1); - }); + testSeqForFn(-1); } } diff --git a/tests/unit/sequencer/test_sequencer_nested.extended.cc b/tests/unit/sequencer/test_sequencer_nested.extended.cc index 1402603096..0313a37506 100644 --- a/tests/unit/sequencer/test_sequencer_nested.extended.cc +++ b/tests/unit/sequencer/test_sequencer_nested.extended.cc @@ -264,22 +264,23 @@ struct TestSequencerNested : TestParallelHarness { #define SEQ_EXPAND(SEQ_HAN, SEQ_FN, NODE, MSG_TYPE, NUM_MSGS, IS_TAG) \ do { \ SeqType const& seq_id = theSeq()->nextSeq(); \ - if ((NODE) == 0) { \ - theSeq()->sequenced(seq_id, (SEQ_FN)); \ - } \ - for (int i = 0; i < (NUM_MSGS); i++) { \ - TagType const tag = (IS_TAG) ? i+1 : no_tag; \ - if ((NODE) == 1) { \ - auto msg = makeMessage(); \ - theMsg()->sendMsg( \ - 0, msg.get(), tag \ - ); \ + \ + runInEpochCollective([=]{ \ + if ((NODE) == 0) { \ + theSeq()->sequenced(seq_id, (SEQ_FN)); \ } \ - } \ + for (int i = 0; i < (NUM_MSGS); i++) { \ + TagType const tag = (IS_TAG) ? i+1 : no_tag; \ + if ((NODE) == 1) { \ + auto msg = makeMessage(); \ + theMsg()->sendMsg( \ + 0, msg.get(), tag \ + ); \ + } \ + } \ + }); \ if ((NODE) == 0) { \ - theTerm()->addAction([=]{ \ SEQ_FN(-1); \ - }); \ } \ } while (false); diff --git a/tests/unit/sequencer/test_sequencer_parallel.extended.cc b/tests/unit/sequencer/test_sequencer_parallel.extended.cc index 9669ad9630..1f69382324 100644 --- a/tests/unit/sequencer/test_sequencer_parallel.extended.cc +++ b/tests/unit/sequencer/test_sequencer_parallel.extended.cc @@ -149,24 +149,23 @@ TEST_P(TestSequencerParallelParam, test_seq_parallel_param) { SeqType const& seq_id = theSeq()->nextSeq(); auto seq_par_cnt_fn = std::bind(seqParFnN, _1, par_count); - if (node == 0) { - seq_par_cnt_fn(SeqParResetAtomicValue); - theSeq()->sequenced(seq_id, seq_par_cnt_fn); - } + runInEpochCollective([=] { + if (node == 0) { + seq_par_cnt_fn(SeqParResetAtomicValue); + theSeq()->sequenced(seq_id, seq_par_cnt_fn); + } - for (CountType i = 0; i < par_count; i++) { - if (node == 1) { - auto msg = makeMessage(); - theMsg()->sendMsg(0, msg.get()); + for (CountType i = 0; i < par_count; i++) { + if (node == 1) { + auto msg = makeMessage(); + theMsg()->sendMsg(0, msg.get()); + } } - } + }); if (node == 0) { - theTerm()->addAction([=]{ - seq_par_cnt_fn(SeqParFinalizeAtomicValue); - }); + seq_par_cnt_fn(SeqParFinalizeAtomicValue); } - } INSTANTIATE_TEST_SUITE_P( @@ -317,22 +316,22 @@ struct TestSequencerParallel : TestParallelHarness { #define PAR_EXPAND(SEQ_HAN, SEQ_FN, NODE, MSG_TYPE, NUM_MSGS, IS_TAG) \ do { \ SeqType const& seq_id = theSeq()->nextSeq(); \ - if ((NODE) == 0) { \ - theSeq()->sequenced(seq_id, (SEQ_FN)); \ - } \ - for (int i = 0; i < (NUM_MSGS); i++) { \ - TagType const tag = (IS_TAG) ? i+1 : no_tag; \ - if ((NODE) == 1) { \ - auto msg = makeMessage(); \ - theMsg()->sendMsg( \ - 0, msg.get(), tag \ - ); \ + runInEpochCollective([=]{ \ + if ((NODE) == 0) { \ + theSeq()->sequenced(seq_id, (SEQ_FN)); \ } \ - } \ + for (int i = 0; i < (NUM_MSGS); i++) { \ + TagType const tag = (IS_TAG) ? i+1 : no_tag; \ + if ((NODE) == 1) { \ + auto msg = makeMessage(); \ + theMsg()->sendMsg( \ + 0, msg.get(), tag \ + ); \ + } \ + } \ + }); \ if ((NODE) == 0) { \ - theTerm()->addAction([=]{ \ SEQ_FN(-1); \ - }); \ } \ } while (false); diff --git a/tests/unit/sequencer/test_sequencer_vrt.extended.cc b/tests/unit/sequencer/test_sequencer_vrt.extended.cc index 8237080bc3..8627fbe468 100644 --- a/tests/unit/sequencer/test_sequencer_vrt.extended.cc +++ b/tests/unit/sequencer/test_sequencer_vrt.extended.cc @@ -182,85 +182,84 @@ struct TestSequencerVirtual : TestParallelHarness { TEST_F(TestSequencerVirtual, test_seq_vc_1) { auto const& my_node = theContext()->getNode(); - if (my_node == 0) { - auto proxy = theVirtualManager()->makeVirtual(29); - SeqType const& seq_id = theVirtualSeq()->createVirtualSeq(proxy); - auto vrt_ptr = theVirtualManager()->getVirtualByProxy(proxy); + runInEpochCollective([=] { + if (my_node == 0) { + auto proxy = theVirtualManager()->makeVirtual(29); + SeqType const& seq_id = theVirtualSeq()->createVirtualSeq(proxy); + auto vrt_ptr = theVirtualManager()->getVirtualByProxy(proxy); - test_vrt_ptr = static_cast(vrt_ptr); - //fmt::print("vrt ptr={}\n", test_vrt_ptr); + test_vrt_ptr = static_cast(vrt_ptr); + // fmt::print("vrt ptr={}\n", test_vrt_ptr); - theVirtualSeq()->sequenced(seq_id, testSeqFn1); + theVirtualSeq()->sequenced(seq_id, testSeqFn1); - auto msg = makeMessage(); - theVirtualManager()->sendMsg( - proxy, msg.get() - ); + auto msg = makeMessage(); + theVirtualManager()->sendMsg( + proxy, msg.get()); + } + }); - theTerm()->addAction([=]{ - testSeqFn1(FinalizeAtomicValue); - }); + if (my_node == 0) { + testSeqFn1(FinalizeAtomicValue); } } TEST_F(TestSequencerVirtual, test_seq_vc_2) { auto const& my_node = theContext()->getNode(); - if (my_node == 0) { - auto proxy = theVirtualManager()->makeVirtual(85); - SeqType const& seq_id = theVirtualSeq()->createVirtualSeq(proxy); - auto vrt_ptr = theVirtualManager()->getVirtualByProxy(proxy); + runInEpochCollective([=] { + if (my_node == 0) { + auto proxy = theVirtualManager()->makeVirtual(85); + SeqType const& seq_id = theVirtualSeq()->createVirtualSeq(proxy); + auto vrt_ptr = theVirtualManager()->getVirtualByProxy(proxy); - test_vrt_ptr = static_cast(vrt_ptr); + test_vrt_ptr = static_cast(vrt_ptr); - theVirtualSeq()->sequenced(seq_id, testSeqFn2); + theVirtualSeq()->sequenced(seq_id, testSeqFn2); - for (int i = 0; i < 2; i++) { - auto msg = makeMessage(); - theVirtualManager()->sendMsg( - proxy, msg.get() - ); + for (int i = 0; i < 2; i++) { + auto msg = makeMessage(); + theVirtualManager()->sendMsg( + proxy, msg.get()); + } } + }); - theTerm()->addAction([=]{ - testSeqFn2(FinalizeAtomicValue); - }); + if (my_node == 0) { + testSeqFn2(FinalizeAtomicValue); } } TEST_F(TestSequencerVirtual, test_seq_vc_distinct_inst_3) { auto const& my_node = theContext()->getNode(); + runInEpochCollective([=] { + if (my_node == 0) { + auto proxy_a = theVirtualManager()->makeVirtual(85); + SeqType const& seq_id_a = theVirtualSeq()->createVirtualSeq(proxy_a); + auto vrt_ptr_a = theVirtualManager()->getVirtualByProxy(proxy_a); + test_vrt_ptr_a = static_cast(vrt_ptr_a); + + auto proxy_b = theVirtualManager()->makeVirtual(23); + SeqType const& seq_id_b = theVirtualSeq()->createVirtualSeq(proxy_b); + auto vrt_ptr_b = theVirtualManager()->getVirtualByProxy(proxy_b); + test_vrt_ptr_b = static_cast(vrt_ptr_b); + + theVirtualSeq()->sequenced(seq_id_a, testSeqFn3a); + theVirtualSeq()->sequenced(seq_id_b, testSeqFn3b); + + auto msg1 = makeMessage(); + theVirtualManager()->sendMsg( + proxy_a, msg1.get()); + auto msg2 = makeMessage(); + theVirtualManager()->sendMsg( + proxy_b, msg2.get()); + } + }); + if (my_node == 0) { - auto proxy_a = theVirtualManager()->makeVirtual(85); - SeqType const& seq_id_a = theVirtualSeq()->createVirtualSeq(proxy_a); - auto vrt_ptr_a = theVirtualManager()->getVirtualByProxy(proxy_a); - test_vrt_ptr_a = static_cast(vrt_ptr_a); - - auto proxy_b = theVirtualManager()->makeVirtual(23); - SeqType const& seq_id_b = theVirtualSeq()->createVirtualSeq(proxy_b); - auto vrt_ptr_b = theVirtualManager()->getVirtualByProxy(proxy_b); - test_vrt_ptr_b = static_cast(vrt_ptr_b); - - theVirtualSeq()->sequenced(seq_id_a, testSeqFn3a); - theVirtualSeq()->sequenced(seq_id_b, testSeqFn3b); - - auto msg1 = makeMessage(); - theVirtualManager()->sendMsg( - proxy_a, msg1.get() - ); - auto msg2 = makeMessage(); - theVirtualManager()->sendMsg( - proxy_b, msg2.get() - ); - - // @todo: fix this it is getting triggered early (a termination detector - // bug?) - theTerm()->addAction([=]{ - // testSeqFn3a(FinalizeAtomicValue); - // testSeqFn3b(FinalizeAtomicValue); - }); + testSeqFn3a(FinalizeAtomicValue); + testSeqFn3b(FinalizeAtomicValue); } } - }}} // end namespace vt::tests::unit