Skip to content

Commit 512c546

Browse files
authored
Merge pull request #1584 from ericniebler/fix-repeat-tests
Catch2 assertions are not thread-safe!
2 parents 2c51979 + db3045d commit 512c546

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

test/exec/test_repeat_effect_until.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,22 @@ namespace {
161161

162162
REQUIRE(called);
163163
}
164+
165+
TEST_CASE("repeat_effect_until works with bulk on a static_thread_pool", "[adaptors][repeat_n]") {
166+
exec::static_thread_pool pool{2};
167+
std::atomic<bool> failed{false};
168+
const auto tid = std::this_thread::get_id();
169+
bool called{false};
170+
ex::sender auto snd = stdexec::on(
171+
pool.get_scheduler(), ex::just() | ex::bulk(ex::par_unseq, 1024, [&](int index) noexcept {
172+
if (tid == std::this_thread::get_id()) {
173+
failed = true;
174+
}
175+
}) | ex::then([&] {
176+
called = true;
177+
return called;
178+
}) | exec::repeat_effect_until());
179+
stdexec::sync_wait(std::move(snd));
180+
REQUIRE(called);
181+
}
164182
} // namespace

test/exec/test_repeat_n.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,28 @@ namespace {
124124
TEST_CASE("repeat_n works when changing threads", "[adaptors][repeat_n]") {
125125
exec::static_thread_pool pool{2};
126126
bool called{false};
127-
sender auto snd = stdexec::on(pool.get_scheduler(), ex::just() | ex::then([&] {
128-
called = true;
129-
}) | exec::repeat_n(10));
130-
stdexec::sync_wait(std::move(snd));
127+
sender auto snd = ex::on(pool.get_scheduler(), ex::just() | ex::then([&] {
128+
called = true;
129+
}) | exec::repeat_n(10));
130+
ex::sync_wait(std::move(snd));
131+
REQUIRE(called);
132+
}
133+
134+
TEST_CASE("repeat_n works with bulk on a static_thread_pool", "[adaptors][repeat_n]") {
135+
exec::static_thread_pool pool{2};
136+
std::atomic<bool> failed{false};
137+
const auto tid = std::this_thread::get_id();
138+
bool called{false};
139+
sender auto snd =
140+
ex::on(pool.get_scheduler(), ex::just() | ex::bulk(ex::par_unseq, 1024, [&](int) noexcept {
141+
if (tid == std::this_thread::get_id()) {
142+
failed = true;
143+
}
144+
}) | ex::then([&] {
145+
called = true;
146+
}) | exec::repeat_n(10));
147+
ex::sync_wait(std::move(snd));
131148
REQUIRE(called);
149+
REQUIRE(!failed.load());
132150
}
133151
} // namespace

0 commit comments

Comments
 (0)