Skip to content

Commit

Permalink
fix(task_manager): update task manager start parameter to 4 in tests …
Browse files Browse the repository at this point in the history
…and don't run start more than once

given the nature of the condition variable, the lambda would be executed multiple times, resulting in more than one call to StartManager::Start
  • Loading branch information
jr0me committed Dec 11, 2024
1 parent 5b9d775 commit a0fca67
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/agent/task_manager/tests/task_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TaskManagerTest : public ::testing::Test

TEST_F(TaskManagerTest, StartAndStop)
{
taskManager.Start(2);
taskManager.Start(4);
taskManager.Stop();
}

Expand All @@ -37,13 +37,18 @@ TEST_F(TaskManagerTest, EnqueueFunctionTask)
};

taskManager.EnqueueTask(task);
bool taskManagerStarted = false;

{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock,
[&]()
{
taskManager.Start(2);
if (!taskManagerStarted)
{
taskManagerStarted = true;
taskManager.Start(4);
}
return taskExecuted.load();
});
}
Expand All @@ -64,13 +69,18 @@ TEST_F(TaskManagerTest, EnqueueCoroutineTask)
};

taskManager.EnqueueTask(coroutineTask());
bool taskManagerStarted = false;

{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock,
[&]()
{
taskManager.Start(2);
if (!taskManagerStarted)
{
taskManagerStarted = true;
taskManager.Start(4);
}
return taskExecuted.load();
});
}
Expand All @@ -92,13 +102,18 @@ TEST_F(TaskManagerTest, EnqueueFunctionTaskIncrementsCounter)
};

taskManager.EnqueueTask(task);
bool taskManagerStarted = false;

{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock,
[&]()
{
taskManager.Start(2);
if (!taskManagerStarted)
{
taskManagerStarted = true;
taskManager.Start(4);
}
return taskExecuted.load();
});
}
Expand Down

0 comments on commit a0fca67

Please sign in to comment.