Skip to content

Commit de81713

Browse files
karzhenkovandreasbuhr
authored andcommitted
Check maximum depth of nested continuations
1 parent 988df1d commit de81713

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/async_auto_reset_event_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ TEST_CASE("multi-threaded")
9191
{
9292
cppcoro::static_thread_pool tp{ 3 };
9393

94+
unsigned max_depth = 0;
95+
9496
auto run = [&]() -> cppcoro::task<>
9597
{
9698
cppcoro::async_auto_reset_event event;
@@ -102,7 +104,13 @@ TEST_CASE("multi-threaded")
102104
co_await tp.schedule();
103105
co_await event;
104106
++value;
107+
108+
thread_local unsigned depth = 0;
109+
if (depth > max_depth) max_depth = depth;
110+
111+
depth += 1;
105112
event.set();
113+
depth -= 1;
106114
};
107115

108116
auto startSignaller = [&]() -> cppcoro::task<>
@@ -135,6 +143,8 @@ TEST_CASE("multi-threaded")
135143
}
136144

137145
cppcoro::sync_wait(cppcoro::when_all(std::move(tasks)));
146+
147+
CHECK_MESSAGE(max_depth < 500, "Maximum depth of nested continuations exceeded");
138148
}
139149

140150
TEST_SUITE_END();

0 commit comments

Comments
 (0)