diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/librados/test_shared.h | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/librados/test_shared.h')
-rw-r--r-- | src/test/librados/test_shared.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/librados/test_shared.h b/src/test/librados/test_shared.h new file mode 100644 index 000000000..6f3747e7b --- /dev/null +++ b/src/test/librados/test_shared.h @@ -0,0 +1,58 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -* +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include <unistd.h> +#include <chrono> +#include <map> +#include <string> +#include <thread> + +#include "include/buffer_fwd.h" + +// helpers shared by librados tests +std::string get_temp_pool_name(const std::string &prefix = "test-rados-api-"); +void assert_eq_sparse(ceph::bufferlist& expected, + const std::map<uint64_t, uint64_t>& extents, + ceph::bufferlist& actual); +class TestAlarm +{ +public: + #ifndef _WIN32 + TestAlarm() { + alarm(1200); + } + ~TestAlarm() { + alarm(0); + } + #else + // TODO: add a timeout mechanism for Windows as well, possibly by using + // CreateTimerQueueTimer. + TestAlarm() { + } + ~TestAlarm() { + } + #endif +}; + +template<class Rep, class Period, typename Func, typename... Args, + typename Return = std::result_of_t<Func&&(Args&&...)>> +Return wait_until(const std::chrono::duration<Rep, Period>& rel_time, + const std::chrono::duration<Rep, Period>& step, + const Return& expected, + Func&& func, Args&&... args) +{ + std::this_thread::sleep_for(rel_time - step); + for (auto& s : {step, step}) { + if (!s.count()) { + break; + } + auto ret = func(std::forward<Args>(args)...); + if (ret == expected) { + return ret; + } + std::this_thread::sleep_for(s); + } + return func(std::forward<Args>(args)...); +} |