From 8ad8a41a84bf7e17c6e9a5fd8d975370a222c0fe Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 25 Feb 2015 08:36:40 -0800 Subject: Introduce slowdown factor for unit test deadlines Dramatically lowers (eliminates maybe?) false negatives from ?SAN runs. --- test/core/util/port_posix.c | 7 ++++--- test/core/util/test_config.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'test/core/util') diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index f0fe1a0e7c..0b6e7918ac 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -113,11 +113,12 @@ int grpc_pick_unused_port(void) { /* Type of port to first pick in next iteration */ int is_tcp = 1; - int try = 0; + int try + = 0; for (;;) { - int port = - try < NUM_RANDOM_PORTS_TO_PICK ? rand() % (65536 - 30000) + 30000 : 0; + int port = try + < NUM_RANDOM_PORTS_TO_PICK ? rand() % (65536 - 30000) + 30000 : 0; if (!is_port_available(&port, is_tcp)) { continue; } diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index b97fbfa613..74c2a3cf1b 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -34,10 +34,24 @@ #ifndef __GRPC_TEST_UTIL_TEST_CONFIG_H__ #define __GRPC_TEST_UTIL_TEST_CONFIG_H__ +#include + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#ifndef GRPC_TEST_SLOWDOWN_FACTOR +#define GRPC_TEST_SLOWDOWN_FACTOR 1.0 +#endif + +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e6 * (x))) + +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add(gpr_now(), \ + gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x))) + void grpc_test_init(int argc, char **argv); #ifdef __cplusplus -- cgit v1.2.3