Changeset View
Changeset View
Standalone View
Standalone View
src/test/scheduler_tests.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(manythreads) { | ||||
// counters, and then schedules another task 0-1000 | // counters, and then schedules another task 0-1000 | ||||
// microseconds in the future to subtract or add from | // microseconds in the future to subtract or add from | ||||
// the counter -random_amount+1, so in the end the shared | // the counter -random_amount+1, so in the end the shared | ||||
// counters should sum to the number of initial tasks performed. | // counters should sum to the number of initial tasks performed. | ||||
CScheduler microTasks; | CScheduler microTasks; | ||||
boost::mutex counterMutex[10]; | boost::mutex counterMutex[10]; | ||||
int counter[10] = {0}; | int counter[10] = {0}; | ||||
FastRandomContext rng(42); | FastRandomContext rng{/* fDeterministic */ true}; | ||||
// [0, 9] | // [0, 9] | ||||
auto zeroToNine = [](FastRandomContext &rc) -> int { | auto zeroToNine = [](FastRandomContext &rc) -> int { | ||||
return rc.randrange(10); | return rc.randrange(10); | ||||
}; | }; | ||||
// [-11, 1000] | // [-11, 1000] | ||||
auto randomMsec = [](FastRandomContext &rc) -> int { | auto randomMsec = [](FastRandomContext &rc) -> int { | ||||
return -11 + rc.randrange(1012); | return -11 + int(rc.randrange(1012)); | ||||
}; | }; | ||||
// [-1000, 1000] | // [-1000, 1000] | ||||
auto randomDelta = [](FastRandomContext &rc) -> int { | auto randomDelta = [](FastRandomContext &rc) -> int { | ||||
return -1000 + rc.randrange(2001); | return -1000 + int(rc.randrange(2001)); | ||||
}; | }; | ||||
boost::chrono::system_clock::time_point start = | boost::chrono::system_clock::time_point start = | ||||
boost::chrono::system_clock::now(); | boost::chrono::system_clock::now(); | ||||
boost::chrono::system_clock::time_point now = start; | boost::chrono::system_clock::time_point now = start; | ||||
boost::chrono::system_clock::time_point first, last; | boost::chrono::system_clock::time_point first, last; | ||||
size_t nTasks = microTasks.getQueueInfo(first, last); | size_t nTasks = microTasks.getQueueInfo(first, last); | ||||
BOOST_CHECK(nTasks == 0); | BOOST_CHECK(nTasks == 0); | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |