From 107e66b65a992d5da0e0d5e64abf0c3ccfe1d41d Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 1 Mar 2020 17:23:59 +0100 Subject: [PATCH] chore: replaced msleep by std::this_thread::sleep_for --- cmake/unit_tests.cmake | 1 - lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc | 9 ++++++--- lib/wf/timer/test/wf/timer/test_timepoint.cc | 8 +++++--- lib/wf/timer/test/wf/timer/test_timer.cc | 13 +++++++------ test/webfuse/tests/integration/provider.cc | 6 ++++-- test/webfuse/tests/integration/server.cc | 1 - test/webfuse/utils/msleep.cc | 19 ------------------- test/webfuse/utils/msleep.hpp | 12 ------------ 8 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 test/webfuse/utils/msleep.cc delete mode 100644 test/webfuse/utils/msleep.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b7887fa..13b91f9 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -18,7 +18,6 @@ add_executable(alltests lib/wf/timer/test/wf/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc - test/webfuse/utils/msleep.cc test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index 416c25f..af38a5c 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -1,10 +1,13 @@ #include #include "wf/jsonrpc/proxy.h" #include "wf/timer/manager.h" -#include "webfuse/utils/msleep.hpp" #include "webfuse/core/json_util.h" -using webfuse_test::msleep; +#include +#include + +using namespace std::chrono_literals; + #define WF_DEFAULT_TIMEOUT (10 * 1000) @@ -289,7 +292,7 @@ TEST(wf_jsonrpc_proxy, timeout) ASSERT_TRUE(send_context.is_called); ASSERT_TRUE(json_is_object(send_context.response)); - msleep(10); + std::this_thread::sleep_for(10ms); wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc index bd7774a..723ff6a 100644 --- a/lib/wf/timer/test/wf/timer/test_timepoint.cc +++ b/lib/wf/timer/test/wf/timer/test_timepoint.cc @@ -1,14 +1,16 @@ #include -#include "webfuse/utils/msleep.hpp" #include "wf/timer/impl/timepoint.h" -using webfuse_test::msleep; +#include +#include + +using namespace std::chrono_literals; TEST(wf_timer_timepoint, now) { wf_timer_timepoint start = wf_timer_impl_timepoint_now(); - msleep(42); + std::this_thread::sleep_for(42ms); wf_timer_timepoint end = wf_timer_impl_timepoint_now(); ASSERT_LT(start, end); diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/lib/wf/timer/test/wf/timer/test_timer.cc index ffeb1d3..e97c011 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/lib/wf/timer/test/wf/timer/test_timer.cc @@ -1,13 +1,14 @@ #include #include +#include +#include -#include "webfuse/utils/msleep.hpp" #include "wf/timer/timer.h" #include "wf/timer/manager.h" using std::size_t; -using webfuse_test::msleep; +using namespace std::chrono_literals; extern "C" { @@ -37,7 +38,7 @@ TEST(wf_timer, trigger) struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); wf_timer_start(timer, 250); - msleep(500); + std::this_thread::sleep_for(500ms); wf_timer_manager_check(manager); ASSERT_TRUE(triggered); @@ -67,7 +68,7 @@ TEST(wf_timer, cancel) struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); wf_timer_start(timer, 250); - msleep(500); + std::this_thread::sleep_for(500ms); wf_timer_cancel(timer); wf_timer_manager_check(manager); @@ -90,7 +91,7 @@ TEST(wf_timer, cancel_multiple_timers) wf_timer_start(timer[i], 0); } - msleep(10); + std::this_thread::sleep_for(10ms); for(size_t i = 0; i < count; i++) { wf_timer_cancel(timer[i]); @@ -122,7 +123,7 @@ TEST(wf_timer, multiple_timers) for(size_t i = 0; i < count; i++) { - msleep(100); + std::this_thread::sleep_for(100ms); wf_timer_manager_check(manager); } diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index 5142ca8..45e331a 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -3,10 +3,12 @@ #include "webfuse/provider/impl/client.h" #include #include +#include #include -#include "webfuse/utils/msleep.hpp" #include "webfuse/utils/static_filesystem.h" +using namespace std::chrono_literals; + namespace webfuse_test { @@ -29,7 +31,7 @@ public: } thread = std::thread(Run, this); - webfuse_test::msleep(200); + std::this_thread::sleep_for(200ms); } ~Private() diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 847efa2..e48f074 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -6,7 +6,6 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" -#include "webfuse/utils/msleep.hpp" #define WF_PATH_MAX (100) diff --git a/test/webfuse/utils/msleep.cc b/test/webfuse/utils/msleep.cc deleted file mode 100644 index 659bb81..0000000 --- a/test/webfuse/utils/msleep.cc +++ /dev/null @@ -1,19 +0,0 @@ -#include "webfuse/utils/msleep.hpp" -#include - -namespace webfuse_test -{ - -void msleep(long millis) -{ - long const secs_per_msec = 1000; - long const msecs_per_nsec = (1000 * 1000); - - long const seconds = millis / secs_per_msec; - long const nanos = (millis % secs_per_msec) * msecs_per_nsec; - - struct timespec timeout = { seconds, nanos }; - while (0 != nanosleep(&timeout, &timeout)); -} - -} \ No newline at end of file diff --git a/test/webfuse/utils/msleep.hpp b/test/webfuse/utils/msleep.hpp deleted file mode 100644 index 47cb1e6..0000000 --- a/test/webfuse/utils/msleep.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WF_TEST_MSLEEP_HPP -#define WF_TEST_MSLEEP_HPP - -namespace webfuse_test -{ - -extern void msleep(long millis); - -} - - -#endif