Skip to content

Commit

Permalink
[Tests/unit/core] : Fix build 'test_workerpool'. (rdkcentral#1570)
Browse files Browse the repository at this point in the history
* [Tests/unit/core] : Fix build 'test_workerpool'.

'ThreadPool' and 'WorkerPool' changes were not (fully) integrated.

* [Tests/unit/core] : Amend 'a65dbb2adf2e9622aae8825c0d88c599a4a252e6'.

- Add 1 to occupation to compensate for the 'internal' timer.

- Reverse the boolean test for calculating occupation.

* [Tests/unit/core] : test for less or equal on timings in 'test_workerpool'.

Clock timings are never exact due to resolution, rounding and scheduling. Assume a Job executed earlier is allowed and preferred.

---------

Co-authored-by: Pierre Wielders <[email protected]>
  • Loading branch information
msieben and pwielders authored Apr 22, 2024
1 parent 932dee7 commit d60aed5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Tests/unit/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ add_executable(${TEST_RUNNER_NAME}
test_weblinktext.cpp
test_websocketjson.cpp
test_websockettext.cpp
#test_workerpool.cpp
test_workerpool.cpp
test_xgetopt.cpp
#test_message_dispatcher.cpp
)
Expand Down
19 changes: 11 additions & 8 deletions Tests/unit/core/test_workerpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class JobControl {
static void CheckScheduledTime(Core::Time current, Core::Time invokedTime, uint16_t scheduledTime)
{
uint8_t currentSecond = current.Seconds();
uint8_t scheduledSecond = scheduledTime/1000;
uint8_t scheduledSecond = scheduledTime; // From milliseconds to seconds, integer division!
uint8_t invokedSecond = invokedTime.Seconds();

uint32_t expectedAddedTime = 0;
Expand All @@ -209,7 +209,7 @@ class JobControl {
expectedAddedTime = (currentSecond + scheduledSecond);
}

EXPECT_EQ(invokedSecond, expectedAddedTime);
EXPECT_LE(invokedSecond, expectedAddedTime);
}
uint32_t WaitForReady(IDispatch* job, const uint32_t waitTime = 0)
{
Expand Down Expand Up @@ -926,13 +926,16 @@ TEST(Core_WorkerPool, Check_RescheduleJobs_MultiplePool_MultipleJobs_AdditionalJ
void CheckMetaData(const uint8_t pending, const uint8_t occupation, const uint8_t expectedRuns)
{
const IWorkerPool::Metadata& metaData = IWorkerPool::Instance().Snapshot();
EXPECT_EQ(metaData.Pending, pending);
EXPECT_EQ(metaData.Occupation, occupation);
uint16_t totalRuns = 0;

EXPECT_EQ(metaData.Pending.size(), pending); // Whatever is in the ThreadPool::_queue is considered pending

uint16_t totalRuns = 0, totalOccupation = 0;
for (uint8_t index = 0; index < metaData.Slots; index++) {
totalRuns += metaData.Slot[index];
totalRuns += metaData.Slot[index].Runs;
totalOccupation += metaData.Slot[index].Job.IsSet();
}
EXPECT_EQ(totalRuns, expectedRuns);
EXPECT_EQ(totalOccupation, occupation);
}
void CheckWorkerPool_MetaData(uint8_t threadCount, uint8_t queueSize, uint8_t additionalJobs)
{
Expand All @@ -954,7 +957,7 @@ void CheckWorkerPool_MetaData(uint8_t threadCount, uint8_t queueSize, uint8_t ad
workerPool.SubmitUsingExternalWorker(jobs[i]);
}

CheckMetaData(queueSize, 0, 0);
CheckMetaData(queueSize, 1, 0);
workerPool.RunThreadPool();

usleep(MaxJobWaitTime);
Expand All @@ -967,7 +970,7 @@ void CheckWorkerPool_MetaData(uint8_t threadCount, uint8_t queueSize, uint8_t ad
}

workerPool.Stop();
CheckMetaData(0, 0, queueSize + additionalJobs);
CheckMetaData(queueSize, 1, queueSize + additionalJobs);
for (auto& job: jobs) {
job.Release();
}
Expand Down

0 comments on commit d60aed5

Please sign in to comment.