MCPcopy Create free account
hub / github.com/arkhipenko/TaskScheduler / SchedulerTest

Class SchedulerTest

tests/test-scheduler-basic.cpp:83–127  ·  view source on GitHub ↗

* @brief Test fixture class for TaskScheduler unit tests * * Provides common setup and teardown functionality for all scheduler tests. * Ensures clean test state between test runs and provides utility methods * for common test operations like running scheduler with timeout conditions. */

Source from the content-addressed store, hash-verified

81 * for common test operations like running scheduler with timeout conditions.
82 */
83class SchedulerTest : public ::testing::Test {
84protected:
85 /**
86 * @brief Set up test environment before each test
87 *
88 * Clears any previous test output and initializes timing system.
89 * Called automatically by Google Test framework before each test method.
90 * Ensures each test starts with a clean, predictable state.
91 */
92 void SetUp() override {
93 clearTestOutput();
94 // Reset time by creating new static start point
95 millis(); // Initialize timing
96 }
97
98 /**
99 * @brief Clean up test environment after each test
100 *
101 * Clears test output to prevent interference between tests.
102 * Called automatically by Google Test framework after each test method.
103 * Ensures no test artifacts affect subsequent tests.
104 */
105 void TearDown() override {
106 clearTestOutput();
107 }
108
109 /**
110 * @brief Helper method to run scheduler until condition is met or timeout
111 *
112 * Executes the scheduler repeatedly until either the specified condition
113 * returns true or the timeout period expires. Essential for testing
114 * time-dependent scheduler behavior without creating infinite loops.
115 *
116 * @param ts Reference to the Scheduler object to execute
117 * @param condition Lambda function that returns true when test condition is met
118 * @param timeout_ms Maximum time to wait before giving up (default: 1000ms)
119 * @return true if condition was met within timeout, false otherwise
120 */
121 bool runSchedulerUntil(Scheduler& ts, std::function<bool()> condition, unsigned long timeout_ms = 1000) {
122 return waitForCondition([&]() {
123 ts.execute();
124 return condition();
125 }, timeout_ms);
126 }
127};
128
129/**
130 * @brief Test basic scheduler object creation

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected