Skip to content

Commit

Permalink
Merge pull request #23 from yqm-307/fix-coroutine-test
Browse files Browse the repository at this point in the history
优化Coroutine单元测试 新增失败点判断
  • Loading branch information
yqm-307 authored Jul 8, 2024
2 parents f3d9fdc + 5af3cde commit e829f75
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions unit_test/Test_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ BOOST_AUTO_TEST_SUITE(CoroutineTest)

BOOST_AUTO_TEST_CASE(t_coroutine_run)
{
std::atomic_int ncount = 0;

std::atomic_int sign_value = 0;


current_coroutine = bbt::coroutine::detail::Coroutine::Create(4096,
[](){
printf("start\n");
printf("coroutine point 1\n");
current_coroutine->Yield();
printf("coroutine point 2\n");
current_coroutine->Yield();
printf("coroutine point 3\n");
[&sign_value,&ncount](){
for (int i = 0; i < 10000; ++i)
{
BOOST_CHECK_EQUAL(sign_value, 1);
sign_value--;
ncount++;
current_coroutine->Yield();
}

});
for (int i = 0; i < 10000; ++i)
{
BOOST_CHECK_EQUAL(sign_value, 0);
sign_value++;
ncount++;
current_coroutine->Resume();
}

BOOST_CHECK_EQUAL(ncount, 20000);

printf("main point 1\n");
current_coroutine->Resume();
printf("main point 2\n");
current_coroutine->Resume();
printf("main point 3\n");
current_coroutine->Resume();

}

Expand Down

0 comments on commit e829f75

Please sign in to comment.