[Tarantool-patches] [PATCH 08/10] test: move fake libev code to fakeev.c/.h files

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Dec 1 02:56:17 MSK 2020


SWIM unit tests contain a special library for emulating the event
loop: swim_test_ev. It provides API similar to libev, but
implemented entirely in user-space, including clock functions.

The latter is the most important point, as the original libev
does not allow to define your own timing functions - internally it
relies on select/kqueue/epoll/poll/select/... with true clock.

Because of that it is impossible to perform long tests with the
original libev, which could last for minutes or even tens of
seconds if their count is big. swim_test_ev uses virtual time,
where hours can be played in milliseconds.

The fake libev is going to be re-used for Raft unit tests. But for
that it is necessary to detach it from all SWIM dependencies.

--

The patch renames swim_test_ev.c/.h to fakeev.c/.h because they
will contain only fakeev functions soon.

The swim methods, implementing swim_ev.h via fakeev, are moved to
their own file in a separate commit. Because their file will be
swim_test_ev.c. If they would be moved here, git would treat it
like everything *except* swim functions was moved to fakeev.h/.c.
It would ruin git history, and is split in 2 commits to avoid
this.

Part of #5303
---
 test/unit/CMakeLists.txt               | 6 +++---
 test/unit/{swim_test_ev.c => fakeev.c} | 2 +-
 test/unit/{swim_test_ev.h => fakeev.h} | 5 +----
 test/unit/swim_test_utils.c            | 1 -
 test/unit/swim_test_utils.h            | 2 +-
 5 files changed, 6 insertions(+), 10 deletions(-)
 rename test/unit/{swim_test_ev.c => fakeev.c} (99%)
 rename test/unit/{swim_test_ev.h => fakeev.h} (96%)

diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index e6a79e911..436178280 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -240,16 +240,16 @@ target_link_libraries(sio.test unit core)
 add_executable(crypto.test crypto.c core_test_utils.c)
 target_link_libraries(crypto.test crypto unit)
 
-add_executable(swim.test swim.c swim_test_transport.c swim_test_ev.c
+add_executable(swim.test swim.c swim_test_transport.c fakeev.c
                swim_test_utils.c ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim.test unit fakesys swim)
 
-add_executable(swim_proto.test swim_proto.c swim_test_transport.c swim_test_ev.c
+add_executable(swim_proto.test swim_proto.c swim_test_transport.c fakeev.c
                swim_test_utils.c ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim_proto.test unit fakesys swim)
 
 add_executable(swim_errinj.test swim_errinj.c swim_test_transport.c
-               swim_test_ev.c swim_test_utils.c
+               fakeev.c swim_test_utils.c
                ${PROJECT_SOURCE_DIR}/src/version.c core_test_utils.c)
 target_link_libraries(swim_errinj.test unit fakesys swim)
 
diff --git a/test/unit/swim_test_ev.c b/test/unit/fakeev.c
similarity index 99%
rename from test/unit/swim_test_ev.c
rename to test/unit/fakeev.c
index 6847836e3..20de35d7f 100644
--- a/test/unit/swim_test_ev.c
+++ b/test/unit/fakeev.c
@@ -28,7 +28,7 @@
  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include "swim_test_ev.h"
+#include "fakeev.h"
 #include "trivia/util.h"
 #include "swim/swim_ev.h"
 #include "tarantool_ev.h"
diff --git a/test/unit/swim_test_ev.h b/test/unit/fakeev.h
similarity index 96%
rename from test/unit/swim_test_ev.h
rename to test/unit/fakeev.h
index d93b149de..b50fe5b3d 100644
--- a/test/unit/swim_test_ev.h
+++ b/test/unit/fakeev.h
@@ -1,5 +1,4 @@
-#ifndef TARANTOOL_SWIM_TEST_EV_H_INCLUDED
-#define TARANTOOL_SWIM_TEST_EV_H_INCLUDED
+#pragma once
 /*
  * Copyright 2010-2019, Tarantool AUTHORS, please see AUTHORS file.
  *
@@ -110,5 +109,3 @@ fakeev_loop_update(struct ev_loop *loop);
 /** Destroy pending events, reset global watch. */
 void
 fakeev_reset(void);
-
-#endif /* TARANTOOL_SWIM_TEST_EV_H_INCLUDED */
diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c
index c9d92a704..708889460 100644
--- a/test/unit/swim_test_utils.c
+++ b/test/unit/swim_test_utils.c
@@ -29,7 +29,6 @@
  * SUCH DAMAGE.
  */
 #include "swim_test_utils.h"
-#include "swim_test_ev.h"
 #include "swim/swim_ev.h"
 #include "uuid/tt_uuid.h"
 #include "trivia/util.h"
diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h
index 0f0051edd..665423a03 100644
--- a/test/unit/swim_test_utils.h
+++ b/test/unit/swim_test_utils.h
@@ -39,7 +39,7 @@
 #include "swim/swim_ev.h"
 #include "swim/swim_proto.h"
 #include "fakesys/fakenet.h"
-#include "swim_test_ev.h"
+#include "fakeev.h"
 
 struct swim_cluster;
 
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list