[tarantool-patches] [PATCH 3/6] test: remove swim_unblock_fd event from swim test harness

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Mar 20 13:49:16 MSK 2019


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)





More information about the Tarantool-patches mailing list