summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/opentracing-cpp/test/util_test.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/opentracing-cpp/test/util_test.cpp
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.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/jaegertracing/opentracing-cpp/test/util_test.cpp')
-rw-r--r--src/jaegertracing/opentracing-cpp/test/util_test.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/jaegertracing/opentracing-cpp/test/util_test.cpp b/src/jaegertracing/opentracing-cpp/test/util_test.cpp
new file mode 100644
index 000000000..9c1e30d02
--- /dev/null
+++ b/src/jaegertracing/opentracing-cpp/test/util_test.cpp
@@ -0,0 +1,26 @@
+#include <opentracing/util.h>
+#include <cmath>
+#include <cstdlib> // Work around to https://stackoverflow.com/a/30084734.
+using namespace opentracing;
+
+#define CATCH_CONFIG_MAIN
+#include <opentracing/catch2/catch.hpp>
+
+TEST_CASE("convert_time_point") {
+ SECTION("We can convert between time points of different clocks") {
+ // Check that converting from a system_clock time_point to a steady_clock
+ // time point and then back again produces approximately the same
+ // system_clock time_point.
+ auto t1 = SystemClock::now();
+ auto t2 = convert_time_point<SteadyClock>(t1);
+ auto t3 = convert_time_point<SystemClock>(t2);
+ auto difference = std::abs(
+ std::chrono::duration_cast<std::chrono::microseconds>(t3 - t1).count());
+ CHECK(difference < 100);
+ }
+
+ SECTION("Converting times from the same clock gives the identity") {
+ auto t = SystemClock::now();
+ CHECK(t == convert_time_point<SystemClock>(t));
+ }
+}