Skip to content

Commit

Permalink
Merge pull request grpc#784 from ctiller/timeout
Browse files Browse the repository at this point in the history
Introduce slowdown factor for unit test deadlines
  • Loading branch information
yang-g committed Feb 26, 2015
2 parents c33731a + c1f1162 commit 0e32857
Show file tree
Hide file tree
Showing 96 changed files with 384 additions and 397 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ LDXX_valgrind = g++
CPPFLAGS_valgrind = -O0
OPENSSL_CFLAGS_valgrind = -DPURIFY
LDFLAGS_valgrind =
DEFINES_valgrind = _DEBUG DEBUG
DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_FACTOR=20

VALID_CONFIG_tsan = 1
REQUIRE_CUSTOM_LIBRARIES_tsan = 1
Expand All @@ -87,7 +87,7 @@ LD_tsan = clang
LDXX_tsan = clang++
CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
LDFLAGS_tsan = -fsanitize=thread
DEFINES_tsan = NDEBUG
DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=10

VALID_CONFIG_asan = 1
REQUIRE_CUSTOM_LIBRARIES_asan = 1
Expand All @@ -97,7 +97,7 @@ LD_asan = clang
LDXX_asan = clang++
CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
LDFLAGS_asan = -fsanitize=address
DEFINES_asan = NDEBUG
DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=5

VALID_CONFIG_msan = 1
REQUIRE_CUSTOM_LIBRARIES_msan = 1
Expand All @@ -108,7 +108,7 @@ LDXX_msan = clang++-libc++
CPPFLAGS_msan = -O1 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
OPENSSL_CFLAGS_msan = -DPURIFY
LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
DEFINES_msan = NDEBUG
DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=20

VALID_CONFIG_ubsan = 1
REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
Expand All @@ -119,7 +119,7 @@ LDXX_ubsan = clang++
CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
OPENSSL_CFLAGS_ubsan = -DPURIFY
LDFLAGS_ubsan = -fsanitize=undefined
DEFINES_ubsan = NDEBUG
DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=10

VALID_CONFIG_gcov = 1
CC_gcov = gcc
Expand Down
10 changes: 5 additions & 5 deletions templates/Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ LDXX_valgrind = g++
CPPFLAGS_valgrind = -O0
OPENSSL_CFLAGS_valgrind = -DPURIFY
LDFLAGS_valgrind =
DEFINES_valgrind = _DEBUG DEBUG
DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_FACTOR=20

VALID_CONFIG_tsan = 1
REQUIRE_CUSTOM_LIBRARIES_tsan = 1
Expand All @@ -104,7 +104,7 @@ LD_tsan = clang
LDXX_tsan = clang++
CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
LDFLAGS_tsan = -fsanitize=thread
DEFINES_tsan = NDEBUG
DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=10

VALID_CONFIG_asan = 1
REQUIRE_CUSTOM_LIBRARIES_asan = 1
Expand All @@ -114,7 +114,7 @@ LD_asan = clang
LDXX_asan = clang++
CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
LDFLAGS_asan = -fsanitize=address
DEFINES_asan = NDEBUG
DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=5

VALID_CONFIG_msan = 1
REQUIRE_CUSTOM_LIBRARIES_msan = 1
Expand All @@ -125,7 +125,7 @@ LDXX_msan = clang++-libc++
CPPFLAGS_msan = -O1 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
OPENSSL_CFLAGS_msan = -DPURIFY
LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
DEFINES_msan = NDEBUG
DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=20

VALID_CONFIG_ubsan = 1
REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
Expand All @@ -136,7 +136,7 @@ LDXX_ubsan = clang++
CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
OPENSSL_CFLAGS_ubsan = -DPURIFY
LDFLAGS_ubsan = -fsanitize=undefined
DEFINES_ubsan = NDEBUG
DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_FACTOR=10

VALID_CONFIG_gcov = 1
CC_gcov = gcc
Expand Down
8 changes: 4 additions & 4 deletions test/core/channel/channel_stack_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ static void channel_func(grpc_channel_element *elem,
}

static void test_create_channel_stack(void) {
const grpc_channel_filter
filter = {call_func, channel_func, sizeof(int),
call_init_func, call_destroy_func, sizeof(int),
channel_init_func, channel_destroy_func, "some_test_filter" };
const grpc_channel_filter filter = {
call_func, channel_func, sizeof(int),
call_init_func, call_destroy_func, sizeof(int),
channel_init_func, channel_destroy_func, "some_test_filter"};
const grpc_channel_filter *filters = &filter;
grpc_channel_stack *channel_stack;
grpc_call_stack *call_stack;
Expand Down
14 changes: 7 additions & 7 deletions test/core/channel/metadata_buffer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ static void init_channel_elem(grpc_channel_element *elem,
static void destroy_channel_elem(grpc_channel_element *elem) {}

static const grpc_channel_filter top_filter = {
fail_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "top_filter" };
fail_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "top_filter"};

static const grpc_channel_filter bottom_filter = {
expect_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "bottom_filter" };
expect_call_op, fail_channel_op, sizeof(size_t),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "bottom_filter"};

static const grpc_channel_filter *filters[2] = {&top_filter, &bottom_filter};

Expand Down Expand Up @@ -149,7 +149,7 @@ static void test_case(size_t key_prefix_len, size_t value_prefix_len,
op.flags = i;
op.data.metadata = grpc_mdelem_from_slices(mdctx, key, value);
op.done_cb = do_nothing;
op.user_data = (void *)(gpr_uintptr)i;
op.user_data = (void *)(gpr_uintptr) i;

grpc_metadata_buffer_queue(&buffer, &op);
}
Expand Down
5 changes: 2 additions & 3 deletions test/core/echo/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ int main(int argc, char **argv) {

GPR_ASSERT(argc == 2);
channel = grpc_channel_create(argv[1], NULL);
call = grpc_channel_create_call_old(
channel, "/foo", "localhost",
gpr_time_add(gpr_time_from_seconds(5), gpr_now()));
call = grpc_channel_create_call_old(channel, "/foo", "localhost",
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5));
GPR_ASSERT(grpc_call_invoke_old(call, cq, (void *)1, (void *)1, 0) ==
GRPC_CALL_OK);

Expand Down
2 changes: 1 addition & 1 deletion test/core/echo/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ 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_time_from_seconds(1)));
if (!ev) continue;
s = ev->tag;
switch (ev->type) {
Expand Down
9 changes: 4 additions & 5 deletions test/core/end2end/cq_verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ static int has_metadata(const grpc_metadata *md, size_t count, const char *key,
return 0;
}

int contains_metadata(grpc_metadata_array *array, const char *key, const char *value) {
int contains_metadata(grpc_metadata_array *array, const char *key,
const char *value) {
return has_metadata(array->metadata, array->count, key, value);
}

Expand Down Expand Up @@ -327,8 +328,7 @@ static void fail_no_event_received(cq_verifier *v) {
}

void cq_verify(cq_verifier *v) {
gpr_timespec deadline =
gpr_time_add(gpr_now(), gpr_time_from_micros(10 * GPR_US_PER_SEC));
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
grpc_event *ev;
expectation *e;
char *s;
Expand Down Expand Up @@ -371,8 +371,7 @@ void cq_verify(cq_verifier *v) {
}

void cq_verify_empty(cq_verifier *v) {
gpr_timespec deadline =
gpr_time_add(gpr_now(), gpr_time_from_micros(3000000));
gpr_timespec deadline = gpr_time_add(gpr_now(), gpr_time_from_seconds(1));
grpc_event *ev;

GPR_ASSERT(v->expect.next == &v->expect && "expectation queue must be empty");
Expand Down
1 change: 1 addition & 0 deletions test/core/end2end/cq_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define __GRPC_TEST_END2END_CQ_VERIFIER_H__

#include <grpc/grpc.h>
#include "test/core/util/test_config.h"

/* A cq_verifier can verify that expected events arrive in a timely fashion
on a single completion queue */
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/dualstack_socket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
static void *tag(gpr_intptr i) { return (void *)i; }

static gpr_timespec ms_from_now(int ms) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_MS * ms));
return GRPC_TIMEOUT_MILLIS_TO_DEADLINE(ms);
}

static void drain_cq(grpc_completion_queue *cq) {
Expand Down
3 changes: 2 additions & 1 deletion test/core/end2end/fixtures/chttp2_fake_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static grpc_end2end_test_config configs[] = {
chttp2_create_fixture_secure_fullstack,
chttp2_init_client_fake_secure_fullstack,
chttp2_init_server_fake_secure_fullstack,
chttp2_tear_down_secure_fullstack}, };
chttp2_tear_down_secure_fullstack},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
3 changes: 2 additions & 1 deletion test/core/end2end/fixtures/chttp2_fullstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f) {
static grpc_end2end_test_config configs[] = {
{"chttp2/fullstack", FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION,
chttp2_create_fixture_fullstack, chttp2_init_client_fullstack,
chttp2_init_server_fullstack, chttp2_tear_down_fullstack}, };
chttp2_init_server_fullstack, chttp2_tear_down_fullstack},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
6 changes: 3 additions & 3 deletions test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {

static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
grpc_credentials *ssl_creds =
grpc_ssl_credentials_create(NULL, NULL);
grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.fr"}};
Expand All @@ -128,7 +127,8 @@ static grpc_end2end_test_config configs[] = {
chttp2_create_fixture_secure_fullstack,
chttp2_init_client_simple_ssl_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack}, };
chttp2_tear_down_secure_fullstack},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static grpc_end2end_test_config configs[] = {
chttp2_create_fixture_secure_fullstack,
chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack,
chttp2_init_server_simple_ssl_secure_fullstack,
chttp2_tear_down_secure_fullstack}, };
chttp2_tear_down_secure_fullstack},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
3 changes: 2 additions & 1 deletion test/core/end2end/fixtures/chttp2_socket_pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
static grpc_end2end_test_config configs[] = {
{"chttp2/socketpair", 0, chttp2_create_fixture_socketpair,
chttp2_init_client_socketpair, chttp2_init_server_socketpair,
chttp2_tear_down_socketpair}, };
chttp2_tear_down_socketpair},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
static grpc_end2end_test_config configs[] = {
{"chttp2/socketpair_one_byte_at_a_time", 0,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair}, };
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
};

int main(int argc, char **argv) {
size_t i;
Expand Down
3 changes: 1 addition & 2 deletions test/core/end2end/no_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ static void *tag(gpr_intptr i) { return (void *)i; }
int main(int argc, char **argv) {
grpc_channel *chan;
grpc_call *call;
gpr_timespec timeout = gpr_time_from_seconds(4);
gpr_timespec deadline = gpr_time_add(gpr_now(), timeout);
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
grpc_completion_queue *cq;
cq_verifier *cqv;
grpc_event *ev;
Expand Down
10 changes: 4 additions & 6 deletions test/core/end2end/tests/cancel_after_accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down Expand Up @@ -163,11 +163,9 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));

GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
&call_details,
&request_metadata_recv,
f.server_cq,
tag(2)));
GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
f.server, &s, &call_details,
&request_metadata_recv, f.server_cq, tag(2)));
cq_expect_completion(v_server, tag(2), GRPC_OP_OK);
cq_verify(v_server);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down Expand Up @@ -121,8 +121,8 @@ static void test_cancel_after_accept_and_writes_closed(
grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));

GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo",
"foo.test.google.fr", deadline, NULL);
cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "foo.test.google.fr",
deadline, NULL);
cq_verify(v_server);

GPR_ASSERT(GRPC_CALL_OK ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/cancel_after_accept_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/cancel_after_invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/cancel_after_invoke_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
5 changes: 3 additions & 2 deletions test/core/end2end/tests/cancel_before_invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down Expand Up @@ -103,7 +103,8 @@ static void end_test(grpc_end2end_test_fixture *f) {
}

/* Cancel before invoke */
static void test_cancel_before_invoke(grpc_end2end_test_config config, int test_ops) {
static void test_cancel_before_invoke(grpc_end2end_test_config config,
int test_ops) {
grpc_op ops[6];
grpc_op *op;
grpc_call *c;
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/cancel_before_invoke_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/cancel_in_a_vacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
}

static gpr_timespec n_seconds_time(int n) {
return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
}

static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Expand Down
Loading

0 comments on commit 0e32857

Please sign in to comment.