Fix flakey time diff assertion in resolver cooldown test

pull/25347/head
Alexander Polcyn 4 years ago
parent 9b749bfe0f
commit d289f34f37
  1. 22
      test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc

@ -31,8 +31,6 @@
#include "test/core/util/test_config.h"
constexpr int kMinResolutionPeriodMs = 1000;
// Provide some slack when checking intervals, to allow for test timing issues.
constexpr int kMinResolutionPeriodForCheckMs = 900;
extern grpc_address_resolver_vtable* grpc_resolve_address_impl;
static grpc_address_resolver_vtable* default_resolve_address;
@ -76,9 +74,16 @@ static void test_resolve_address_impl(const char* name,
} else {
grpc_millis now =
grpc_timespec_to_millis_round_up(gpr_now(GPR_CLOCK_MONOTONIC));
GPR_ASSERT(now - last_resolution_time >= kMinResolutionPeriodForCheckMs);
GPR_ASSERT(now - last_resolution_time >= kMinResolutionPeriodMs);
last_resolution_time = now;
}
// For correct time diff comparisons, make sure that any subsequent calls
// to grpc_core::ExecCtx::Get()->Now() on this thread don't return a time
// which is earlier than that returned by the call(s) to
// gpr_now(GPR_CLOCK_MONOTONIC) within this function. This is important
// because the resolver's last_resolution_timestamp_ will be taken from
// grpc_core::ExecCtx::Get()->Now() right after this returns.
grpc_core::ExecCtx::Get()->InvalidateNow();
}
static grpc_error* test_blocking_resolve_address_impl(
@ -109,14 +114,21 @@ static grpc_ares_request* test_dns_lookup_ares_locked(
gpr_log(GPR_DEBUG,
"last_resolution_time:%" PRId64 " now:%" PRId64
" min_time_between:%d",
last_resolution_time, now, kMinResolutionPeriodForCheckMs);
last_resolution_time, now, kMinResolutionPeriodMs);
if (last_resolution_time == 0) {
last_resolution_time =
grpc_timespec_to_millis_round_up(gpr_now(GPR_CLOCK_MONOTONIC));
} else {
GPR_ASSERT(now - last_resolution_time >= kMinResolutionPeriodForCheckMs);
GPR_ASSERT(now - last_resolution_time >= kMinResolutionPeriodMs);
last_resolution_time = now;
}
// For correct time diff comparisons, make sure that any subsequent calls
// to grpc_core::ExecCtx::Get()->Now() on this thread don't return a time
// which is earlier than that returned by the call(s) to
// gpr_now(GPR_CLOCK_MONOTONIC) within this function. This is important
// because the resolver's last_resolution_timestamp_ will be taken from
// grpc_core::ExecCtx::Get()->Now() right after this returns.
grpc_core::ExecCtx::Get()->InvalidateNow();
return result;
}

Loading…
Cancel
Save