Skip to content

Commit

Permalink
relax test timing checks (#6481)
Browse files Browse the repository at this point in the history
* relax test timing checks

* add minimum threshold check on fist delay
  • Loading branch information
ironage authored Apr 10, 2023
1 parent aa98927 commit 7a17dab
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,12 +1996,6 @@ TEST_CASE("app: make distributable client file", "[sync][app]") {
}
}

constexpr size_t minus_25_percent(size_t val)
{
REALM_ASSERT(val * .75 > 10);
return val * .75 - 10;
}

TEST_CASE("app: sync integration", "[sync][app]") {
auto logger = std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);

Expand Down Expand Up @@ -2759,14 +2753,25 @@ TEST_CASE("app: sync integration", "[sync][app]") {

// sync delays start at 1000ms minus a random number of up to 25%.
// the subsequent delay is double the previous one minus a random 25% again.
constexpr size_t min_first_delay = minus_25_percent(1000);
std::vector<uint64_t> expected_min_delays = {0, min_first_delay};
while (expected_min_delays.size() < delay_times.size()) {
expected_min_delays.push_back(minus_25_percent(expected_min_delays.back() << 1));
// this calculation happens in Connection::initiate_reconnect_wait()
bool increasing_delay = true;
for (size_t i = 1; i < delay_times.size(); ++i) {
if (delay_times[i - 1] >= delay_times[i]) {
increasing_delay = false;
}
}
// fail if the first delay isn't longer than half a second
if (delay_times.size() <= 1 || delay_times[1] < 500) {
increasing_delay = false;
}
for (size_t i = 0; i < delay_times.size(); ++i) {
REQUIRE(delay_times[i] > expected_min_delays[i]);
if (!increasing_delay) {
std::cerr << "delay times are not increasing: ";
for (auto& delay : delay_times) {
std::cerr << delay << ", ";
}
std::cerr << std::endl;
}
REQUIRE(increasing_delay);
}
}

Expand Down

0 comments on commit 7a17dab

Please sign in to comment.