feat add thread_pool test case
This commit is contained in:
parent
a711d6bfb4
commit
9444c23db2
@ -1,4 +1,5 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
#include <sled/synchronization/event.h>
|
||||||
#include <sled/system/thread_pool.h>
|
#include <sled/system/thread_pool.h>
|
||||||
|
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
@ -37,8 +38,10 @@ multiply_return(const int a, const int b)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("ThreadPool")
|
TEST_SUITE("ThreadPool")
|
||||||
{
|
{
|
||||||
|
TEST_CASE("submit")
|
||||||
|
{
|
||||||
sled::ThreadPool *tp = new sled::ThreadPool();
|
sled::ThreadPool *tp = new sled::ThreadPool();
|
||||||
REQUIRE_NE(tp, nullptr);
|
REQUIRE_NE(tp, nullptr);
|
||||||
|
|
||||||
@ -59,4 +62,23 @@ TEST_CASE("ThreadPool")
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete tp;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user