From 3697765c014c0f69490283eca93eab62ad6bdbeb Mon Sep 17 00:00:00 2001 From: donnadionne Date: Sat, 21 Nov 2020 12:30:39 -0800 Subject: [PATCH] Revert "Adjusting time measurements for the timeout test to make it more stable" --- src/core/lib/iomgr/exec_ctx.cc | 8 ++-- test/cpp/end2end/xds_end2end_test.cc | 65 +++++++++++----------------- 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index db3135c5b44..18d0aae4624 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -109,13 +109,13 @@ grpc_millis grpc_timespec_to_millis_round_up(gpr_timespec ts) { } grpc_millis grpc_cycle_counter_to_millis_round_down(gpr_cycle_counter cycles) { - return timespec_to_millis_round_down(gpr_convert_clock_type( - gpr_cycle_counter_to_time(cycles), g_start_time.clock_type)); + return timespan_to_millis_round_down( + gpr_cycle_counter_sub(cycles, g_start_cycle)); } grpc_millis grpc_cycle_counter_to_millis_round_up(gpr_cycle_counter cycles) { - return timespec_to_millis_round_up(gpr_convert_clock_type( - gpr_cycle_counter_to_time(cycles), g_start_time.clock_type)); + return timespan_to_millis_round_up( + gpr_cycle_counter_sub(cycles, g_start_cycle)); } namespace grpc_core { diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index ff9e53112b9..2af66f85f8b 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -51,7 +51,6 @@ #include "src/core/ext/xds/xds_client.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/env.h" -#include "src/core/lib/gpr/time_precise.h" #include "src/core/lib/gpr/tmpfile.h" #include "src/core/lib/gprpp/map.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -4216,9 +4215,11 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClustersWithPickingDelays) { } TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) { + // TODO(https://github.com/grpc/grpc/issues/24549): TSAN won't work here. + if (BuiltUnderAsan() || BuiltUnderTsan()) return; + gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_TIMEOUT", "true"); - const int64_t kTimeoutMillis = 500; - const int64_t kTimeoutNano = kTimeoutMillis * 1000000; + const int64_t kTimeoutNano = 500000000; const int64_t kTimeoutGrpcTimeoutHeaderMaxSecond = 1; const int64_t kTimeoutMaxStreamDurationSecond = 2; const int64_t kTimeoutHttpMaxStreamDurationSecond = 3; @@ -4308,15 +4309,7 @@ TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) { // Set listener and route config. SetListenerAndRouteConfiguration(0, std::move(listener), new_route_config); // Test grpc_timeout_header_max of 1.5 seconds applied - gpr_timespec now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - gpr_timespec est_timeout_time = gpr_time_add( - now, gpr_time_from_millis( - kTimeoutGrpcTimeoutHeaderMaxSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); - gpr_timespec est_upperbound = gpr_time_add( - now, gpr_time_from_millis( - kTimeoutMaxStreamDurationSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); + auto t0 = system_clock::now(); CheckRpcSendFailure(1, RpcOptions() .set_rpc_service(SERVICE_ECHO1) @@ -4324,19 +4317,15 @@ TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) { .set_wait_for_ready(true) .set_timeout_ms(kTimeoutApplicationSecond * 1000), StatusCode::DEADLINE_EXCEEDED); - now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - EXPECT_GE(gpr_time_cmp(now, est_timeout_time), 0); - EXPECT_LT(gpr_time_cmp(now, est_upperbound), 0); + auto ellapsed_nano_seconds = + std::chrono::duration_cast(system_clock::now() - + t0); + EXPECT_GT(ellapsed_nano_seconds.count(), + kTimeoutGrpcTimeoutHeaderMaxSecond * 1000000000 + kTimeoutNano); + EXPECT_LT(ellapsed_nano_seconds.count(), + kTimeoutMaxStreamDurationSecond * 1000000000); // Test max_stream_duration of 2.5 seconds applied - now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - est_timeout_time = gpr_time_add( - now, gpr_time_from_millis( - kTimeoutMaxStreamDurationSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); - est_upperbound = gpr_time_add( - now, gpr_time_from_millis( - kTimeoutHttpMaxStreamDurationSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); + t0 = system_clock::now(); CheckRpcSendFailure(1, RpcOptions() .set_rpc_service(SERVICE_ECHO2) @@ -4344,26 +4333,24 @@ TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) { .set_wait_for_ready(true) .set_timeout_ms(kTimeoutApplicationSecond * 1000), StatusCode::DEADLINE_EXCEEDED); - now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - EXPECT_GE(gpr_time_cmp(now, est_timeout_time), 0); - EXPECT_LT(gpr_time_cmp(now, est_upperbound), 0); + ellapsed_nano_seconds = std::chrono::duration_cast( + system_clock::now() - t0); + EXPECT_GT(ellapsed_nano_seconds.count(), + kTimeoutMaxStreamDurationSecond * 1000000000 + kTimeoutNano); + EXPECT_LT(ellapsed_nano_seconds.count(), + kTimeoutHttpMaxStreamDurationSecond * 1000000000); // Test http_stream_duration of 3.5 seconds applied - now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - est_timeout_time = gpr_time_add( - now, gpr_time_from_millis( - kTimeoutHttpMaxStreamDurationSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); - est_upperbound = gpr_time_add( - now, - gpr_time_from_millis(kTimeoutApplicationSecond * 1000 + kTimeoutMillis, - GPR_TIMESPAN)); + t0 = system_clock::now(); CheckRpcSendFailure(1, RpcOptions().set_wait_for_ready(true).set_timeout_ms( kTimeoutApplicationSecond * 1000), StatusCode::DEADLINE_EXCEEDED); - now = gpr_cycle_counter_to_time(gpr_get_cycle_counter()); - EXPECT_GE(gpr_time_cmp(now, est_timeout_time), 0); - EXPECT_LT(gpr_time_cmp(now, est_upperbound), 0); + ellapsed_nano_seconds = std::chrono::duration_cast( + system_clock::now() - t0); + EXPECT_GT(ellapsed_nano_seconds.count(), + kTimeoutHttpMaxStreamDurationSecond * 1000000000 + kTimeoutNano); + EXPECT_LT(ellapsed_nano_seconds.count(), + kTimeoutApplicationSecond * 1000000000); gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_TIMEOUT"); }