From b175e693e0da21c90c63ad477637fe7c901e5eac Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 10 Jan 2021 17:16:23 +0500 Subject: [PATCH 1/5] Check maximum depth of nested continuations --- test/async_auto_reset_event_tests.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/async_auto_reset_event_tests.cpp b/test/async_auto_reset_event_tests.cpp index 32cdb42b..1c95b274 100644 --- a/test/async_auto_reset_event_tests.cpp +++ b/test/async_auto_reset_event_tests.cpp @@ -91,6 +91,8 @@ TEST_CASE("multi-threaded") { cppcoro::static_thread_pool tp{ 3 }; + unsigned max_depth = 0; + auto run = [&]() -> cppcoro::task<> { cppcoro::async_auto_reset_event event; @@ -102,7 +104,13 @@ TEST_CASE("multi-threaded") co_await tp.schedule(); co_await event; ++value; + + thread_local unsigned depth = 0; + if (depth > max_depth) max_depth = depth; + + depth += 1; event.set(); + depth -= 1; }; auto startSignaller = [&]() -> cppcoro::task<> @@ -135,6 +143,8 @@ TEST_CASE("multi-threaded") } cppcoro::sync_wait(cppcoro::when_all(std::move(tasks))); + + CHECK_MESSAGE(max_depth < 500, "Maximum depth of nested continuations exceeded"); } TEST_SUITE_END(); From b43d6b1e808e70cc20deeee0aca9cb54f71b658f Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 10 Jan 2021 23:32:02 +0500 Subject: [PATCH 2/5] Reduce allowed depth of nested continuations to zero --- test/async_auto_reset_event_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/async_auto_reset_event_tests.cpp b/test/async_auto_reset_event_tests.cpp index 1c95b274..38549986 100644 --- a/test/async_auto_reset_event_tests.cpp +++ b/test/async_auto_reset_event_tests.cpp @@ -144,7 +144,7 @@ TEST_CASE("multi-threaded") cppcoro::sync_wait(cppcoro::when_all(std::move(tasks))); - CHECK_MESSAGE(max_depth < 500, "Maximum depth of nested continuations exceeded"); + CHECK_MESSAGE(max_depth == 0, "Nested continuations detected"); } TEST_SUITE_END(); From 01fbc06ce3ce14e72a112737e33fccc448790303 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sun, 10 Jan 2021 23:59:54 +0500 Subject: [PATCH 3/5] Try a workaround to prevent nested continuations --- test/async_auto_reset_event_tests.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/async_auto_reset_event_tests.cpp b/test/async_auto_reset_event_tests.cpp index 38549986..cf8fe775 100644 --- a/test/async_auto_reset_event_tests.cpp +++ b/test/async_auto_reset_event_tests.cpp @@ -91,8 +91,6 @@ TEST_CASE("multi-threaded") { cppcoro::static_thread_pool tp{ 3 }; - unsigned max_depth = 0; - auto run = [&]() -> cppcoro::task<> { cppcoro::async_auto_reset_event event; @@ -105,12 +103,18 @@ TEST_CASE("multi-threaded") co_await event; ++value; - thread_local unsigned depth = 0; - if (depth > max_depth) max_depth = depth; + thread_local volatile bool nested = false; + + if (nested) + { + co_await tp.schedule(); + assert(!nested); + } + + nested = true; + cppcoro::scoped_lambda cleanup = [] { nested = false; }; - depth += 1; event.set(); - depth -= 1; }; auto startSignaller = [&]() -> cppcoro::task<> @@ -143,8 +147,6 @@ TEST_CASE("multi-threaded") } cppcoro::sync_wait(cppcoro::when_all(std::move(tasks))); - - CHECK_MESSAGE(max_depth == 0, "Nested continuations detected"); } TEST_SUITE_END(); From 9954e490c24576d20739b0a4bd0a1a0d5f57361d Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Mon, 11 Jan 2021 20:42:41 +0500 Subject: [PATCH 4/5] Run selected test using verbose mode --- .github/workflows/cmake.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4f571745..18c10223 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -191,4 +191,6 @@ jobs: shell: bash # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --output-on-failure -C $BUILD_TYPE + run: | + ctest --output-on-failure -C $BUILD_TYPE && \ + ctest -V -R '^async auto reset event tests-multi-threaded$' From 2e83b235fde544e269190d655b3c87895d61a5b8 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Mon, 11 Jan 2021 22:29:07 +0500 Subject: [PATCH 5/5] Adjust timeout --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f5afecd1..a67428d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,7 +47,7 @@ if(WIN32) ) else() # let more time for some tests - set(async_auto_reset_event_tests_TIMEOUT 60) + set(async_auto_reset_event_tests_TIMEOUT 200) endif() foreach(test ${tests})