feat add thread_pool test case
Some checks failed
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 2m22s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 1m24s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 1m21s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 4m3s

This commit is contained in:
tqcq 2024-03-31 22:16:53 +08:00
parent a711d6bfb4
commit 9444c23db2
2 changed files with 38 additions and 16 deletions

View File

@ -1,4 +1,5 @@
#include <random>
#include <sled/synchronization/event.h>
#include <sled/system/thread_pool.h>
std::random_device rd;
@ -37,8 +38,10 @@ multiply_return(const int a, const int b)
return res;
}
TEST_CASE("ThreadPool")
TEST_SUITE("ThreadPool")
{
TEST_CASE("submit")
{
sled::ThreadPool *tp = new sled::ThreadPool();
REQUIRE_NE(tp, nullptr);
@ -59,4 +62,23 @@ TEST_CASE("ThreadPool")
}
delete tp;
}
TEST_CASE("PostTask")
{
sled::ThreadPool *tp = new sled::ThreadPool();
sled::Event waiter;
tp->PostTask([&]() { waiter.Set(); });
CHECK(waiter.Wait(sled::TimeDelta::Seconds(1)));
delete tp;
}
TEST_CASE("PostDelayedTask")
{
sled::ThreadPool *tp = new sled::ThreadPool();
sled::Event waiter;
tp->PostDelayedTask([&]() { waiter.Set(); }, sled::TimeDelta::Millis(100));
CHECK_FALSE(waiter.Wait(sled::TimeDelta::Millis(50)));
CHECK(waiter.Wait(sled::TimeDelta::Millis(150)));
delete tp;
}
}