Skip to content

Commit 41776b6

Browse files
committed
Fix stopwatch tests
1 parent d484266 commit 41776b6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tracer/test/Datadog.Trace.Tests/Util/StopwatchTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ public void ComputesCorrectTimespan()
2323
sw.Stop();
2424

2525
// Extract the internal ticks
26+
#if NET6_0_OR_GREATER
27+
// Since at least .NET 6, Stopwatch.GetRawElapsedTicks is directly exposed as ElapsedTicks
28+
// and in .NET 10+ the GetRawElapsedTicks method doesn't exist
29+
var stopwatchTicks = sw.ElapsedTicks;
30+
#else
2631
var stopwatchTicks = (long)typeof(Stopwatch)
2732
.GetMethod("GetRawElapsedTicks", BindingFlags.Instance | BindingFlags.NonPublic)
2833
.Invoke(sw, null);
29-
34+
#endif
3035
var elapsed = StopwatchHelpers.GetElapsed(stopwatchTicks);
3136

3237
Assert.Equal(sw.Elapsed, elapsed);

0 commit comments

Comments
 (0)