Skip to content

Commit

Permalink
#955 Clear out uses of addAction in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Aug 11, 2020
1 parent 31dcbe9 commit 12cf645
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 293 deletions.
16 changes: 9 additions & 7 deletions tests/unit/pipe/test_callback_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, test_handler>(1, msg.get());
runInEpochCollective([=] {
if (this_node == 0) {
auto cb = theCB()->makeFunc([] { called = 400; });
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, test_handler>(1, msg.get());
}
});

theTerm()->addAction([=]{
EXPECT_EQ(called, 400);
});
if (this_node == 0) {
EXPECT_EQ(called, 400);
}
}

Expand Down
41 changes: 20 additions & 21 deletions tests/unit/pipe/test_callback_func_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,27 @@ TEST_F(TestCallbackFuncCtx, test_callback_func_ctx_2) {
return;
}

ctx = std::make_unique<Context>();
ctx->val = this_node;

auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeFunc<DataMsg,Context>(
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<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, test_handler>(next, msg.get());

theTerm()->addAction([=]{
//fmt::print("{}: called={}\n", this_node, called);
EXPECT_EQ(called, 500);
runInEpochCollective([=] {
ctx = std::make_unique<Context>();
ctx->val = this_node;

auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeFunc<DataMsg, Context>(
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<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, test_handler>(next, msg.get());
});

// fmt::print("{}: called={}\n", this_node, called);
EXPECT_EQ(called, 500);
}

}}} // end namespace vt::tests::unit
70 changes: 38 additions & 32 deletions tests/unit/pipe/test_callback_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,81 +114,87 @@ TEST_F(TestCallbackSend, test_callback_send_1) {
auto const& this_node = theContext()->getNode();

called = 0;
auto cb = theCB()->makeSend<DataMsg,callbackFn>(this_node);
auto nmsg = makeMessage<DataMsg>(1,2,3);
cb.send(nmsg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 100);
runInEpochCollective([=] {
auto cb = theCB()->makeSend<DataMsg, callbackFn>(this_node);
auto nmsg = makeMessage<DataMsg>(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<CallbackFunctor>(this_node);
auto nmsg = makeMessage<DataMsg>(1,2,3);
cb.send(nmsg.get());

theTerm()->addAction([=]{
EXPECT_EQ(called, 200);
runInEpochCollective([=] {
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto nmsg = makeMessage<DataMsg>(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<CallbackFunctorEmpty>(this_node);
cb.send();

theTerm()->addAction([=]{
EXPECT_EQ(called, 300);
runInEpochCollective([=] {
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
cb.send();
});

EXPECT_EQ(called, 300);
}

TEST_F(TestCallbackSend, test_callback_send_remote_1) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<DataMsg,callbackFn>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(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<DataMsg, callbackFn>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
});

EXPECT_EQ(called, 100);
}

TEST_F(TestCallbackSend, test_callback_send_remote_2) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctor>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(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<CallbackFunctor>(this_node);
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
});

EXPECT_EQ(called, 200);
}

TEST_F(TestCallbackSend, test_callback_send_remote_3) {
auto const& this_node = theContext()->getNode();
auto const& num_nodes = theContext()->getNumNodes();

called = 0;
auto next = this_node + 1 < num_nodes ? this_node + 1 : 0;
auto cb = theCB()->makeSend<CallbackFunctorEmpty>(this_node);
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, testHandlerEmpty>(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<CallbackFunctorEmpty>(this_node);
auto msg = makeMessage<CallbackMsg>(cb);
theMsg()->sendMsg<CallbackMsg, testHandlerEmpty>(next, msg.get());
});

EXPECT_EQ(called, 300);
}


Expand Down
110 changes: 60 additions & 50 deletions tests/unit/pipe/test_callback_send_collection.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb2>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
runInEpochCollective([=] {
if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
} else {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb2>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
}
}
}
});

theTerm()->addAction([=]{
proxy.destroy();
});
if (this_node == 0) {
theCollection()->destroyCollections();
}
}

Expand All @@ -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<TestCol>(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<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb2>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
runInEpochCollective([=] {
if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(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<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(next, msg.get());
} else {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb2>(proxy(i));
auto msg = makeMessage<CallbackDataMsg>(cb);
theMsg()->sendMsg<CallbackDataMsg, testHandler>(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<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb = theCB()->makeSend<TestCol,DataMsg,&TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol,DataMsg,cb3>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8,9,10);
cb.send(nmsg.get());
runInEpochCollective([=] {
if (this_node == 0) {
auto const& range = Index1D(32);
auto proxy = theCollection()->construct<TestCol>(range);

for (auto i = 0; i < 32; i++) {
if (i % 2 == 0) {
auto cb =
theCB()->makeSend<TestCol, DataMsg, &TestCol::cb1>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
} else {
auto cb = theCB()->makeSend<TestCol, DataMsg, cb3>(proxy(i));
auto nmsg = makeMessage<DataMsg>(8, 9, 10);
cb.send(nmsg.get());
}
}
}
});

theTerm()->addAction([=]{
proxy.destroy();
});
if (this_node == 0) {
theCollection()->destroyCollections();
}
}

Expand Down
Loading

0 comments on commit 12cf645

Please sign in to comment.