Merge remote-tracking branch 'origin/master' into concurrent
# Conflicts: # lib/main/thread/pithreadpoolexecutor.cpp # lib/main/thread/pithreadpoolexecutor.h # tests/concurrent/ExecutorIntegrationTest.cpp # tests/concurrent/ExecutorUnitTest.cpp # tests/concurrent/testutil.h
This commit is contained in:
55
tests/concurrent/ExecutorIntegrationTest.cpp
Normal file
55
tests/concurrent/ExecutorIntegrationTest.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pithreadpoolexecutor.h"
|
||||
#include "pimutex.h"
|
||||
#include "testutil.h"
|
||||
|
||||
TEST(ExcutorIntegrationTest, execute_is_runnable_invoke) {
|
||||
PIMutex m;
|
||||
int invokedRunnables = 0;
|
||||
PIThreadPoolExecutor executorService(1);
|
||||
executorService.execute([&]() {
|
||||
m.lock();
|
||||
invokedRunnables++;
|
||||
m.unlock();
|
||||
});
|
||||
piMSleep(WAIT_THREAD_TIME_MS);
|
||||
m.lock();
|
||||
ASSERT_EQ(invokedRunnables, 1);
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
TEST(ExcutorIntegrationTest, execute_is_not_execute_after_shutdown) {
|
||||
volatile bool isRunnableInvoke = false;
|
||||
PIThreadPoolExecutor executorService(1);
|
||||
executorService.shutdown();
|
||||
executorService.execute([&]() {
|
||||
isRunnableInvoke = true;
|
||||
});
|
||||
piMSleep(WAIT_THREAD_TIME_MS);
|
||||
ASSERT_FALSE(isRunnableInvoke);
|
||||
}
|
||||
|
||||
TEST(ExcutorIntegrationTest, execute_is_execute_before_shutdown) {
|
||||
volatile bool isRunnableInvoke = false;
|
||||
PIThreadPoolExecutor executorService(1);
|
||||
executorService.execute([&]() {
|
||||
piMSleep(WAIT_THREAD_TIME_MS);
|
||||
isRunnableInvoke = true;
|
||||
});
|
||||
executorService.shutdown();
|
||||
piMSleep(2 * WAIT_THREAD_TIME_MS);
|
||||
ASSERT_TRUE(isRunnableInvoke);
|
||||
}
|
||||
|
||||
TEST(ExcutorIntegrationTest, execute_is_awaitTermination_wait) {
|
||||
PIThreadPoolExecutor executorService(1);
|
||||
executorService.execute([&]() {
|
||||
piMSleep(2 * WAIT_THREAD_TIME_MS);
|
||||
});
|
||||
executorService.shutdown();
|
||||
PITimeMeasurer measurer;
|
||||
ASSERT_TRUE(executorService.awaitTermination(3 * WAIT_THREAD_TIME_MS));
|
||||
double waitTime = measurer.elapsed_m();
|
||||
ASSERT_GE(waitTime, WAIT_THREAD_TIME_MS);
|
||||
ASSERT_LE(waitTime, 4 * WAIT_THREAD_TIME_MS);
|
||||
}
|
||||
Reference in New Issue
Block a user