| 49 | } // (anonymous) namespace |
| 50 | |
| 51 | TEST(dds_DCPS_MultiTask, TimingChecker) |
| 52 | { |
| 53 | using namespace OpenDDS::DCPS; |
| 54 | |
| 55 | bool tight_timing = Utils::TimingChecker::check_timing(); |
| 56 | |
| 57 | ThreadStatusManager tsm; |
| 58 | ReactorTask reactor_task(false); |
| 59 | reactor_task.open_reactor_task(&tsm); |
| 60 | |
| 61 | RcHandle<TestObj> obj = make_rch<TestObj>(rchandle_from(&reactor_task)); |
| 62 | obj->multi_->enable(TimeDuration::from_msec(2000)); // 2.0 seconds |
| 63 | ACE_DEBUG((LM_DEBUG, "total_count = %d\n", total_count.load())); |
| 64 | EXPECT_EQ(total_count, 0u); |
| 65 | ACE_OS::sleep(5); // 5.0 seconds |
| 66 | ACE_DEBUG((LM_DEBUG, "total_count = %d\n", total_count.load())); |
| 67 | EXPECT_EQ(total_count, 2u); // expect 2 executions within a 5.0 second interval when period is 2.0 seconds |
| 68 | obj->set_do_enable(true); |
| 69 | const MonotonicTimePoint deadline = MonotonicTimePoint::now() + TimeDuration::from_msec(2000); // 2.0 seconds from now |
| 70 | size_t enable_calls = 0; |
| 71 | while (MonotonicTimePoint::now() < deadline) { |
| 72 | ++enable_calls; |
| 73 | obj->multi_->enable(TimeDuration::from_msec(100)); // 0.1 seconds from now |
| 74 | ACE_OS::sleep(ACE_Time_Value(0, 1000)); // sleep for 0.001 seconds |
| 75 | } |
| 76 | obj->set_do_enable(false); |
| 77 | ACE_OS::sleep(ACE_Time_Value(0, 110000)); // sleep for 0.11 seconds to catch final "fast" executions |
| 78 | ACE_DEBUG((LM_DEBUG, "enable_calls = %d\n", enable_calls)); |
| 79 | ACE_DEBUG((LM_DEBUG, "total_count = %d\n", total_count.load())); |
| 80 | // 1 from the slow period, 20 from the fast period (2.0 / 0.1) |
| 81 | if (tight_timing) { |
| 82 | EXPECT_EQ(total_count, 22u); |
| 83 | } else { |
| 84 | EXPECT_GE(total_count, 17u); |
| 85 | EXPECT_LE(total_count, 22u); |
| 86 | } |
| 87 | ACE_OS::sleep(5); // sleep for 5.0 more seconds, should fall back to 2.0 second default period |
| 88 | ACE_DEBUG((LM_DEBUG, "total_count = %d\n", total_count.load())); |
| 89 | // 1 from the slow period, 20 from the fast period (2.0 / 0.1), 2 more from last slow period |
| 90 | if (tight_timing) { |
| 91 | EXPECT_EQ(total_count, 24u); |
| 92 | } else { |
| 93 | EXPECT_GE(total_count, 19u); |
| 94 | EXPECT_LE(total_count, 24u); |
| 95 | } |
| 96 | obj->multi_->disable(); |
| 97 | |
| 98 | reactor_task.stop(); |
| 99 | } |
nothing calls this directly
no test coverage detected