From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 3/6] test: remove swim_unblock_fd event from swim test harness Date: Wed, 20 Mar 2019 13:49:16 +0300 [thread overview] Message-ID: <d7eecc0d5488895205cdca0e47156a06acae9406.1553078631.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1553078631.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1553078631.git.v.shpilevoy@tarantool.org> It was designed to control when to unblock a blocked fake file descriptor. Blocked fd accepts all messages, but does not deliver them to SWIM. Also it takes messages to send from SWIM, but does not forward it into the 'network'. But such a complex event is not necessary after swim_brk_event appeared. It allows to block an fd, play event loop for a strictly specified fake seconds number, unblock fd, and play further. Follow-up for 03b9a6e91baf246ee2bb9841d01ba3824b6768a6 --- test/unit/swim.c | 9 +++++-- test/unit/swim_test_ev.c | 47 ------------------------------------- test/unit/swim_test_ev.h | 4 ---- test/unit/swim_test_utils.c | 17 ++++++++++++-- test/unit/swim_test_utils.h | 10 +++++++- 5 files changed, 31 insertions(+), 56 deletions(-) diff --git a/test/unit/swim.c b/test/unit/swim.c index 3a97aeb18..2c04e25b9 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -201,9 +201,14 @@ swim_test_add_remove(void) * removed from s1 after the message is scheduled but * before its completion. */ - swim_cluster_block_io(cluster, 0, 2); - swim_do_loop_step(loop()); + swim_cluster_block_io(cluster, 0); + swim_run_for(1); + /* + * Now the message from s1 is in 'fly', round step is not + * finished. + */ swim_remove_member(s1, swim_member_uuid(s2_self)); + swim_cluster_unblock_io(cluster, 0); is(swim_cluster_wait_fullmesh(cluster, 1), 0, "back in fullmesh after a member removal in the middle of a step"); diff --git a/test/unit/swim_test_ev.c b/test/unit/swim_test_ev.c index d4a0a4752..5b84a68de 100644 --- a/test/unit/swim_test_ev.c +++ b/test/unit/swim_test_ev.c @@ -54,7 +54,6 @@ static int event_id = 0; */ enum swim_event_type { SWIM_EVENT_TIMER, - SWIM_EVENT_FD_UNBLOCK, SWIM_EVENT_BRK, }; @@ -205,52 +204,6 @@ swim_timer_event_new(struct ev_watcher *watcher, double delay) assert(rc != mh_end(events_hash)); } -/** - * SWIM fake transport's event. It is used to block a fake file - * descriptor for a delay. Right after a block that event is - * generated to unblock the descriptor later. - */ -struct swim_fd_unblock_event { - struct swim_event base; - /** A fake file descriptor to unlock. */ - int fd; -}; - -/** Delete a fd unblock event. */ -static void -swim_fd_unblock_event_delete(struct swim_event *e) -{ - assert(e->type == SWIM_EVENT_FD_UNBLOCK); - swim_event_destroy(e); - free(e); -} - -/** Process and delete a fd unblock event. */ -static void -swim_fd_unblock_event_process(struct swim_event *e, struct ev_loop *loop) -{ - (void) loop; - assert(e->type == SWIM_EVENT_FD_UNBLOCK); - struct swim_fd_unblock_event *fe = (struct swim_fd_unblock_event *) e; - swim_test_transport_unblock_fd(fe->fd); - swim_fd_unblock_event_delete(e); -} - -void -swim_test_ev_block_fd(int fd, double delay) -{ - struct swim_fd_unblock_event *e = - (struct swim_fd_unblock_event *) malloc(sizeof(*e)); - assert(e != NULL); - /* Block now. */ - swim_test_transport_block_fd(fd); - /* Unblock after delay. */ - swim_event_create(&e->base, SWIM_EVENT_FD_UNBLOCK, delay, - swim_fd_unblock_event_process, - swim_fd_unblock_event_delete); - e->fd = fd; -} - /** * Breakpoint event for debug. It does nothing but stops the event * loop after a timeout to allow highlevel API to check some diff --git a/test/unit/swim_test_ev.h b/test/unit/swim_test_ev.h index 01a1b8868..82bbfc635 100644 --- a/test/unit/swim_test_ev.h +++ b/test/unit/swim_test_ev.h @@ -47,10 +47,6 @@ swim_test_ev_init(void); void swim_test_ev_free(void); -/** Block a file descriptor @a fd for @a delay fake seconds. */ -void -swim_test_ev_block_fd(int fd, double delay); - /** * Stop the event loop after @a delay fake seconds. It does not * affect other events, so the loop can stop earlier multiple diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c index 0b301333b..ee24b0320 100644 --- a/test/unit/swim_test_utils.c +++ b/test/unit/swim_test_utils.c @@ -30,6 +30,7 @@ */ #include "swim_test_utils.h" #include "swim_test_ev.h" +#include "swim_test_transport.h" #include "swim/swim.h" #include "swim/swim_ev.h" #include "uuid/tt_uuid.h" @@ -94,9 +95,15 @@ swim_cluster_node(struct swim_cluster *cluster, int i) } void -swim_cluster_block_io(struct swim_cluster *cluster, int i, double delay) +swim_cluster_block_io(struct swim_cluster *cluster, int i) { - swim_test_ev_block_fd(swim_fd(cluster->node[i]), delay); + swim_test_transport_block_fd(swim_fd(cluster->node[i])); +} + +void +swim_cluster_unblock_io(struct swim_cluster *cluster, int i) +{ + swim_test_transport_unblock_fd(swim_fd(cluster->node[i])); } /** Check if @a s1 knows every member of @a s2's table. */ @@ -153,6 +160,12 @@ swim_cluster_wait_fullmesh(struct swim_cluster *cluster, double timeout) return swim_wait_timeout(timeout, swim_cluster_is_fullmesh(cluster)); } +void +swim_run_for(double duration) +{ + swim_wait_timeout(duration, false); +} + bool swim_error_check_match(const char *msg) { diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h index 90962b658..56fc2f57d 100644 --- a/test/unit/swim_test_utils.h +++ b/test/unit/swim_test_utils.h @@ -58,7 +58,11 @@ swim_cluster_node(struct swim_cluster *cluster, int i); /** Block IO on a SWIM instance with id @a i. */ void -swim_cluster_block_io(struct swim_cluster *cluster, int i, double delay); +swim_cluster_block_io(struct swim_cluster *cluster, int i); + +/** Unblock IO on a SWIM instance with id @a i. */ +void +swim_cluster_unblock_io(struct swim_cluster *cluster, int i); /** * Explicitly add a member of id @a from_id to a member of id @@ -78,6 +82,10 @@ swim_cluster_is_fullmesh(struct swim_cluster *cluster); int swim_cluster_wait_fullmesh(struct swim_cluster *cluster, double timeout); +/** Process SWIM events for @a duration fake seconds. */ +void +swim_run_for(double duration); + #define swim_start_test(n) { \ header(); \ say_verbose("-------- SWIM start test %s --------", __func__); \ -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2019-03-20 10:49 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-20 10:49 [tarantool-patches] [PATCH 0/6] SWIM failure detection draft Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 1/6] swim: follow-ups for SWIM anti-entropy Vladislav Shpilevoy 2019-03-29 8:27 ` [tarantool-patches] " Konstantin Osipov 2019-03-29 10:19 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 2/6] test: introduce breakpoints for swim's event loop Vladislav Shpilevoy 2019-03-29 18:20 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 2019-04-02 19:16 ` Vladislav Shpilevoy 2019-04-02 20:40 ` Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` Vladislav Shpilevoy [this message] 2019-03-29 18:22 ` [tarantool-patches] Re: [PATCH 3/6] test: remove swim_unblock_fd event from swim test harness Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 4/6] swim: expose enum swim_member_status to public API Vladislav Shpilevoy 2019-03-29 18:24 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 2019-04-02 13:17 ` Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 5/6] test: differentiate blocked and closed swim fake fds Vladislav Shpilevoy 2019-03-29 18:25 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 6/6] [RAW] swim: introduce failure detection component Vladislav Shpilevoy 2019-03-29 18:59 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 2019-04-04 10:20 ` Vladislav Shpilevoy 2019-04-04 12:45 ` Konstantin Osipov 2019-04-04 13:57 ` Vladislav Shpilevoy 2019-04-04 16:14 ` Vladimir Davydov 2019-04-04 16:47 ` Vladislav Shpilevoy 2019-03-27 19:28 ` [tarantool-patches] [PATCH 7/6] swim: make swim_upsert_member returning two values Vladislav Shpilevoy 2019-03-28 8:52 ` [tarantool-patches] " Konstantin Osipov 2019-03-28 11:52 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d7eecc0d5488895205cdca0e47156a06acae9406.1553078631.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 3/6] test: remove swim_unblock_fd event from swim test harness' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox