Calculate clock difference and accomodate it to deflake timeout tests (#28868)

* Calculating clock difference and accomendate it to deflake timeout
tests.

* Fixing according to code review comments.
pull/28901/merge
donnadionne 3 years ago committed by GitHub
parent 2fdb5f90c3
commit 431d314eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      test/cpp/end2end/xds/xds_end2end_test.cc

@ -3449,6 +3449,18 @@ TEST_P(LdsV2Test, IgnoresHttpFilters) {
using LdsRdsTest = BasicTest;
MATCHER_P2(AdjustedClockInRange, t1, t2, "equals time") {
gpr_cycle_counter cycle_now = gpr_get_cycle_counter();
grpc_millis cycle_time = grpc_cycle_counter_to_millis_round_down(cycle_now);
grpc_millis time_spec =
grpc_timespec_to_millis_round_down(gpr_now(GPR_CLOCK_MONOTONIC));
grpc_millis now = arg + time_spec - cycle_time;
bool ok = true;
ok &= ::testing::ExplainMatchResult(::testing::Ge(t1), now, result_listener);
ok &= ::testing::ExplainMatchResult(::testing::Lt(t2), now, result_listener);
return ok;
}
// Tests that LDS client should send an ACK upon correct LDS response (with
// inlined RDS result).
TEST_P(LdsRdsTest, Vanilla) {
@ -4732,7 +4744,7 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClustersWithPickingDelays) {
EXPECT_EQ(1, backends_[1]->backend_service()->request_count());
}
TEST_P(LdsRdsTest, DISABLED_XdsRoutingApplyXdsTimeout) {
TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) {
const int64_t kTimeoutMillis = 500;
const int64_t kTimeoutNano = kTimeoutMillis * 1000000;
const int64_t kTimeoutGrpcTimeoutHeaderMaxSecond = 1;
@ -4830,9 +4842,7 @@ TEST_P(LdsRdsTest, DISABLED_XdsRoutingApplyXdsTimeout) {
.set_wait_for_ready(true)
.set_timeout_ms(kTimeoutApplicationSecond * 1000))
.set_expected_error_code(StatusCode::DEADLINE_EXCEEDED));
t0 = NowFromCycleCounter();
EXPECT_GE(t0, t1);
EXPECT_LT(t0, t2);
EXPECT_THAT(NowFromCycleCounter(), AdjustedClockInRange(t1, t2));
// Test max_stream_duration of 2.5 seconds applied
t0 = NowFromCycleCounter();
t1 = t0 + kTimeoutMaxStreamDurationSecond * 1000 + kTimeoutMillis;
@ -4846,9 +4856,7 @@ TEST_P(LdsRdsTest, DISABLED_XdsRoutingApplyXdsTimeout) {
.set_wait_for_ready(true)
.set_timeout_ms(kTimeoutApplicationSecond * 1000))
.set_expected_error_code(StatusCode::DEADLINE_EXCEEDED));
t0 = NowFromCycleCounter();
EXPECT_GE(t0, t1);
EXPECT_LT(t0, t2);
EXPECT_THAT(NowFromCycleCounter(), AdjustedClockInRange(t1, t2));
// Test http_stream_duration of 3.5 seconds applied
t0 = NowFromCycleCounter();
t1 = t0 + kTimeoutHttpMaxStreamDurationSecond * 1000 + kTimeoutMillis;
@ -4858,9 +4866,7 @@ TEST_P(LdsRdsTest, DISABLED_XdsRoutingApplyXdsTimeout) {
.set_rpc_options(RpcOptions().set_wait_for_ready(true).set_timeout_ms(
kTimeoutApplicationSecond * 1000))
.set_expected_error_code(StatusCode::DEADLINE_EXCEEDED));
t0 = NowFromCycleCounter();
EXPECT_GE(t0, t1);
EXPECT_LT(t0, t2);
EXPECT_THAT(NowFromCycleCounter(), AdjustedClockInRange(t1, t2));
}
TEST_P(LdsRdsTest, XdsRoutingApplyApplicationTimeoutWhenXdsTimeoutExplicit0) {

Loading…
Cancel
Save