diff options
author | Craig Tiller <ctiller@google.com> | 2015-11-17 16:15:03 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-11-17 16:15:03 -0800 |
commit | 47b48459f3802af8aa7d5e4cbe2d4fda5cd16449 (patch) | |
tree | b584a48d447077a4729b79eb20ff590ef6eebf88 | |
parent | 892c34a067bef8064a8de587c14198398f4fdc73 (diff) |
Robustness work for lb_policies_test
-rw-r--r-- | src/core/client_config/subchannel.c | 15 | ||||
-rw-r--r-- | test/core/client_config/lb_policies_test.c | 17 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c index 49c2cf9a19..b15a9033af 100644 --- a/src/core/client_config/subchannel.c +++ b/src/core/client_config/subchannel.c @@ -697,10 +697,25 @@ static double generate_uniform_random_number(grpc_subchannel *c) { /* Update backoff_delta and next_attempt in subchannel */ static void update_reconnect_parameters(grpc_subchannel *c) { + size_t i; gpr_int32 backoff_delta_millis, jitter; gpr_int32 max_backoff_millis = GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000; double jitter_range; + + if (c->args) { + for (i = 0; i < c->args->num_args; i++) { + if (0 == strcmp(c->args->args[i].key, + "grpc.testing.fixed_reconnect_backoff")) { + GPR_ASSERT(c->args->args[i].type == GRPC_ARG_INTEGER); + c->next_attempt = gpr_time_add( + gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_millis(c->args->args[i].value.integer, GPR_TIMESPAN)); + return; + } + } + } + backoff_delta_millis = (gpr_int32)(gpr_time_to_millis(c->backoff_delta) * GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER); diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c index 281d2b2ee1..4a469564bd 100644 --- a/test/core/client_config/lb_policies_test.c +++ b/test/core/client_config/lb_policies_test.c @@ -269,7 +269,7 @@ int *perform_request(servers_fixture *f, grpc_channel *client, } memset(s_valid, 0, f->num_servers * sizeof(int)); - deadline = n_millis_time(1000); + deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", "foo.test.google.fr", deadline, NULL); GPR_ASSERT(c); @@ -304,7 +304,8 @@ int *perform_request(servers_fixture *f, grpc_channel *client, grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); s_idx = -1; - while ((ev = grpc_completion_queue_next(f->cq, n_millis_time(300), NULL)) + while ((ev = grpc_completion_queue_next( + f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2), NULL)) .type != GRPC_QUEUE_TIMEOUT) { GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); read_tag = ((int)(gpr_intptr)ev.tag); @@ -316,6 +317,7 @@ int *perform_request(servers_fixture *f, grpc_channel *client, s_idx = read_tag - 1000; s_valid[s_idx] = 1; connection_sequence[iter_num] = s_idx; + break; } else if (read_tag == 1) { gpr_log(GPR_DEBUG, "client timed out"); GPR_ASSERT(ev.success); @@ -453,6 +455,8 @@ void run_spec(const test_spec *spec) { int *actual_connection_sequence; request_data rdata; servers_fixture *f; + grpc_channel_args args; + grpc_arg arg; rdata.call_details = gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); f = setup_servers("127.0.0.1", &rdata, spec->num_servers); @@ -462,7 +466,14 @@ void run_spec(const test_spec *spec) { f->num_servers, ",", NULL); gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", servers_hostports_str); - client = grpc_insecure_channel_create(client_hostport, NULL, NULL); + + arg.type = GRPC_ARG_INTEGER; + arg.key = "grpc.testing.fixed_reconnect_backoff"; + arg.value.integer = 100; + args.num_args = 1; + args.args = &arg; + + client = grpc_insecure_channel_create(client_hostport, &args, NULL); gpr_log(GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, servers_hostports_str, client_hostport); |