diff options
author | Craig Tiller <ctiller@google.com> | 2015-09-22 10:42:19 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-09-22 10:42:19 -0700 |
commit | 45724b35e411fef7c5da66a74c78428c11d56843 (patch) | |
tree | 9264034aca675c89444e02f72ef58e67d7043604 /test/core/client_config | |
parent | 298751c1195523ef6228595043b583c3a6270e08 (diff) |
indent pass to get logical source lines on one physical line
Diffstat (limited to 'test/core/client_config')
-rw-r--r-- | test/core/client_config/lb_policies_test.c | 879 | ||||
-rw-r--r-- | test/core/client_config/uri_parser_test.c | 74 |
2 files changed, 486 insertions, 467 deletions
diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c index 411e96598a..931bdef017 100644 --- a/test/core/client_config/lb_policies_test.c +++ b/test/core/client_config/lb_policies_test.c @@ -50,7 +50,8 @@ #include "test/core/util/port.h" #include "test/core/end2end/cq_verifier.h" -typedef struct servers_fixture { +typedef struct servers_fixture +{ size_t num_servers; grpc_server **servers; grpc_call **server_calls; @@ -59,10 +60,10 @@ typedef struct servers_fixture { grpc_metadata_array *request_metadata_recv; } servers_fixture; -typedef void (*verifier_fn)(const servers_fixture *, grpc_channel *, - const int *, const size_t); +typedef void (*verifier_fn) (const servers_fixture *, grpc_channel *, const int *, const size_t); -typedef struct test_spec { +typedef struct test_spec +{ size_t num_iters; size_t num_servers; @@ -75,145 +76,170 @@ typedef struct test_spec { } test_spec; -static void test_spec_reset(test_spec *spec) { +static void +test_spec_reset (test_spec * spec) +{ size_t i, j; - for (i = 0; i < spec->num_iters; i++) { - for (j = 0; j < spec->num_servers; j++) { - spec->kill_at[i][j] = 0; - spec->revive_at[i][j] = 0; + for (i = 0; i < spec->num_iters; i++) + { + for (j = 0; j < spec->num_servers; j++) + { + spec->kill_at[i][j] = 0; + spec->revive_at[i][j] = 0; + } } - } } -static test_spec *test_spec_create(size_t num_iters, size_t num_servers) { +static test_spec * +test_spec_create (size_t num_iters, size_t num_servers) +{ test_spec *spec; size_t i; - spec = gpr_malloc(sizeof(test_spec)); + spec = gpr_malloc (sizeof (test_spec)); spec->num_iters = num_iters; spec->num_servers = num_servers; - spec->kill_at = gpr_malloc(sizeof(int *) * num_iters); - spec->revive_at = gpr_malloc(sizeof(int *) * num_iters); - for (i = 0; i < num_iters; i++) { - spec->kill_at[i] = gpr_malloc(sizeof(int) * num_servers); - spec->revive_at[i] = gpr_malloc(sizeof(int) * num_servers); - } - - test_spec_reset(spec); + spec->kill_at = gpr_malloc (sizeof (int *) * num_iters); + spec->revive_at = gpr_malloc (sizeof (int *) * num_iters); + for (i = 0; i < num_iters; i++) + { + spec->kill_at[i] = gpr_malloc (sizeof (int) * num_servers); + spec->revive_at[i] = gpr_malloc (sizeof (int) * num_servers); + } + + test_spec_reset (spec); return spec; } -static void test_spec_destroy(test_spec *spec) { +static void +test_spec_destroy (test_spec * spec) +{ size_t i; - for (i = 0; i < spec->num_iters; i++) { - gpr_free(spec->kill_at[i]); - gpr_free(spec->revive_at[i]); - } + for (i = 0; i < spec->num_iters; i++) + { + gpr_free (spec->kill_at[i]); + gpr_free (spec->revive_at[i]); + } - gpr_free(spec->kill_at); - gpr_free(spec->revive_at); + gpr_free (spec->kill_at); + gpr_free (spec->revive_at); - gpr_free(spec); + gpr_free (spec); } -static void *tag(gpr_intptr t) { return (void *)t; } +static void * +tag (gpr_intptr t) +{ + return (void *) t; +} -static gpr_timespec n_seconds_time(int n) { - return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +static gpr_timespec +n_seconds_time (int n) +{ + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE (n); } -static void drain_cq(grpc_completion_queue *cq) { +static void +drain_cq (grpc_completion_queue * cq) +{ grpc_event ev; - do { - ev = grpc_completion_queue_next(cq, n_seconds_time(5), NULL); - } while (ev.type != GRPC_QUEUE_SHUTDOWN); + do + { + ev = grpc_completion_queue_next (cq, n_seconds_time (5), NULL); + } + while (ev.type != GRPC_QUEUE_SHUTDOWN); } -static void kill_server(const servers_fixture *f, size_t i) { - gpr_log(GPR_INFO, "KILLING SERVER %d", i); - GPR_ASSERT(f->servers[i] != NULL); - grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT(grpc_completion_queue_pluck( - f->cq, tag(10000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL) - .type == GRPC_OP_COMPLETE); - grpc_server_destroy(f->servers[i]); +static void +kill_server (const servers_fixture * f, size_t i) +{ + gpr_log (GPR_INFO, "KILLING SERVER %d", i); + GPR_ASSERT (f->servers[i] != NULL); + grpc_server_shutdown_and_notify (f->servers[i], f->cq, tag (10000)); + GPR_ASSERT (grpc_completion_queue_pluck (f->cq, tag (10000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE (5), NULL).type == GRPC_OP_COMPLETE); + grpc_server_destroy (f->servers[i]); f->servers[i] = NULL; } -static void revive_server(const servers_fixture *f, size_t i) { +static void +revive_server (const servers_fixture * f, size_t i) +{ int got_port; - gpr_log(GPR_INFO, "RAISE AGAIN SERVER %d", i); - GPR_ASSERT(f->servers[i] == NULL); - f->servers[i] = grpc_server_create(NULL, NULL); - grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); - GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( - f->servers[i], f->servers_hostports[i])) > 0); - grpc_server_start(f->servers[i]); + gpr_log (GPR_INFO, "RAISE AGAIN SERVER %d", i); + GPR_ASSERT (f->servers[i] == NULL); + f->servers[i] = grpc_server_create (NULL, NULL); + grpc_server_register_completion_queue (f->servers[i], f->cq, NULL); + GPR_ASSERT ((got_port = grpc_server_add_insecure_http2_port (f->servers[i], f->servers_hostports[i])) > 0); + grpc_server_start (f->servers[i]); } -static servers_fixture *setup_servers(const char *server_host, - const size_t num_servers) { - servers_fixture *f = gpr_malloc(sizeof(servers_fixture)); +static servers_fixture * +setup_servers (const char *server_host, const size_t num_servers) +{ + servers_fixture *f = gpr_malloc (sizeof (servers_fixture)); int *ports; int got_port; size_t i; f->num_servers = num_servers; - f->server_calls = gpr_malloc(sizeof(grpc_call *) * num_servers); - f->request_metadata_recv = - gpr_malloc(sizeof(grpc_metadata_array) * num_servers); + f->server_calls = gpr_malloc (sizeof (grpc_call *) * num_servers); + f->request_metadata_recv = gpr_malloc (sizeof (grpc_metadata_array) * num_servers); /* Create servers. */ - ports = gpr_malloc(sizeof(int *) * num_servers); - f->servers = gpr_malloc(sizeof(grpc_server *) * num_servers); - f->servers_hostports = gpr_malloc(sizeof(char *) * num_servers); - f->cq = grpc_completion_queue_create(NULL); - for (i = 0; i < num_servers; i++) { - ports[i] = grpc_pick_unused_port_or_die(); - - gpr_join_host_port(&f->servers_hostports[i], server_host, ports[i]); - - f->servers[i] = grpc_server_create(NULL, NULL); - grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); - GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( - f->servers[i], f->servers_hostports[i])) > 0); - GPR_ASSERT(ports[i] == got_port); - grpc_server_start(f->servers[i]); - } - gpr_free(ports); + ports = gpr_malloc (sizeof (int *) * num_servers); + f->servers = gpr_malloc (sizeof (grpc_server *) * num_servers); + f->servers_hostports = gpr_malloc (sizeof (char *) * num_servers); + f->cq = grpc_completion_queue_create (NULL); + for (i = 0; i < num_servers; i++) + { + ports[i] = grpc_pick_unused_port_or_die (); + + gpr_join_host_port (&f->servers_hostports[i], server_host, ports[i]); + + f->servers[i] = grpc_server_create (NULL, NULL); + grpc_server_register_completion_queue (f->servers[i], f->cq, NULL); + GPR_ASSERT ((got_port = grpc_server_add_insecure_http2_port (f->servers[i], f->servers_hostports[i])) > 0); + GPR_ASSERT (ports[i] == got_port); + grpc_server_start (f->servers[i]); + } + gpr_free (ports); return f; } -static void teardown_servers(servers_fixture *f) { +static void +teardown_servers (servers_fixture * f) +{ size_t i; /* Destroy server. */ - for (i = 0; i < f->num_servers; i++) { - if (f->servers[i] == NULL) continue; - grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT(grpc_completion_queue_pluck( - f->cq, tag(10000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL) - .type == GRPC_OP_COMPLETE); - grpc_server_destroy(f->servers[i]); - } - grpc_completion_queue_shutdown(f->cq); - drain_cq(f->cq); - grpc_completion_queue_destroy(f->cq); - - gpr_free(f->servers); - - for (i = 0; i < f->num_servers; i++) { - gpr_free(f->servers_hostports[i]); - } - - gpr_free(f->servers_hostports); - gpr_free(f->request_metadata_recv); - gpr_free(f->server_calls); - gpr_free(f); + for (i = 0; i < f->num_servers; i++) + { + if (f->servers[i] == NULL) + continue; + grpc_server_shutdown_and_notify (f->servers[i], f->cq, tag (10000)); + GPR_ASSERT (grpc_completion_queue_pluck (f->cq, tag (10000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE (5), NULL).type == GRPC_OP_COMPLETE); + grpc_server_destroy (f->servers[i]); + } + grpc_completion_queue_shutdown (f->cq); + drain_cq (f->cq); + grpc_completion_queue_destroy (f->cq); + + gpr_free (f->servers); + + for (i = 0; i < f->num_servers; i++) + { + gpr_free (f->servers_hostports[i]); + } + + gpr_free (f->servers_hostports); + gpr_free (f->request_metadata_recv); + gpr_free (f->server_calls); + gpr_free (f); } /** Returns connection sequence (server indices), which must be freed */ -int *perform_request(servers_fixture *f, grpc_channel *client, - const test_spec *spec) { +int * +perform_request (servers_fixture * f, grpc_channel * client, const test_spec * spec) +{ grpc_call *c; int s_idx; int *s_valid; @@ -232,157 +258,160 @@ int *perform_request(servers_fixture *f, grpc_channel *client, grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; - s_valid = gpr_malloc(sizeof(int) * f->num_servers); - call_details = gpr_malloc(sizeof(grpc_call_details) * f->num_servers); - connection_sequence = gpr_malloc(sizeof(int) * spec->num_iters); + s_valid = gpr_malloc (sizeof (int) * f->num_servers); + call_details = gpr_malloc (sizeof (grpc_call_details) * f->num_servers); + connection_sequence = gpr_malloc (sizeof (int) * spec->num_iters); /* Send a trivial request. */ - deadline = n_seconds_time(60); - - for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { - cq_verifier *cqv = cq_verifier_create(f->cq); - details = NULL; - details_capacity = 0; - was_cancelled = 2; - - for (i = 0; i < f->num_servers; i++) { - if (spec->kill_at[iter_num][i] != 0) { - kill_server(f, i); - } else if (spec->revive_at[iter_num][i] != 0) { - /* killing takes precedence */ - revive_server(f, i); - } - } - - connection_sequence[iter_num] = -1; - grpc_metadata_array_init(&initial_metadata_recv); - grpc_metadata_array_init(&trailing_metadata_recv); + deadline = n_seconds_time (60); + + for (iter_num = 0; iter_num < spec->num_iters; iter_num++) + { + cq_verifier *cqv = cq_verifier_create (f->cq); + details = NULL; + details_capacity = 0; + was_cancelled = 2; + + for (i = 0; i < f->num_servers; i++) + { + if (spec->kill_at[iter_num][i] != 0) + { + kill_server (f, i); + } + else if (spec->revive_at[iter_num][i] != 0) + { + /* killing takes precedence */ + revive_server (f, i); + } + } + + connection_sequence[iter_num] = -1; + grpc_metadata_array_init (&initial_metadata_recv); + grpc_metadata_array_init (&trailing_metadata_recv); + + for (i = 0; i < f->num_servers; i++) + { + grpc_call_details_init (&call_details[i]); + } + memset (s_valid, 0, f->num_servers * sizeof (int)); + + c = grpc_channel_create_call (client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", "foo.test.google.fr", deadline, NULL); + GPR_ASSERT (c); - for (i = 0; i < f->num_servers; i++) { - grpc_call_details_init(&call_details[i]); - } - memset(s_valid, 0, f->num_servers * sizeof(int)); - - c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - "/foo", "foo.test.google.fr", deadline, NULL); - GPR_ASSERT(c); - - op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata = &initial_metadata_recv; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; - op->data.recv_status_on_client.status = &status; - op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; - op->flags = 0; - op->reserved = NULL; - op++; - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); - - /* "listen" on all servers */ - for (i = 0; i < f->num_servers; i++) { - grpc_metadata_array_init(&f->request_metadata_recv[i]); - if (f->servers[i] != NULL) { - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(f->servers[i], &f->server_calls[i], - &call_details[i], - &f->request_metadata_recv[i], f->cq, - f->cq, tag(1000 + (int)i))); - } - } - - s_idx = -1; - while ((ev = grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)) - .type != GRPC_QUEUE_TIMEOUT) { - read_tag = ((int)(gpr_intptr)ev.tag); - gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d", - ev.success, ev.type, read_tag, iter_num); - if (ev.success && read_tag >= 1000) { - GPR_ASSERT(s_idx == -1); /* only one server must reply */ - /* only server notifications for non-shutdown events */ - s_idx = read_tag - 1000; - s_valid[s_idx] = 1; - connection_sequence[iter_num] = s_idx; - } - } - - if (s_idx >= 0) { op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op->flags = 0; op->reserved = NULL; op++; - op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; - op->data.send_status_from_server.trailing_metadata_count = 0; - op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op->flags = 0; op->reserved = NULL; op++; - op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; - op->data.recv_close_on_server.cancelled = &was_cancelled; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; op->flags = 0; op->reserved = NULL; op++; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(f->server_calls[s_idx], - ops, (size_t)(op - ops), - tag(102), NULL)); - - cq_expect_completion(cqv, tag(102), 1); - cq_expect_completion(cqv, tag(1), 1); - cq_verify(cqv); - - GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details[s_idx].method, "/foo")); - GPR_ASSERT(0 == strcmp(call_details[s_idx].host, "foo.test.google.fr")); - GPR_ASSERT(was_cancelled == 1); - } - - for (i = 0; i < f->num_servers; i++) { - if (s_valid[i] != 0) { - grpc_call_destroy(f->server_calls[i]); - } - grpc_metadata_array_destroy(&f->request_metadata_recv[i]); - } - grpc_metadata_array_destroy(&initial_metadata_recv); - grpc_metadata_array_destroy(&trailing_metadata_recv); - - cq_verifier_destroy(cqv); - - grpc_call_destroy(c); - - for (i = 0; i < f->num_servers; i++) { - grpc_call_details_destroy(&call_details[i]); + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT (GRPC_CALL_OK == grpc_call_start_batch (c, ops, (size_t) (op - ops), tag (1), NULL)); + + /* "listen" on all servers */ + for (i = 0; i < f->num_servers; i++) + { + grpc_metadata_array_init (&f->request_metadata_recv[i]); + if (f->servers[i] != NULL) + { + GPR_ASSERT (GRPC_CALL_OK == grpc_server_request_call (f->servers[i], &f->server_calls[i], &call_details[i], &f->request_metadata_recv[i], f->cq, f->cq, tag (1000 + (int) i))); + } + } + + s_idx = -1; + while ((ev = grpc_completion_queue_next (f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE (1), NULL)).type != GRPC_QUEUE_TIMEOUT) + { + read_tag = ((int) (gpr_intptr) ev.tag); + gpr_log (GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d", ev.success, ev.type, read_tag, iter_num); + if (ev.success && read_tag >= 1000) + { + GPR_ASSERT (s_idx == -1); /* only one server must reply */ + /* only server notifications for non-shutdown events */ + s_idx = read_tag - 1000; + s_valid[s_idx] = 1; + connection_sequence[iter_num] = s_idx; + } + } + + if (s_idx >= 0) + { + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; + op->data.send_status_from_server.status_details = "xyz"; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT (GRPC_CALL_OK == grpc_call_start_batch (f->server_calls[s_idx], ops, (size_t) (op - ops), tag (102), NULL)); + + cq_expect_completion (cqv, tag (102), 1); + cq_expect_completion (cqv, tag (1), 1); + cq_verify (cqv); + + GPR_ASSERT (status == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT (0 == strcmp (details, "xyz")); + GPR_ASSERT (0 == strcmp (call_details[s_idx].method, "/foo")); + GPR_ASSERT (0 == strcmp (call_details[s_idx].host, "foo.test.google.fr")); + GPR_ASSERT (was_cancelled == 1); + } + + for (i = 0; i < f->num_servers; i++) + { + if (s_valid[i] != 0) + { + grpc_call_destroy (f->server_calls[i]); + } + grpc_metadata_array_destroy (&f->request_metadata_recv[i]); + } + grpc_metadata_array_destroy (&initial_metadata_recv); + grpc_metadata_array_destroy (&trailing_metadata_recv); + + cq_verifier_destroy (cqv); + + grpc_call_destroy (c); + + for (i = 0; i < f->num_servers; i++) + { + grpc_call_details_destroy (&call_details[i]); + } + gpr_free (details); } - gpr_free(details); - } - gpr_free(call_details); - gpr_free(s_valid); + gpr_free (call_details); + gpr_free (s_valid); return connection_sequence; } -static void assert_channel_connectivity( - grpc_channel *ch, size_t num_accepted_conn_states, - grpc_connectivity_state accepted_conn_state, ...) { +static void +assert_channel_connectivity (grpc_channel * ch, size_t num_accepted_conn_states, grpc_connectivity_state accepted_conn_state, ...) +{ size_t i; grpc_channel_stack *client_stack; grpc_channel_element *client_channel_filter; @@ -390,316 +419,306 @@ static void assert_channel_connectivity( grpc_closure_list closure_list = GRPC_CLOSURE_LIST_INIT; va_list ap; - client_stack = grpc_channel_get_channel_stack(ch); - client_channel_filter = grpc_channel_stack_last_element(client_stack); - - actual_conn_state = grpc_client_channel_check_connectivity_state( - client_channel_filter, 0 /* don't try to connect */, &closure_list); - grpc_closure_list_run(&closure_list); - va_start(ap, accepted_conn_state); - for (i = 0; i < num_accepted_conn_states; i++) { - if (actual_conn_state == accepted_conn_state) { - break; - } - accepted_conn_state = va_arg(ap, grpc_connectivity_state); - } - va_end(ap); - if (i == num_accepted_conn_states) { - char **accepted_strs = - gpr_malloc(sizeof(char *) * num_accepted_conn_states); - char *accepted_str_joined; - va_start(ap, accepted_conn_state); - for (i = 0; i < num_accepted_conn_states; i++) { - GPR_ASSERT(gpr_asprintf(&accepted_strs[i], "%d", accepted_conn_state) > - 0); - accepted_conn_state = va_arg(ap, grpc_connectivity_state); + client_stack = grpc_channel_get_channel_stack (ch); + client_channel_filter = grpc_channel_stack_last_element (client_stack); + + actual_conn_state = grpc_client_channel_check_connectivity_state (client_channel_filter, 0 /* don't try to connect */ , &closure_list); + grpc_closure_list_run (&closure_list); + va_start (ap, accepted_conn_state); + for (i = 0; i < num_accepted_conn_states; i++) + { + if (actual_conn_state == accepted_conn_state) + { + break; + } + accepted_conn_state = va_arg (ap, grpc_connectivity_state); } - va_end(ap); - accepted_str_joined = gpr_strjoin_sep((const char **)accepted_strs, - num_accepted_conn_states, ", ", NULL); - gpr_log( - GPR_ERROR, - "Channel connectivity assertion failed: expected <one of [%s]>, got %d", - accepted_str_joined, actual_conn_state); - - for (i = 0; i < num_accepted_conn_states; i++) { - gpr_free(accepted_strs[i]); + va_end (ap); + if (i == num_accepted_conn_states) + { + char **accepted_strs = gpr_malloc (sizeof (char *) * num_accepted_conn_states); + char *accepted_str_joined; + va_start (ap, accepted_conn_state); + for (i = 0; i < num_accepted_conn_states; i++) + { + GPR_ASSERT (gpr_asprintf (&accepted_strs[i], "%d", accepted_conn_state) > 0); + accepted_conn_state = va_arg (ap, grpc_connectivity_state); + } + va_end (ap); + accepted_str_joined = gpr_strjoin_sep ((const char **) accepted_strs, num_accepted_conn_states, ", ", NULL); + gpr_log (GPR_ERROR, "Channel connectivity assertion failed: expected <one of [%s]>, got %d", accepted_str_joined, actual_conn_state); + + for (i = 0; i < num_accepted_conn_states; i++) + { + gpr_free (accepted_strs[i]); + } + gpr_free (accepted_strs); + gpr_free (accepted_str_joined); + abort (); } - gpr_free(accepted_strs); - gpr_free(accepted_str_joined); - abort(); - } } -void run_spec(const test_spec *spec) { +void +run_spec (const test_spec * spec) +{ grpc_channel *client; char *client_hostport; char *servers_hostports_str; int *actual_connection_sequence; - servers_fixture *f = setup_servers("127.0.0.1", spec->num_servers); + servers_fixture *f = setup_servers ("127.0.0.1", spec->num_servers); /* Create client. */ - servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, - 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); + servers_hostports_str = gpr_strjoin_sep ((const char **) f->servers_hostports, 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); - gpr_log(GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, - servers_hostports_str, client_hostport); + gpr_log (GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, servers_hostports_str, client_hostport); - actual_connection_sequence = perform_request(f, client, spec); + actual_connection_sequence = perform_request (f, client, spec); - spec->verifier(f, client, actual_connection_sequence, spec->num_iters); + spec->verifier (f, client, actual_connection_sequence, spec->num_iters); - gpr_free(client_hostport); - gpr_free(servers_hostports_str); - gpr_free(actual_connection_sequence); + gpr_free (client_hostport); + gpr_free (servers_hostports_str); + gpr_free (actual_connection_sequence); - grpc_channel_destroy(client); - teardown_servers(f); + grpc_channel_destroy (client); + teardown_servers (f); } -static void print_failed_expectations(const int *expected_connection_sequence, - const int *actual_connection_sequence, - const size_t expected_seq_length, - const size_t num_iters) { +static void +print_failed_expectations (const int *expected_connection_sequence, const int *actual_connection_sequence, const size_t expected_seq_length, const size_t num_iters) +{ size_t i; - for (i = 0; i < num_iters; i++) { - gpr_log(GPR_ERROR, "FAILURE: Iter, expected, actual:%d (%d, %d)", i, - expected_connection_sequence[i % expected_seq_length], - actual_connection_sequence[i]); - } + for (i = 0; i < num_iters; i++) + { + gpr_log (GPR_ERROR, "FAILURE: Iter, expected, actual:%d (%d, %d)", i, expected_connection_sequence[i % expected_seq_length], actual_connection_sequence[i]); + } } -static void verify_vanilla_round_robin(const servers_fixture *f, - grpc_channel *client, - const int *actual_connection_sequence, - const size_t num_iters) { +static void +verify_vanilla_round_robin (const servers_fixture * f, grpc_channel * client, const int *actual_connection_sequence, const size_t num_iters) +{ int *expected_connection_sequence; size_t i; const size_t expected_seq_length = f->num_servers; /* verify conn. seq. expectation */ /* get the first sequence of "num_servers" elements */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence, - sizeof(int) * expected_seq_length); - - for (i = 0; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, - actual, i); - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); + expected_connection_sequence = gpr_malloc (sizeof (int) * expected_seq_length); + memcpy (expected_connection_sequence, actual_connection_sequence, sizeof (int) * expected_seq_length); + + for (i = 0; i < num_iters; i++) + { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); + print_failed_expectations (expected_connection_sequence, actual_connection_sequence, expected_seq_length, num_iters); + abort (); + } } - } - assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); + assert_channel_connectivity (client, 1, GRPC_CHANNEL_READY); - gpr_free(expected_connection_sequence); + gpr_free (expected_connection_sequence); } /* At the start of the second iteration, all but the first and last servers (as * given in "f") are killed */ -static void verify_vanishing_floor_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { +static void +verify_vanishing_floor_round_robin (const servers_fixture * f, grpc_channel * client, const int *actual_connection_sequence, const size_t num_iters) +{ int *expected_connection_sequence; const size_t expected_seq_length = 2; size_t i; /* verify conn. seq. expectation */ /* copy the first full sequence (without -1s) */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence + 2, - expected_seq_length * sizeof(int)); + expected_connection_sequence = gpr_malloc (sizeof (int) * expected_seq_length); + memcpy (expected_connection_sequence, actual_connection_sequence + 2, expected_seq_length * sizeof (int)); /* first three elements of the sequence should be [<1st>, -1] */ - if (actual_connection_sequence[0] != expected_connection_sequence[0]) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", - expected_connection_sequence[0], actual_connection_sequence[0], 0); - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - 1u); - abort(); - } - - GPR_ASSERT(actual_connection_sequence[1] == -1); - - for (i = 2; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, - actual, i); - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); + if (actual_connection_sequence[0] != expected_connection_sequence[0]) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected_connection_sequence[0], actual_connection_sequence[0], 0); + print_failed_expectations (expected_connection_sequence, actual_connection_sequence, expected_seq_length, 1u); + abort (); + } + + GPR_ASSERT (actual_connection_sequence[1] == -1); + + for (i = 2; i < num_iters; i++) + { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); + print_failed_expectations (expected_connection_sequence, actual_connection_sequence, expected_seq_length, num_iters); + abort (); + } } - } - gpr_free(expected_connection_sequence); + gpr_free (expected_connection_sequence); } -static void verify_total_carnage_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { +static void +verify_total_carnage_round_robin (const servers_fixture * f, grpc_channel * client, const int *actual_connection_sequence, const size_t num_iters) +{ size_t i; - for (i = 0; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = -1; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, - actual, i); - abort(); + for (i = 0; i < num_iters; i++) + { + const int actual = actual_connection_sequence[i]; + const int expected = -1; + if (actual != expected) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); + abort (); + } } - } /* even though we know all the servers are dead, the client is still trying * retrying, believing it's in a transient failure situation */ - assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_CHANNEL_CONNECTING); + assert_channel_connectivity (client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_CHANNEL_CONNECTING); } -static void verify_partial_carnage_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { +static void +verify_partial_carnage_round_robin (const servers_fixture * f, grpc_channel * client, const int *actual_connection_sequence, const size_t num_iters) +{ int *expected_connection_sequence; size_t i; const size_t expected_seq_length = f->num_servers; /* verify conn. seq. expectation */ /* get the first sequence of "num_servers" elements */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence, - sizeof(int) * expected_seq_length); - - for (i = 0; i < num_iters / 2; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, - actual, i); - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); + expected_connection_sequence = gpr_malloc (sizeof (int) * expected_seq_length); + memcpy (expected_connection_sequence, actual_connection_sequence, sizeof (int) * expected_seq_length); + + for (i = 0; i < num_iters / 2; i++) + { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); + print_failed_expectations (expected_connection_sequence, actual_connection_sequence, expected_seq_length, num_iters); + abort (); + } } - } /* second half of the iterations go without response */ - for (; i < num_iters; i++) { - GPR_ASSERT(actual_connection_sequence[i] == -1); - } + for (; i < num_iters; i++) + { + GPR_ASSERT (actual_connection_sequence[i] == -1); + } /* even though we know all the servers are dead, the client is still trying * retrying, believing it's in a transient failure situation */ - assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_CHANNEL_CONNECTING); - gpr_free(expected_connection_sequence); + assert_channel_connectivity (client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_CHANNEL_CONNECTING); + gpr_free (expected_connection_sequence); } -static void verify_rebirth_round_robin(const servers_fixture *f, - grpc_channel *client, - const int *actual_connection_sequence, - const size_t num_iters) { +static void +verify_rebirth_round_robin (const servers_fixture * f, grpc_channel * client, const int *actual_connection_sequence, const size_t num_iters) +{ int *expected_connection_sequence; size_t i; const size_t expected_seq_length = f->num_servers; /* verify conn. seq. expectation */ /* get the first sequence of "num_servers" elements */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence + 4, - sizeof(int) * expected_seq_length); + expected_connection_sequence = gpr_malloc (sizeof (int) * expected_seq_length); + memcpy (expected_connection_sequence, actual_connection_sequence + 4, sizeof (int) * expected_seq_length); /* first iteration succeeds */ - GPR_ASSERT(actual_connection_sequence[0] != -1); + GPR_ASSERT (actual_connection_sequence[0] != -1); /* back up on the third (or maybe fourth) iteration */ i = 3; - if (actual_connection_sequence[i] == -1) { - i = 4; - } - for (; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, - actual, i); - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); + if (actual_connection_sequence[i] == -1) + { + i = 4; + } + for (; i < num_iters; i++) + { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) + { + gpr_log (GPR_ERROR, "FAILURE: expected %d, actual %d at iter %d", expected, actual, i); + print_failed_expectations (expected_connection_sequence, actual_connection_sequence, expected_seq_length, num_iters); + abort (); + } } - } /* things are fine once the servers are brought back up */ - assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); - gpr_free(expected_connection_sequence); + assert_channel_connectivity (client, 1, GRPC_CHANNEL_READY); + gpr_free (expected_connection_sequence); } -int main(int argc, char **argv) { +int +main (int argc, char **argv) +{ test_spec *spec; size_t i; 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_init (); /* everything is fine, all servers stay up the whole time and life's peachy */ - spec = test_spec_create(NUM_ITERS, NUM_SERVERS); + spec = test_spec_create (NUM_ITERS, NUM_SERVERS); spec->verifier = verify_vanilla_round_robin; spec->description = "test_all_server_up"; - run_spec(spec); + run_spec (spec); /* Kill all servers first thing in the morning */ - test_spec_reset(spec); + test_spec_reset (spec); spec->verifier = verify_total_carnage_round_robin; spec->description = "test_kill_all_server"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[0][i] = 1; - } - run_spec(spec); + for (i = 0; i < NUM_SERVERS; i++) + { + spec->kill_at[0][i] = 1; + } + run_spec (spec); /* at the start of the 2nd iteration, kill all but the first and last servers. * This should knock down the server bound to be selected next */ - test_spec_reset(spec); + test_spec_reset (spec); spec->verifier = verify_vanishing_floor_round_robin; spec->description = "test_kill_all_server_at_2nd_iteration"; - for (i = 1; i < NUM_SERVERS - 1; i++) { - spec->kill_at[1][i] = 1; - } - run_spec(spec); + for (i = 1; i < NUM_SERVERS - 1; i++) + { + spec->kill_at[1][i] = 1; + } + run_spec (spec); /* Midway, kill all servers. */ - test_spec_reset(spec); + test_spec_reset (spec); spec->verifier = verify_partial_carnage_round_robin; spec->description = "test_kill_all_server_midway"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[spec->num_iters / 2][i] = 1; - } - run_spec(spec); + for (i = 0; i < NUM_SERVERS; i++) + { + spec->kill_at[spec->num_iters / 2][i] = 1; + } + run_spec (spec); /* After first iteration, kill all servers. On the third one, bring them all * back up. */ - test_spec_reset(spec); + test_spec_reset (spec); spec->verifier = verify_rebirth_round_robin; spec->description = "test_kill_all_server_after_1st_resurrect_at_3rd"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[1][i] = 1; - spec->revive_at[3][i] = 1; - } - run_spec(spec); + for (i = 0; i < NUM_SERVERS; i++) + { + spec->kill_at[1][i] = 1; + spec->revive_at[3][i] = 1; + } + run_spec (spec); - test_spec_destroy(spec); + test_spec_destroy (spec); - grpc_shutdown(); + grpc_shutdown (); return 0; } diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c index df12d6b4cb..3f91a3242e 100644 --- a/test/core/client_config/uri_parser_test.c +++ b/test/core/client_config/uri_parser_test.c @@ -39,48 +39,48 @@ #include "test/core/util/test_config.h" -static void test_succeeds(const char *uri_text, const char *scheme, - const char *authority, const char *path, - const char *query, const char *fragment) { - grpc_uri *uri = grpc_uri_parse(uri_text, 0); - GPR_ASSERT(uri); - GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); - GPR_ASSERT(0 == strcmp(authority, uri->authority)); - GPR_ASSERT(0 == strcmp(path, uri->path)); - GPR_ASSERT(0 == strcmp(query, uri->query)); - GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - grpc_uri_destroy(uri); +static void +test_succeeds (const char *uri_text, const char *scheme, const char *authority, const char *path, const char *query, const char *fragment) +{ + grpc_uri *uri = grpc_uri_parse (uri_text, 0); + GPR_ASSERT (uri); + GPR_ASSERT (0 == strcmp (scheme, uri->scheme)); + GPR_ASSERT (0 == strcmp (authority, uri->authority)); + GPR_ASSERT (0 == strcmp (path, uri->path)); + GPR_ASSERT (0 == strcmp (query, uri->query)); + GPR_ASSERT (0 == strcmp (fragment, uri->fragment)); + grpc_uri_destroy (uri); } -static void test_fails(const char *uri_text) { - GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); +static void +test_fails (const char *uri_text) +{ + GPR_ASSERT (NULL == grpc_uri_parse (uri_text, 0)); } -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); - test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); - test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", - ""); - test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", ""); - test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom", "", ""); - test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", - "127.0.0.1:2181", "/foo/bar", "", ""); - test_succeeds("http://www.google.com?yay-i'm-using-queries", "http", - "www.google.com", "", "yay-i'm-using-queries", ""); - test_succeeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "", - "fragment-all-the-things"); - test_succeeds("http:?legit", "http", "", "", "legit", ""); - test_succeeds("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too"); - test_succeeds("http:?legit#twice", "http", "", "", "legit", "twice"); - test_succeeds("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?"); - test_succeeds("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/"); +int +main (int argc, char **argv) +{ + grpc_test_init (argc, argv); + test_succeeds ("http://www.google.com", "http", "www.google.com", "", "", ""); + test_succeeds ("dns:///foo", "dns", "", "/foo", "", ""); + test_succeeds ("http://www.google.com:90", "http", "www.google.com:90", "", "", ""); + test_succeeds ("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", ""); + test_succeeds ("a+b:foo.coom", "a+b", "", "foo.coom", "", ""); + test_succeeds ("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", "127.0.0.1:2181", "/foo/bar", "", ""); + test_succeeds ("http://www.google.com?yay-i'm-using-queries", "http", "www.google.com", "", "yay-i'm-using-queries", ""); + test_succeeds ("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "", "fragment-all-the-things"); + test_succeeds ("http:?legit", "http", "", "", "legit", ""); + test_succeeds ("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too"); + test_succeeds ("http:?legit#twice", "http", "", "", "legit", "twice"); + test_succeeds ("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?"); + test_succeeds ("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/"); - test_fails("xyz"); - test_fails("http:?dangling-pct-%0"); - test_fails("http://foo?[bar]"); - test_fails("http://foo?x[bar]"); - test_fails("http://foo?bar#lol#"); + test_fails ("xyz"); + test_fails ("http:?dangling-pct-%0"); + test_fails ("http://foo?[bar]"); + test_fails ("http://foo?x[bar]"); + test_fails ("http://foo?bar#lol#"); return 0; } |