Skip to content

Commit

Permalink
Clean up other error_sender test facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
aurianer committed Jul 13, 2022
1 parent e42124f commit 97e3897
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 56 deletions.
50 changes: 2 additions & 48 deletions libs/pika/execution/tests/include/algorithm_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ struct void_sender
}
};

template <typename... Ts>
template <typename...>
struct error_sender
{
template <template <typename...> class Tuple,
template <typename...> class Variant>
using value_types = Variant<Tuple<Ts...>>;
using value_types = Variant<Tuple<>>;

template <template <typename...> class Variant>
using error_types = Variant<std::exception_ptr>;
Expand All @@ -66,7 +66,6 @@ struct error_sender

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_value_t(),
pika::execution::experimental::set_error_t(std::exception_ptr)>;

template <typename R>
Expand Down Expand Up @@ -223,51 +222,6 @@ struct void_callback_helper
}
};

template <typename T>
struct error_typed_sender
{
template <template <class...> class Tuple,
template <class...> class Variant>
using value_types = Variant<Tuple<T>>;

template <template <class...> class Variant>
using error_types = Variant<std::exception_ptr>;

static constexpr bool sends_done = false;

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_value_t(T),
pika::execution::experimental::set_error_t(std::exception_ptr)>;

template <typename R>
struct operation_state
{
std::decay_t<R> r;

friend void tag_invoke(pika::execution::experimental::start_t,
operation_state& os) noexcept
{
try
{
throw std::runtime_error("error");
}
catch (...)
{
pika::execution::experimental::set_error(
std::move(os.r), std::current_exception());
}
};
};

template <typename R>
friend auto tag_invoke(
pika::execution::experimental::connect_t, error_typed_sender, R&& r)
{
return operation_state<R>{std::forward<R>(r)};
}
};

void check_exception_ptr(std::exception_ptr eptr)
{
try
Expand Down
6 changes: 3 additions & 3 deletions libs/pika/execution/tests/unit/algorithm_when_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main()
// Failure path
{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(error_typed_sender<double>{});
auto s = ex::when_all(error_sender<double>{});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -210,7 +210,7 @@ int main()

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(ex::just(42), error_typed_sender<double>{});
auto s = ex::when_all(ex::just(42), error_sender<double>{});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -220,7 +220,7 @@ int main()

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(error_typed_sender<double>{}, ex::just(42));
auto s = ex::when_all(error_sender<double>{}, ex::just(42));
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand Down
10 changes: 5 additions & 5 deletions libs/pika/execution/tests/unit/algorithm_when_all_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int main()
// Failure path
{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all_vector(std::vector{error_typed_sender<double>{}});
auto s = ex::when_all_vector(std::vector{error_sender<double>{}});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -264,7 +264,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::unique_any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -279,7 +279,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::unique_any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -294,7 +294,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -309,7 +309,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand Down

0 comments on commit 97e3897

Please sign in to comment.