From aa77548bd637ffd1a7461136e6206906dc4c61c7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 11:54:45 +0100 Subject: New WorkItem/job/promise/future based interface --- test/test-worker.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test-worker.cpp b/test/test-worker.cpp index 3c5ed7e..c542020 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -2,6 +2,43 @@ #include "testHelpers.h" #include +#include #include +#include -BOOST_AUTO_TEST_CASE(exists) { } +uint32_t +workCounter() +{ + static std::atomic_uint32_t n; + usleep(1000); + return n++; +} + +BOOST_AUTO_TEST_CASE(basic_slow_counter) +{ + std::vector> ps; + for (int i {}; i < 30; ++i) { + ps.push_back(Worker::addWork(workCounter)); + } + std::set out; + std::transform(ps.begin(), ps.end(), std::inserter(out, out.end()), [](auto && p) { + return p->get(); + }); + BOOST_REQUIRE_EQUAL(out.size(), ps.size()); + BOOST_CHECK_EQUAL(*out.begin(), 0); + BOOST_CHECK_EQUAL(*out.rbegin(), ps.size() - 1); +} + +BOOST_AUTO_TEST_CASE(basic_error_handler) +{ + auto workitem = Worker::addWork([]() { + throw std::runtime_error {"test"}; + }); + BOOST_CHECK_THROW(workitem->get(), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(basic_void_work) +{ + auto workitem = Worker::addWork([]() {}); + BOOST_CHECK_NO_THROW(workitem->get()); +} -- cgit v1.2.3