-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
TraceEventCacheClassTests.cs
82 lines (74 loc) · 2.84 KB
/
TraceEventCacheClassTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Diagnostics.TraceSourceTests
{
public class TraceEventCacheClassTests
{
[Fact]
public void DateTimePropertyTest()
{
var cache = new TraceEventCache();
var begin = DateTime.UtcNow;
var dt = cache.DateTime;
var end = DateTime.UtcNow;
Assert.True(dt >= begin);
Assert.True(dt <= end);
var cached = cache.DateTime;
Assert.Equal(dt, cached);
}
[Fact]
public void ProcessIdTest()
{
var cache = new TraceEventCache();
int id = cache.ProcessId;
int expected = Environment.ProcessId;
Assert.Equal((int)expected, id);
}
[Fact]
public void ThreadIdTest()
{
var cache = new TraceEventCache();
var id = cache.ThreadId;
Assert.NotNull(id);
Assert.NotEqual("", id);
}
[Fact]
public void TimestampTest()
{
var cache = new TraceEventCache();
var dt1 = cache.Timestamp;
var dt2 = cache.Timestamp;
Assert.Equal(dt1, dt2);
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/50957", typeof(PlatformDetection), nameof(PlatformDetection.IsBrowser), nameof(PlatformDetection.IsMonoAOT))]
public void CallstackTest_NotEmpty()
{
var cache = new TraceEventCache();
Assert.NotEmpty(cache.Callstack);
}
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/50957", typeof(PlatformDetection), nameof(PlatformDetection.IsBrowser), nameof(PlatformDetection.IsMonoAOT))]
public void CallstackTest_ContainsExpectedFrames()
{
var cache = new TraceEventCache();
Assert.Contains("System.Environment.get_StackTrace()", cache.Callstack);
}
[Fact]
public void LogicalOperationStack()
{
var cache = new TraceEventCache();
var logicalOperationStack = cache.LogicalOperationStack;
Assert.Equal(0, logicalOperationStack.Count);
Trace.CorrelationManager.StartLogicalOperation("SecondaryThread");
Trace.CorrelationManager.StartLogicalOperation("MainThread");
Assert.NotNull(logicalOperationStack);
Assert.Equal(2, logicalOperationStack.Count);
Assert.Equal("MainThread", logicalOperationStack.Pop().ToString());
Assert.Equal("SecondaryThread", logicalOperationStack.Peek().ToString());
Trace.CorrelationManager.StopLogicalOperation();
Assert.Equal(0, logicalOperationStack.Count);
}
}
}