From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A3F582BB0B for ; Wed, 24 Apr 2019 10:36:29 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0NDru4YuezlV for ; Wed, 24 Apr 2019 10:36:29 -0400 (EDT) Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 35EBE2BAAA for ; Wed, 24 Apr 2019 10:36:29 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 1/6] test: rename swim_cluster_node to swim_cluster_member Date: Wed, 24 Apr 2019 17:36:15 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org There are two different structures - public struct swim_member exposed by SWIM API, and struct swim_node defined and used inside tests. Before this patch swim_cluster_node() was returning struct swim_member, just historically. But more and more places appear where it is wanted to safely take struct swim_node, not swim_member, with an appropriate assertion on an invalid index. This patch renames swim_cluster_node() to swim_cluster_member(), and introduces new swim_cluster_node() returning swim_node. --- test/unit/swim.c | 28 ++++++++++---------- test/unit/swim_test_utils.c | 51 +++++++++++++++++++++---------------- test/unit/swim_test_utils.h | 2 +- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/test/unit/swim.c b/test/unit/swim.c index 1cdfd45aa..e375e6607 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -105,7 +105,7 @@ swim_test_uuid_update(void) struct swim_cluster *cluster = swim_cluster_new(2); swim_cluster_add_link(cluster, 0, 1); fail_if(swim_cluster_wait_fullmesh(cluster, 1) != 0); - struct swim *s = swim_cluster_node(cluster, 0); + struct swim *s = swim_cluster_member(cluster, 0); struct tt_uuid old_uuid = *swim_member_uuid(swim_self(s)); struct tt_uuid new_uuid = uuid_nil; new_uuid.time_low = 1000; @@ -180,8 +180,8 @@ swim_test_add_remove(void) struct swim_cluster *cluster = swim_cluster_new(2); swim_cluster_add_link(cluster, 0, 1); fail_if(swim_cluster_wait_fullmesh(cluster, 1) != 0); - struct swim *s1 = swim_cluster_node(cluster, 0); - struct swim *s2 = swim_cluster_node(cluster, 1); + struct swim *s1 = swim_cluster_member(cluster, 0); + struct swim *s2 = swim_cluster_member(cluster, 1); const struct swim_member *s2_self = swim_self(s2); is(swim_add_member(s1, swim_member_uri(s2_self), @@ -272,8 +272,8 @@ swim_test_basic_failure_detection(void) swim_cluster_block_io(cluster, 1); /* Next round after 1 sec + let ping hang for 0.25 sec. */ swim_run_for(1.25); - struct swim *s1 = swim_cluster_node(cluster, 0); - struct swim *s2 = swim_cluster_node(cluster, 1); + struct swim *s1 = swim_cluster_member(cluster, 0); + struct swim *s2 = swim_cluster_member(cluster, 1); const struct swim_member *s2_self = swim_self(s2); swim_remove_member(s1, swim_member_uuid(s2_self)); swim_cluster_unblock_io(cluster, 1); @@ -343,8 +343,8 @@ swim_test_probe(void) swim_start_test(2); struct swim_cluster *cluster = swim_cluster_new(2); - struct swim *s1 = swim_cluster_node(cluster, 0); - struct swim *s2 = swim_cluster_node(cluster, 1); + struct swim *s1 = swim_cluster_member(cluster, 0); + struct swim *s2 = swim_cluster_member(cluster, 1); const char *s2_uri = swim_member_uri(swim_self(s2)); is(swim_probe_member(s1, s2_uri), 0, "send probe"); is(swim_cluster_wait_fullmesh(cluster, 0.1), 0, @@ -503,11 +503,11 @@ swim_test_quit(void) * received the 'quit' message with the same UUID. Of * course, it should be refuted. */ - struct swim *s0 = swim_cluster_node(cluster, 0); + struct swim *s0 = swim_cluster_member(cluster, 0); struct tt_uuid s0_uuid = *swim_member_uuid(swim_self(s0)); - struct swim *s1 = swim_cluster_node(cluster, 1); + struct swim *s1 = swim_cluster_member(cluster, 1); swim_remove_member(s1, &s0_uuid); - struct swim *s2 = swim_cluster_node(cluster, 2); + struct swim *s2 = swim_cluster_member(cluster, 2); swim_remove_member(s2, &s0_uuid); swim_cluster_quit_node(cluster, 0); @@ -578,7 +578,7 @@ swim_test_uri_update(void) swim_cluster_add_link(cluster, 2, 1); swim_cluster_add_link(cluster, 2, 0); - struct swim *s0 = swim_cluster_node(cluster, 0); + struct swim *s0 = swim_cluster_member(cluster, 0); const struct swim_member *s0_self = swim_self(s0); const char *new_s0_uri = "127.0.0.5:1"; fail_if(swim_cfg(s0, "127.0.0.5:1", -1, -1, -1, NULL) != 0); @@ -586,7 +586,7 @@ swim_test_uri_update(void) * Since S1 knows about S2 only, one round step is enough. */ swim_run_for(1); - struct swim *s1 = swim_cluster_node(cluster, 1); + struct swim *s1 = swim_cluster_member(cluster, 1); const struct swim_member *s0_view = swim_member_by_uuid(s1, swim_member_uuid(s0_self)); is(strcmp(new_s0_uri, swim_member_uri(s0_view)), 0, @@ -619,8 +619,8 @@ swim_test_broadcast(void) swim_start_test(6); int size = 4; struct swim_cluster *cluster = swim_cluster_new(size); - struct swim *s0 = swim_cluster_node(cluster, 0); - struct swim *s1 = swim_cluster_node(cluster, 1); + struct swim *s0 = swim_cluster_member(cluster, 0); + struct swim *s1 = swim_cluster_member(cluster, 1); const char *s1_uri = swim_member_uri(swim_self(s1)); struct uri u; fail_if(uri_parse(&u, s1_uri) != 0 || u.service == NULL); diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c index 45570cce5..4f488fb7b 100644 --- a/test/unit/swim_test_utils.c +++ b/test/unit/swim_test_utils.c @@ -137,12 +137,25 @@ swim_cluster_delete(struct swim_cluster *cluster) free(cluster); } +/** Safely get node of @a cluster with id @a i. */ +static inline struct swim_node * +swim_cluster_node(struct swim_cluster *cluster, int i) +{ + assert(i >= 0 && i < cluster->size); + return &cluster->node[i]; +} + +struct swim * +swim_cluster_member(struct swim_cluster *cluster, int i) +{ + return swim_cluster_node(cluster, i)->swim; +} + int swim_cluster_update_uuid(struct swim_cluster *cluster, int i, const struct tt_uuid *new_uuid) { - assert(i >= 0 && i < cluster->size); - struct swim_node *n = &cluster->node[i]; + struct swim_node *n = swim_cluster_node(cluster, i); if (swim_cfg(n->swim, NULL, -1, -1, -1, new_uuid) != 0) return -1; n->uuid = *new_uuid; @@ -152,9 +165,10 @@ swim_cluster_update_uuid(struct swim_cluster *cluster, int i, int swim_cluster_add_link(struct swim_cluster *cluster, int to_id, int from_id) { - const struct swim_member *from = swim_self(cluster->node[from_id].swim); - return swim_add_member(cluster->node[to_id].swim, swim_member_uri(from), - swim_member_uuid(from)); + const struct swim_member *from = + swim_self(swim_cluster_member(cluster, from_id)); + return swim_add_member(swim_cluster_member(cluster, to_id), + swim_member_uri(from), swim_member_uuid(from)); } static const struct swim_member * @@ -165,8 +179,9 @@ swim_cluster_member_view(struct swim_cluster *cluster, int node_id, * Do not use node[member_id].swim - it can be NULL * already, for example, in case of quit or deletion. */ - return swim_member_by_uuid(cluster->node[node_id].swim, - &cluster->node[member_id].uuid); + struct swim_node *n = swim_cluster_node(cluster, member_id); + return swim_member_by_uuid(swim_cluster_member(cluster, node_id), + &n->uuid); } enum swim_member_status @@ -208,22 +223,14 @@ int swim_cluster_member_set_payload(struct swim_cluster *cluster, int i, const char *payload, uint16_t size) { - struct swim *s = swim_cluster_node(cluster, i); + struct swim *s = swim_cluster_member(cluster, i); return swim_set_payload(s, payload, size); } -struct swim * -swim_cluster_node(struct swim_cluster *cluster, int i) -{ - assert(i >= 0 && i < cluster->size); - return cluster->node[i].swim; -} - void swim_cluster_quit_node(struct swim_cluster *cluster, int i) { - assert(i >= 0 && i < cluster->size); - struct swim_node *n = &cluster->node[i]; + struct swim_node *n = swim_cluster_node(cluster, i); assert(tt_uuid_is_equal(&n->uuid, swim_member_uuid(swim_self(n->swim)))); swim_quit(n->swim); @@ -233,8 +240,7 @@ swim_cluster_quit_node(struct swim_cluster *cluster, int i) void swim_cluster_restart_node(struct swim_cluster *cluster, int i) { - assert(i >= 0 && i < cluster->size); - struct swim_node *n = &cluster->node[i]; + struct swim_node *n = swim_cluster_node(cluster, i); struct swim *s = n->swim; char uri[128]; swim_cluster_id_to_uri(uri, i); @@ -261,7 +267,8 @@ swim_cluster_block_io(struct swim_cluster *cluster, int i) void swim_cluster_unblock_io(struct swim_cluster *cluster, int i) { - swim_test_transport_unblock_fd(swim_fd(cluster->node[i].swim)); + struct swim *s = swim_cluster_member(cluster, i); + swim_test_transport_unblock_fd(swim_fd(s)); } /** A structure used by drop rate packet filter. */ @@ -308,7 +315,7 @@ static void swim_cluster_set_drop_generic(struct swim_cluster *cluster, int i, double value, bool is_for_in, bool is_for_out) { - int fd = swim_fd(swim_cluster_node(cluster, i)); + int fd = swim_fd(swim_cluster_member(cluster, i)); if (value == 0) { swim_test_transport_remove_filter(fd, swim_filter_drop_rate); return; @@ -374,7 +381,7 @@ void swim_cluster_drop_components(struct swim_cluster *cluster, int i, const int *keys, int key_count) { - int fd = swim_fd(swim_cluster_node(cluster, i)); + int fd = swim_fd(swim_cluster_member(cluster, i)); if (key_count == 0) { swim_test_transport_remove_filter(fd, swim_filter_drop_component); diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h index 100a67e0c..145af9b1f 100644 --- a/test/unit/swim_test_utils.h +++ b/test/unit/swim_test_utils.h @@ -70,7 +70,7 @@ swim_error_check_match(const char *msg); /** Get a SWIM instance by its ordinal number. */ struct swim * -swim_cluster_node(struct swim_cluster *cluster, int i); +swim_cluster_member(struct swim_cluster *cluster, int i); /** Quit a member with id @a id. */ void -- 2.20.1 (Apple Git-117)