Port some tests to use static_thread_pool instead of io_service.
This should allow them to be run under Linux/Clang.
This commit is contained in:
parent
1451ad0f73
commit
ed172f6941
|
@ -11,11 +11,7 @@
|
|||
#include <cppcoro/when_all.hpp>
|
||||
#include <cppcoro/when_all_ready.hpp>
|
||||
#include <cppcoro/on_scope_exit.hpp>
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
# include <cppcoro/io_service.hpp>
|
||||
# include "io_service_fixture.hpp"
|
||||
#endif
|
||||
#include <cppcoro/static_thread_pool.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
@ -91,10 +87,10 @@ TEST_CASE("multiple waiters")
|
|||
check()));
|
||||
}
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
|
||||
TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
||||
TEST_CASE("multi-threaded")
|
||||
{
|
||||
cppcoro::static_thread_pool tp{ 3 };
|
||||
|
||||
auto run = [&]() -> cppcoro::task<>
|
||||
{
|
||||
cppcoro::async_auto_reset_event event;
|
||||
|
@ -103,7 +99,7 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
|||
|
||||
auto startWaiter = [&]() -> cppcoro::task<>
|
||||
{
|
||||
co_await io_service().schedule();
|
||||
co_await tp.schedule();
|
||||
co_await event;
|
||||
++value;
|
||||
event.set();
|
||||
|
@ -111,7 +107,7 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
|||
|
||||
auto startSignaller = [&]() -> cppcoro::task<>
|
||||
{
|
||||
co_await io_service().schedule();
|
||||
co_await tp.schedule();
|
||||
value = 5;
|
||||
event.set();
|
||||
};
|
||||
|
@ -141,6 +137,4 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
|||
cppcoro::sync_wait(cppcoro::when_all(std::move(tasks)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
|
@ -11,11 +11,7 @@
|
|||
#include <cppcoro/when_all.hpp>
|
||||
#include <cppcoro/when_all_ready.hpp>
|
||||
#include <cppcoro/on_scope_exit.hpp>
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
# include <cppcoro/io_service.hpp>
|
||||
# include "io_service_fixture.hpp"
|
||||
#endif
|
||||
#include <cppcoro/static_thread_pool.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
@ -53,10 +49,10 @@ TEST_CASE("single waiter")
|
|||
cppcoro::sync_wait(cppcoro::when_all_ready(run(), check()));
|
||||
}
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
|
||||
TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
||||
TEST_CASE("multi-threaded")
|
||||
{
|
||||
cppcoro::static_thread_pool tp;
|
||||
|
||||
cppcoro::sync_wait([&]() -> cppcoro::task<>
|
||||
{
|
||||
cppcoro::single_consumer_async_auto_reset_event valueChangedEvent;
|
||||
|
@ -75,7 +71,7 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
|||
|
||||
auto modifier = [&](int count) -> cppcoro::task<int>
|
||||
{
|
||||
co_await io_service().schedule();
|
||||
co_await tp.schedule();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
value.fetch_add(1, std::memory_order_relaxed);
|
||||
|
@ -94,6 +90,4 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<3>, "multi-threaded")
|
|||
}());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
|
@ -9,11 +9,7 @@
|
|||
#include <cppcoro/task.hpp>
|
||||
#include <cppcoro/shared_task.hpp>
|
||||
#include <cppcoro/on_scope_exit.hpp>
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
# include <cppcoro/io_service.hpp>
|
||||
# include "io_service_fixture.hpp"
|
||||
#endif
|
||||
#include <cppcoro/static_thread_pool.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
@ -55,20 +51,19 @@ TEST_CASE("sync_wait(shared_task<T>)")
|
|||
CHECK(cppcoro::sync_wait(makeTask()) == "foo");
|
||||
}
|
||||
|
||||
#if CPPCORO_OS_WINNT
|
||||
|
||||
TEST_CASE_FIXTURE(io_service_fixture_with_threads<1>, "multiple threads")
|
||||
TEST_CASE("multiple threads")
|
||||
{
|
||||
// We are creating a new task and starting it inside the sync_wait().
|
||||
// The task will reschedule itself for resumption on an I/O thread
|
||||
// The task will reschedule itself for resumption on a thread-pool thread
|
||||
// which will sometimes complete before this thread calls event.wait()
|
||||
// inside sync_wait(). Thus we're roughly testing the thread-safety of
|
||||
// sync_wait().
|
||||
cppcoro::static_thread_pool tp{ 1 };
|
||||
|
||||
int value = 0;
|
||||
auto createLazyTask = [&]() -> cppcoro::task<int>
|
||||
{
|
||||
co_await io_service().schedule();
|
||||
co_await tp.schedule();
|
||||
co_return value++;
|
||||
};
|
||||
|
||||
|
@ -78,6 +73,4 @@ TEST_CASE_FIXTURE(io_service_fixture_with_threads<1>, "multiple threads")
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
|
Loading…
Reference in a new issue