2023-12-18 08:37:25 +01:00
|
|
|
#include "EngineTest.h"
|
|
|
|
|
#include "ThreadPool.h"
|
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
|
|
TEST(ThreadPool, RunBatch)
|
|
|
|
|
{
|
|
|
|
|
ThreadPool t(10);
|
|
|
|
|
uint32 test = 20;
|
|
|
|
|
std::mutex m;
|
2023-12-18 13:03:03 +01:00
|
|
|
List<std::function<void()>> work;
|
2023-12-18 08:37:25 +01:00
|
|
|
for (uint32 i = 0; i < 400; ++i)
|
|
|
|
|
{
|
2023-12-18 13:03:03 +01:00
|
|
|
work.add([&]() {
|
2023-12-18 08:37:25 +01:00
|
|
|
std::unique_lock l(m);
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
test++;
|
2023-12-18 13:03:03 +01:00
|
|
|
});
|
2023-12-18 08:37:25 +01:00
|
|
|
}
|
|
|
|
|
t.runAndWait(std::move(work));
|
|
|
|
|
ASSERT_EQ(test, 420);
|
|
|
|
|
}
|