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

Function TEST_F

tests/test-scheduler-priority.cpp:350–487  ·  view source on GitHub ↗

* @brief Test basic scheduler hierarchy setup and validation (based on example11) * * TESTS: setHighPriorityScheduler(), currentScheduler(), currentTask() * * PURPOSE: Verify that scheduler hierarchy can be established correctly * and that the priority relationships work as expected for basic scenarios, * following the pattern from Scheduler_example11_Priority. * * PRIORITY HIERARCHY SETUP

Source from the content-addressed store, hash-verified

348 * - Priority evaluation follows documented sequence
349 */
350TEST_F(PrioritySchedulerTest, BasicSchedulerHierarchy) {
351 // Create base and high priority schedulers (matching example11)
352 Scheduler base_scheduler;
353 Scheduler high_scheduler;
354
355 // Establish hierarchy - high scheduler has priority over base
356 base_scheduler.setHighPriorityScheduler(&high_scheduler);
357
358 // Add tasks to schedulers with intervals matching example11
359 // Base priority tasks: longer intervals
360 Task t1(1000, 3, &priority_test_callback, &base_scheduler, false); // 1000ms interval
361 Task t2(2000, 2, &priority_test_callback, &base_scheduler, false); // 2000ms interval
362 Task t3(3000, 1, &priority_test_callback, &base_scheduler, false); // 3000ms interval
363
364 // High priority tasks: shorter intervals for more frequent execution
365 Task t4(500, 6, &priority_test_callback, &high_scheduler, false); // 500ms interval
366 Task t5(1000, 3, &priority_test_callback, &high_scheduler, false); // 1000ms interval
367
368 // Set task IDs for identification (like in example11)
369 t1.setId(1);
370 t2.setId(2);
371 t3.setId(3);
372 t4.setId(4);
373 t5.setId(5);
374
375 // Enable all tasks recursively (like example11: enableAll(true))
376 base_scheduler.enableAll(true);
377
378 // Verify tasks are enabled
379 EXPECT_TRUE(t1.isEnabled());
380 EXPECT_TRUE(t2.isEnabled());
381 EXPECT_TRUE(t3.isEnabled());
382 EXPECT_TRUE(t4.isEnabled());
383 EXPECT_TRUE(t5.isEnabled());
384
385 // Execute scheduler for sufficient time to see priority pattern
386 // High priority tasks should execute more frequently due to shorter intervals
387 bool success = runPrioritySchedulerUntil(base_scheduler, []() {
388 return priority_callback_counter >= 15; // 6+3=9 high + 3+2+1=6 base = 15 total
389 }, 5000);
390
391 EXPECT_TRUE(success);
392 EXPECT_EQ(priority_callback_counter, 15);
393
394 // Count executions by task ID to verify the priority pattern
395 int task1_count = 0, task2_count = 0, task3_count = 0; // Base priority tasks
396 int task4_count = 0, task5_count = 0; // High priority tasks
397
398 for (size_t i = 0; i < getPriorityTestOutputCount(); i++) {
399 std::string output = getPriorityTestOutput(i);
400 if (output == "task_1_executed") task1_count++;
401 else if (output == "task_2_executed") task2_count++;
402 else if (output == "task_3_executed") task3_count++;
403 else if (output == "task_4_executed") task4_count++;
404 else if (output == "task_5_executed") task5_count++;
405 }
406
407 // Verify execution counts match expected iterations

Callers

nothing calls this directly

Calls 8

millisFunction · 0.85
setIdMethod · 0.80
enableAllMethod · 0.80
isEnabledMethod · 0.80
restartMethod · 0.80
disableAllMethod · 0.80
enableMethod · 0.45

Tested by

no test coverage detected