Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 950 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(event_loop) { | ||||
// We don't have any task scheduled anymore. | // We don't have any task scheduled anymore. | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | ||||
// Can't stop the event loop twice. | // Can't stop the event loop twice. | ||||
BOOST_CHECK(!m_processor->stopEventLoop()); | BOOST_CHECK(!m_processor->stopEventLoop()); | ||||
// Wait for the scheduler to stop. | // Wait for the scheduler to stop. | ||||
s.stop(true); | s.StopWhenDrained(); | ||||
schedulerThread.join(); | schedulerThread.join(); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(destructor) { | BOOST_AUTO_TEST_CASE(destructor) { | ||||
CScheduler s; | CScheduler s; | ||||
std::chrono::system_clock::time_point start, stop; | std::chrono::system_clock::time_point start, stop; | ||||
std::thread schedulerThread; | std::thread schedulerThread; | ||||
BOOST_CHECK(m_processor->startEventLoop(s)); | BOOST_CHECK(m_processor->startEventLoop(s)); | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 1); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 1); | ||||
// Start the service thread after the queue size check to prevent a race | // Start the service thread after the queue size check to prevent a race | ||||
// condition where the thread may be processing the event loop task during | // condition where the thread may be processing the event loop task during | ||||
// the check. | // the check. | ||||
schedulerThread = std::thread(std::bind(&CScheduler::serviceQueue, &s)); | schedulerThread = std::thread(std::bind(&CScheduler::serviceQueue, &s)); | ||||
// Destroy the processor. | // Destroy the processor. | ||||
m_processor.reset(); | m_processor.reset(); | ||||
// Now that avalanche is destroyed, there is no more scheduled tasks. | // Now that avalanche is destroyed, there is no more scheduled tasks. | ||||
BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | BOOST_CHECK_EQUAL(s.getQueueInfo(start, stop), 0); | ||||
// Wait for the scheduler to stop. | // Wait for the scheduler to stop. | ||||
s.stop(true); | s.StopWhenDrained(); | ||||
schedulerThread.join(); | schedulerThread.join(); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |