@@ -81,6 +81,14 @@ struct ReaderMock : public BaseReader {
81
81
const StrMap& _keyValuePairs;
82
82
};
83
83
84
+ template <typename ClockType>
85
+ typename ClockType::duration absTimeDiff (
86
+ const typename ClockType::time_point& lhs,
87
+ const typename ClockType::time_point& rhs)
88
+ {
89
+ return (rhs < lhs) ? (lhs - rhs) : (rhs - lhs);
90
+ }
91
+
84
92
} // anonymous namespace
85
93
86
94
TEST (Tracer, testTracer)
@@ -161,6 +169,46 @@ TEST(Tracer, testTracer)
161
169
tracer->StartSpanWithOptions (" test-span-with-debug-parent" , options)
162
170
.release ()));
163
171
172
+ options.references .clear ();
173
+ options.references .emplace_back (
174
+ opentracing::SpanReferenceType::FollowsFromRef, &parentCtx);
175
+ options.start_steady_timestamp = Tracer::SteadyClock::now ();
176
+ span.reset (static_cast <Span*>(
177
+ tracer->StartSpanWithOptions (" test-span-with-default-system-timestamp" ,
178
+ options)
179
+ .release ()));
180
+ const auto calculatedSystemTime =
181
+ static_cast <Tracer::SystemClock::time_point>(
182
+ opentracing::convert_time_point<Tracer::SystemClock>(
183
+ span->startTimeSteady ()));
184
+ ASSERT_GE (
185
+ std::chrono::milliseconds (10 ),
186
+ absTimeDiff<Tracer::SystemClock>(
187
+ span->startTimeSystem (), calculatedSystemTime));
188
+
189
+ options.start_system_timestamp = Tracer::SystemClock::now ();
190
+ span.reset (static_cast <Span*>(
191
+ tracer->StartSpanWithOptions (" test-span-with-default-steady-timestamp" ,
192
+ options)
193
+ .release ()));
194
+ const auto calculatedSteadyTime =
195
+ static_cast <Tracer::SteadyClock::time_point>(
196
+ opentracing::convert_time_point<Tracer::SteadyClock>(
197
+ span->startTimeSystem ()));
198
+ ASSERT_GE (
199
+ std::chrono::milliseconds (10 ),
200
+ absTimeDiff<Tracer::SteadyClock>(
201
+ span->startTimeSteady (), calculatedSteadyTime));
202
+
203
+ options.start_system_timestamp = Tracer::SystemClock::now ();
204
+ options.start_steady_timestamp = Tracer::SteadyClock::now ();
205
+ span.reset (static_cast <Span*>(
206
+ tracer->StartSpanWithOptions (" test-span-with-both-timestamps" ,
207
+ options)
208
+ .release ()));
209
+ ASSERT_EQ (options.start_system_timestamp , span->startTimeSystem ());
210
+ ASSERT_EQ (options.start_steady_timestamp , span->startTimeSteady ());
211
+
164
212
span.reset ();
165
213
166
214
opentracing::Tracer::InitGlobal (opentracing::MakeNoopTracer ());
0 commit comments