diff options
author | Vijay Pai <vpai@google.com> | 2015-07-10 16:43:58 -0700 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2015-07-10 16:43:58 -0700 |
commit | d1c925402964f5c1139d71ff7fe5cac97b1ee257 (patch) | |
tree | 49cfb2ff68a32ddc5ebfb3e771dcdcc334c25c0a /test | |
parent | 25adcaa164780075cf85ae63774e0cae867effff (diff) | |
parent | 080d6c50bbed3dde739b2de610023d8bd8d7966f (diff) |
Merge pull request #2289 from ctiller/footprints-on-the-sands-of-time
Introduce multiple clocks to GPR
Diffstat (limited to 'test')
27 files changed, 92 insertions, 78 deletions
diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 33f7c02b61..407c72b519 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -248,7 +248,8 @@ void cq_verify(cq_verifier *v) { } void cq_verify_empty(cq_verifier *v) { - gpr_timespec deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(1)); + gpr_timespec deadline = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1)); grpc_event ev; GPR_ASSERT(v->expect.next == &v->expect && "expectation queue must be empty"); diff --git a/test/core/fling/client.c b/test/core/fling/client.c index ee5e390c39..6741a9dec8 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -124,7 +124,7 @@ static void step_ping_pong_stream(void) { } static double now(void) { - gpr_timespec tv = gpr_now(); + gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); return 1e9 * tv.tv_sec + tv.tv_nsec; } diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 9542e15ad0..468013c3ec 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -241,7 +241,8 @@ int main(int argc, char **argv) { shutdown_started = 1; } ev = grpc_completion_queue_next( - cq, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000))); + cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000))); s = ev.tag; switch (ev.type) { case GRPC_OP_COMPLETE: diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index 6e579bc045..ca0b2d1519 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -145,7 +145,8 @@ int main(int argc, char **argv) { gpr_free(args[0]); gpr_free(args[2]); - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); grpc_test_init(argc, argv); grpc_init(); diff --git a/test/core/iomgr/alarm_list_test.c b/test/core/iomgr/alarm_list_test.c index 684e3f579a..225c449d4b 100644 --- a/test/core/iomgr/alarm_list_test.c +++ b/test/core/iomgr/alarm_list_test.c @@ -51,7 +51,7 @@ static void cb(void *arg, int success) { } static void add_test(void) { - gpr_timespec start = gpr_now(); + gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); int i; grpc_alarm alarms[20]; @@ -61,13 +61,13 @@ static void add_test(void) { /* 10 ms alarms. will expire in the current epoch */ for (i = 0; i < 10; i++) { grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(10)), - cb, (void *)(gpr_intptr) i, start); + cb, (void *)(gpr_intptr)i, start); } /* 1010 ms alarms. will expire in the next epoch */ for (i = 10; i < 20; i++) { grpc_alarm_init(&alarms[i], gpr_time_add(start, gpr_time_from_millis(1010)), - cb, (void *)(gpr_intptr) i, start); + cb, (void *)(gpr_intptr)i, start); } /* collect alarms. Only the first batch should be ready. */ @@ -115,15 +115,15 @@ void destruction_test(void) { memset(cb_called, 0, sizeof(cb_called)); grpc_alarm_init(&alarms[0], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr) 0, gpr_time_0); + (void *)(gpr_intptr)0, gpr_time_0); grpc_alarm_init(&alarms[1], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr) 1, gpr_time_0); + (void *)(gpr_intptr)1, gpr_time_0); grpc_alarm_init(&alarms[2], gpr_time_from_millis(100), cb, - (void *)(gpr_intptr) 2, gpr_time_0); + (void *)(gpr_intptr)2, gpr_time_0); grpc_alarm_init(&alarms[3], gpr_time_from_millis(3), cb, - (void *)(gpr_intptr) 3, gpr_time_0); + (void *)(gpr_intptr)3, gpr_time_0); grpc_alarm_init(&alarms[4], gpr_time_from_millis(1), cb, - (void *)(gpr_intptr) 4, gpr_time_0); + (void *)(gpr_intptr)4, gpr_time_0); GPR_ASSERT(1 == grpc_alarm_check(NULL, gpr_time_from_millis(2), NULL)); GPR_ASSERT(1 == cb_called[4][1]); grpc_alarm_cancel(&alarms[0]); diff --git a/test/core/iomgr/alarm_test.c b/test/core/iomgr/alarm_test.c index 0ccec435e6..362eb5fe63 100644 --- a/test/core/iomgr/alarm_test.c +++ b/test/core/iomgr/alarm_test.c @@ -113,7 +113,7 @@ static void test_grpc_alarm(void) { gpr_event_init(&arg.fcb_arg); grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg, - gpr_now()); + gpr_now(GPR_CLOCK_REALTIME)); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg.mu); @@ -165,7 +165,7 @@ static void test_grpc_alarm(void) { gpr_event_init(&arg2.fcb_arg); grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), - alarm_cb, &arg2, gpr_now()); + alarm_cb, &arg2, gpr_now(GPR_CLOCK_REALTIME)); grpc_alarm_cancel(&alarm_to_cancel); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 8198c24752..0cfba5fac8 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -254,7 +254,7 @@ static void read_and_write_test(grpc_endpoint_test_config config, gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!state.read_done || !state.write_done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); @@ -350,14 +350,14 @@ static void shutdown_during_write_test(grpc_endpoint_test_config config, deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!write_st.done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); grpc_endpoint_destroy(write_st.ep); gpr_mu_lock(GRPC_POLLSET_MU(g_pollset)); while (!read_st.done) { - GPR_ASSERT(gpr_time_cmp(gpr_now(), deadline) < 0); + GPR_ASSERT(gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0); grpc_pollset_work(g_pollset, deadline); } gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset)); diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c index b673c032b2..710cd725df 100644 --- a/test/core/iomgr/tcp_client_posix_test.c +++ b/test/core/iomgr/tcp_client_posix_test.c @@ -187,11 +187,12 @@ void test_times_out(void) { /* Make sure the event doesn't trigger early */ gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); while (gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(2)), - gpr_now()) > 0) { - int is_after_deadline = gpr_time_cmp(connect_deadline, gpr_now()) <= 0; + gpr_now(GPR_CLOCK_REALTIME)) > 0) { + int is_after_deadline = + gpr_time_cmp(connect_deadline, gpr_now(GPR_CLOCK_REALTIME)) <= 0; if (is_after_deadline && gpr_time_cmp(gpr_time_add(connect_deadline, gpr_time_from_seconds(1)), - gpr_now()) > 0) { + gpr_now(GPR_CLOCK_REALTIME)) > 0) { /* allow some slack before insisting that things be done */ } else { GPR_ASSERT(g_connections_complete == diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c index fb262711c0..110a2eb1d9 100644 --- a/test/core/iomgr/tcp_server_posix_test.c +++ b/test/core/iomgr/tcp_server_posix_test.c @@ -135,7 +135,7 @@ static void test_connect(int n) { gpr_log(GPR_DEBUG, "wait"); while (g_nconnects == nconnects_before && - gpr_time_cmp(deadline, gpr_now()) > 0) { + gpr_time_cmp(deadline, gpr_now(GPR_CLOCK_REALTIME)) > 0) { grpc_pollset_work(&g_pollset, deadline); } gpr_log(GPR_DEBUG, "wait done"); diff --git a/test/core/network_benchmarks/low_level_ping_pong.c b/test/core/network_benchmarks/low_level_ping_pong.c index 78a0eef1a2..0ce4bd4b25 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.c +++ b/test/core/network_benchmarks/low_level_ping_pong.c @@ -296,7 +296,7 @@ static void print_histogram(gpr_histogram *histogram) { } static double now(void) { - gpr_timespec tv = gpr_now(); + gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); return 1e9 * tv.tv_sec + tv.tv_nsec; } diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 241ec1ce4f..a34dcf07c4 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -568,7 +568,7 @@ void test_performance(void) { double write_time_micro = 0.0; int nrecords = 0; setup_test(0); - start_time = gpr_now(); + start_time = gpr_now(GPR_CLOCK_REALTIME); while (1) { void* record = census_log_start_write(write_size); if (record == NULL) { @@ -577,7 +577,7 @@ void test_performance(void) { census_log_end_write(record, write_size); nrecords++; } - write_time = gpr_time_sub(gpr_now(), start_time); + write_time = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start_time); write_time_micro = write_time.tv_sec * 1000000 + write_time.tv_nsec / 1000; census_log_shutdown(); printf( diff --git a/test/core/statistics/multiple_writers_circular_buffer_test.c b/test/core/statistics/multiple_writers_circular_buffer_test.c index a645e15918..56ada893ef 100644 --- a/test/core/statistics/multiple_writers_circular_buffer_test.c +++ b/test/core/statistics/multiple_writers_circular_buffer_test.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); test_multiple_writers_circular_log(); return 0; } diff --git a/test/core/statistics/multiple_writers_test.c b/test/core/statistics/multiple_writers_test.c index 84aef15c1a..e524927da6 100644 --- a/test/core/statistics/multiple_writers_test.c +++ b/test/core/statistics/multiple_writers_test.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); test_multiple_writers(); return 0; } diff --git a/test/core/statistics/performance_test.c b/test/core/statistics/performance_test.c index 3c1e28241e..3f0e080093 100644 --- a/test/core/statistics/performance_test.c +++ b/test/core/statistics/performance_test.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); test_performance(); return 0; } diff --git a/test/core/statistics/quick_test.c b/test/core/statistics/quick_test.c index 0e432314bb..c72ae77b98 100644 --- a/test/core/statistics/quick_test.c +++ b/test/core/statistics/quick_test.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); test_invalid_record_size(); test_end_write_with_different_size(); test_read_pending_record(); diff --git a/test/core/statistics/small_log_test.c b/test/core/statistics/small_log_test.c index c151b77f63..b26b95f639 100644 --- a/test/core/statistics/small_log_test.c +++ b/test/core/statistics/small_log_test.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) { grpc_test_init(argc, argv); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); test_small_log(); return 0; } diff --git a/test/core/statistics/window_stats_test.c b/test/core/statistics/window_stats_test.c index d893f7f792..1c66a87407 100644 --- a/test/core/statistics/window_stats_test.c +++ b/test/core/statistics/window_stats_test.c @@ -83,7 +83,7 @@ void empty_test(void) { result.statistic = ∑ census_window_stats_get_sums(stats, zero, &result); GPR_ASSERT(result.count == 0 && sum.value1 == 0 && sum.value2 == 0); - census_window_stats_get_sums(stats, gpr_now(), &result); + census_window_stats_get_sums(stats, gpr_now(GPR_CLOCK_REALTIME), &result); GPR_ASSERT(result.count == 0 && sum.value1 == 0 && sum.value2 == 0); census_window_stats_destroy(stats); } @@ -268,7 +268,7 @@ void rolling_time_test(void) { struct census_window_stats* stats = census_window_stats_create(1, &kMinInterval, 7, &kMyStatInfo); GPR_ASSERT(stats != NULL); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); for (i = 0; i < 100000; i++) { increment.tv_nsec = rand() % 100000000; /* up to 1/10th second */ when = gpr_time_add(when, increment); @@ -292,7 +292,7 @@ void infinite_interval_test(void) { gpr_timespec increment = {0, 0}; struct census_window_stats* stats = census_window_stats_create(1, &gpr_inf_future, 10, &kMyStatInfo); - srand(gpr_now().tv_nsec); + srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); for (i = 0; i < count; i++) { increment.tv_sec = rand() % 21600; /* 6 hours */ when = gpr_time_add(when, increment); diff --git a/test/core/support/cancellable_test.c b/test/core/support/cancellable_test.c index b2db1afc76..2f4b67a785 100644 --- a/test/core/support/cancellable_test.c +++ b/test/core/support/cancellable_test.c @@ -81,22 +81,23 @@ static void test(void) { GPR_ASSERT(!gpr_cancellable_is_cancelled(&t.cancel)); /* Test timeout on event wait for uncancelled gpr_cancellable */ - interval = gpr_now(); - gpr_event_cancellable_wait( - &t.ev, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), &t.cancel); - interval = gpr_time_sub(gpr_now(), interval); + interval = gpr_now(GPR_CLOCK_REALTIME); + gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000)), + &t.cancel); + interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); /* Test timeout on cv wait for uncancelled gpr_cancellable */ gpr_mu_lock(&t.mu); - interval = gpr_now(); + interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), - &t.cancel)) { + &t.cv, &t.mu, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cancel)) { } - interval = gpr_time_sub(gpr_now(), interval); + interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); GPR_ASSERT(gpr_time_cmp(interval, gpr_time_from_micros(500000)) >= 0); GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(2000000), interval) >= 0); gpr_mu_unlock(&t.mu); @@ -112,8 +113,8 @@ static void test(void) { /* Wait a second, and check that no threads have finished waiting. */ gpr_mu_lock(&t.mu); - gpr_cv_wait(&t.cv, &t.mu, - gpr_time_add(gpr_now(), gpr_time_from_micros(1000000))); + gpr_cv_wait(&t.cv, &t.mu, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000))); GPR_ASSERT(t.n == n); gpr_mu_unlock(&t.mu); @@ -129,21 +130,22 @@ static void test(void) { /* Test timeout on cv wait for cancelled gpr_cancellable */ gpr_mu_lock(&t.mu); - interval = gpr_now(); + interval = gpr_now(GPR_CLOCK_REALTIME); while (!gpr_cv_cancellable_wait( - &t.cv, &t.mu, - gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), - &t.cancel)) { + &t.cv, &t.mu, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000000)), + &t.cancel)) { } - interval = gpr_time_sub(gpr_now(), interval); + interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); gpr_mu_unlock(&t.mu); /* Test timeout on event wait for cancelled gpr_cancellable */ - interval = gpr_now(); - gpr_event_cancellable_wait( - &t.ev, gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)), &t.cancel); - interval = gpr_time_sub(gpr_now(), interval); + interval = gpr_now(GPR_CLOCK_REALTIME); + gpr_event_cancellable_wait(&t.ev, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000)), + &t.cancel); + interval = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), interval); GPR_ASSERT(gpr_time_cmp(gpr_time_from_micros(100000), interval) >= 0); gpr_mu_destroy(&t.mu); diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 44bc6ba471..99be5cdc90 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -242,12 +242,12 @@ static void test(const char *name, void (*body)(void *m), void (*extra)(void *m), int timeout_s) { gpr_int64 iterations = 1024; struct test *m; - gpr_timespec start = gpr_now(); + gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec time_taken; gpr_timespec deadline = gpr_time_add(start, gpr_time_from_micros(timeout_s * 1000000)); fprintf(stderr, "%s:", name); - while (gpr_time_cmp(gpr_now(), deadline) < 0) { + while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { iterations <<= 1; fprintf(stderr, " %ld", (long)iterations); m = test_new(10, iterations); @@ -265,7 +265,7 @@ static void test(const char *name, void (*body)(void *m), } test_destroy(m); } - time_taken = gpr_time_sub(gpr_now(), start); + time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start); fprintf(stderr, " done %ld.%09d s\n", (long)time_taken.tv_sec, (int)time_taken.tv_nsec); } @@ -323,7 +323,8 @@ static void inc_with_1ms_delay(void *v /*=m*/) { for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; gpr_mu_lock(&m->mu); - deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(1000)); + deadline = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); while (!gpr_cv_wait(&m->cv, &m->mu, deadline)) { } m->counter++; @@ -339,7 +340,8 @@ static void inc_with_1ms_delay_event(void *v /*=m*/) { gpr_int64 i; for (i = 0; i != m->iterations; i++) { gpr_timespec deadline; - deadline = gpr_time_add(gpr_now(), gpr_time_from_micros(1000)); + deadline = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(1000)); GPR_ASSERT(gpr_event_wait(&m->event, deadline) == NULL); gpr_mu_lock(&m->mu); m->counter++; @@ -382,9 +384,9 @@ static void consumer(void *v /*=m*/) { gpr_mu_lock(&m->mu); m->counter = n; gpr_mu_unlock(&m->mu); - GPR_ASSERT( - !queue_remove(&m->q, &value, - gpr_time_add(gpr_now(), gpr_time_from_micros(1000000)))); + GPR_ASSERT(!queue_remove(&m->q, &value, + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000000)))); mark_thread_done(m); } diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index d1be348baf..177adbebc2 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -69,7 +69,7 @@ static void test_wait_empty(void) { LOG_TEST("test_wait_empty"); cc = grpc_completion_queue_create(); - GPR_ASSERT(grpc_completion_queue_next(cc, gpr_now()).type == + GPR_ASSERT(grpc_completion_queue_next(cc, gpr_now(GPR_CLOCK_REALTIME)).type == GRPC_QUEUE_TIMEOUT); shutdown_and_destroy(cc); } diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index 0b3c54373d..3218953166 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -52,11 +52,11 @@ extern "C" { (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR) #define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(), \ + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x))) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(), \ +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), \ gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x))) #ifndef GRPC_TEST_CUSTOM_PICK_PORT @@ -69,4 +69,4 @@ void grpc_test_init(int argc, char **argv); } #endif /* __cplusplus */ -#endif /* GRPC_TEST_CORE_UTIL_TEST_CONFIG_H */ +#endif /* GRPC_TEST_CORE_UTIL_TEST_CONFIG_H */ diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 3791d15220..f0d9f75214 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -115,15 +115,15 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { } while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( - gpr_now(), + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(request->param().client_cancel_after_us()))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( - gpr_now(), - gpr_time_from_micros(request->param().server_cancel_after_us()))); + gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(request->param().server_cancel_after_us()))); return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); @@ -527,7 +527,8 @@ TEST_F(End2endTest, BadCredentials) { } void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_micros(delay_us))); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(delay_us))); while (!service->signal_client()) { } context->TryCancel(); diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index 3fdae9bc07..4d4d590bdd 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -84,7 +84,8 @@ class ServiceImpl GRPC_FINAL gpr_log(GPR_INFO, "recv msg %s", request.message().c_str()); response.set_message(request.message()); stream->Write(response); - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(1))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); } return Status::OK; } @@ -98,7 +99,8 @@ class ServiceImpl GRPC_FINAL msg << "Hello " << i; response.set_message(msg.str()); if (!writer->Write(response)) break; - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(1))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1))); } return Status::OK; } @@ -145,7 +147,8 @@ class CrashTest : public ::testing::Test { TEST_F(CrashTest, ResponseStream) { auto server = CreateServerAndClient("response"); - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneResponseStream()); @@ -154,7 +157,8 @@ TEST_F(CrashTest, ResponseStream) { TEST_F(CrashTest, BidiStream) { auto server = CreateServerAndClient("bidi"); - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); KillClient(); server->Shutdown(); GPR_ASSERT(HadOneBidiStream()); diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 0b43dfd106..0b4d942566 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -96,14 +96,14 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { } while (!context->IsCancelled()) { gpr_sleep_until(gpr_time_add( - gpr_now(), + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(request->param().client_cancel_after_us()))); } return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( - gpr_now(), + gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(request->param().server_cancel_after_us()))); return Status::CANCELLED; } else { diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index c8cc11e6ab..5597bcd549 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -185,7 +185,7 @@ std::unique_ptr<ScenarioResult> RunScenario( // Let everything warmup gpr_log(GPR_INFO, "Warming up"); - gpr_timespec start = gpr_now(); + gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); gpr_sleep_until(gpr_time_add(start, gpr_time_from_seconds(warmup_seconds))); // Start a run diff --git a/test/cpp/qps/timer.cc b/test/cpp/qps/timer.cc index d1b6bc1e55..07289f699b 100644 --- a/test/cpp/qps/timer.cc +++ b/test/cpp/qps/timer.cc @@ -41,7 +41,7 @@ Timer::Timer() : start_(Sample()) {} double Timer::Now() { - auto ts = gpr_now(); + auto ts = gpr_now(GPR_CLOCK_REALTIME); return ts.tv_sec + 1e-9 * ts.tv_nsec; } diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index 14a8b0b089..2bc0a56970 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -57,7 +57,8 @@ static void RunServer() { QpsWorker worker(FLAGS_driver_port, FLAGS_server_port); while (!got_sigint) { - gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5))); + gpr_sleep_until( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5))); } } |