From d3b83f4693026ec306397da371ce7b4cd9d5f892 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 15 Dec 2016 18:07:24 -0800 Subject: [PATCH] Deflake lb_policies_test --- test/core/client_channel/lb_policies_test.c | 32 ++++++++++----------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index 6e4058fc214..016610763cf 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -241,6 +241,8 @@ static request_sequences request_sequences_create(size_t n) { res.n = n; res.connections = gpr_malloc(sizeof(*res.connections) * n); res.connectivity_states = gpr_malloc(sizeof(*res.connectivity_states) * n); + memset(res.connections, 0, sizeof(*res.connections) * n); + memset(res.connectivity_states, 0, sizeof(*res.connectivity_states) * n); return res; } @@ -782,17 +784,15 @@ static void verify_total_carnage_round_robin(const servers_fixture *f, } } - /* no server is ever available. The persistent state is TRANSIENT_FAILURE. May - * also be CONNECTING if, under load, this check took too long to run and some - * subchannel already transitioned to retrying. */ + /* No server is ever available. There should be no READY states (or SHUTDOWN). + * Note that all other states (IDLE, CONNECTING, TRANSIENT_FAILURE) are still + * possible, as the policy transitions while attempting to reconnect. */ for (size_t i = 0; i < sequences->n; i++) { const grpc_connectivity_state actual = sequences->connectivity_states[i]; - if (actual != GRPC_CHANNEL_TRANSIENT_FAILURE && - actual != GRPC_CHANNEL_CONNECTING) { + if (actual == GRPC_CHANNEL_READY || actual == GRPC_CHANNEL_SHUTDOWN) { gpr_log(GPR_ERROR, - "CONNECTIVITY STATUS SEQUENCE FAILURE: expected " - "GRPC_CHANNEL_TRANSIENT_FAILURE or GRPC_CHANNEL_CONNECTING, got " - "'%s' at iteration #%d", + "CONNECTIVITY STATUS SEQUENCE FAILURE: got unexpected state " + "'%s' at iteration #%d.", grpc_connectivity_state_name(actual), (int)i); abort(); } @@ -841,17 +841,15 @@ static void verify_partial_carnage_round_robin( abort(); } - /* ... and that the last one should be TRANSIENT_FAILURE, after all servers - * are gone. May also be CONNECTING if, under load, this check took too long - * to run and the subchannel already transitioned to retrying. */ + /* ... and that the last one shouldn't be READY (or SHUTDOWN): all servers are + * gone. It may be all other states (IDLE, CONNECTING, TRANSIENT_FAILURE), as + * the policy transitions while attempting to reconnect. */ actual = sequences->connectivity_states[num_iters - 1]; for (i = 0; i < sequences->n; i++) { - if (actual != GRPC_CHANNEL_TRANSIENT_FAILURE && - actual != GRPC_CHANNEL_CONNECTING) { + if (actual == GRPC_CHANNEL_READY || actual == GRPC_CHANNEL_SHUTDOWN) { gpr_log(GPR_ERROR, - "CONNECTIVITY STATUS SEQUENCE FAILURE: expected " - "GRPC_CHANNEL_TRANSIENT_FAILURE or GRPC_CHANNEL_CONNECTING, got " - "'%s' at iteration #%d", + "CONNECTIVITY STATUS SEQUENCE FAILURE: got unexpected state " + "'%s' at iteration #%d.", grpc_connectivity_state_name(actual), (int)i); abort(); } @@ -948,8 +946,8 @@ int main(int argc, char **argv) { const size_t NUM_ITERS = 10; const size_t NUM_SERVERS = 4; - grpc_test_init(argc, argv); grpc_init(); + grpc_test_init(argc, argv); grpc_tracer_set_enabled("round_robin", 1); GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist",