mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-10-01 03:43:42 +08:00
fix RateKeeper test
This commit is contained in:
@@ -6,11 +6,18 @@
|
|||||||
TEST_CASE("RateKeeper") {
|
TEST_CASE("RateKeeper") {
|
||||||
float freq = GENERATE(10, 50, 100);
|
float freq = GENERATE(10, 50, 100);
|
||||||
RateKeeper rk("Test RateKeeper", freq);
|
RateKeeper rk("Test RateKeeper", freq);
|
||||||
|
|
||||||
|
int lags = 0;
|
||||||
|
int bad_keep_times = 0;
|
||||||
for (int i = 0; i < freq; ++i) {
|
for (int i = 0; i < freq; ++i) {
|
||||||
double begin = seconds_since_boot();
|
double begin = seconds_since_boot();
|
||||||
util::sleep_for(util::random_int(0, 1000.0 / freq - 1));
|
util::sleep_for(util::random_int(0, 1000.0 / freq - 1));
|
||||||
bool lagged = rk.keepTime();
|
bool lagged = rk.keepTime();
|
||||||
REQUIRE(std::abs(seconds_since_boot() - begin - (1 / freq)) < 1e-3);
|
lags += lagged;
|
||||||
REQUIRE(lagged == false);
|
bad_keep_times += (seconds_since_boot() - begin - (1 / freq)) > 1e-3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// need a tolerance here due to scheduling
|
||||||
|
REQUIRE(lags < 5);
|
||||||
|
REQUIRE(bad_keep_times < 5);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user