-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathApmTransactionManagerTests.cs
More file actions
125 lines (101 loc) · 3.97 KB
/
Copy pathApmTransactionManagerTests.cs
File metadata and controls
125 lines (101 loc) · 3.97 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using Ev.ServiceBus.Apm;
using Xunit;
namespace Ev.ServiceBus.UnitTests;
public sealed class ApmTransactionManagerTests : IDisposable
{
public ApmTransactionManagerTests()
{
ApmTransactionManager.ResetForTests();
}
public void Dispose()
{
ApmTransactionManager.ResetForTests();
}
[Fact]
public void ShouldSuppressError_WithTrackedTransactionId_ReturnsTrue()
{
ApmTransactionManager.AddCancelledTransactionIdForTests("tx-abc");
var result = ApmTransactionManager.ShouldSuppressError(
"tx-abc",
"System.Threading.Tasks.TaskCanceledException",
"some.culprit");
Assert.True(result);
}
[Fact]
public void ShouldSuppressError_WithTrackedTransactionId_RemovesIdAfterMatch()
{
ApmTransactionManager.AddCancelledTransactionIdForTests("tx-abc");
ApmTransactionManager.ShouldSuppressError("tx-abc", "System.Threading.Tasks.TaskCanceledException", "some.culprit");
var secondResult = ApmTransactionManager.ShouldSuppressError(
"tx-abc",
"System.Threading.Tasks.TaskCanceledException",
"some.culprit");
Assert.False(secondResult);
}
[Fact]
public void ShouldSuppressError_WithAmqpReceiverCulpritAndTaskCanceledException_ReturnsTrue()
{
var result = ApmTransactionManager.ShouldSuppressError(
"untracked-tx",
"System.Threading.Tasks.TaskCanceledException",
"Azure.Messaging.ServiceBus.Amqp.AmqpReceiver+<ReceiveMessagesAsyncInternal>d__45");
Assert.True(result);
}
[Fact]
public void ShouldSuppressError_WithAmqpReceiverCulpritAndOperationCanceledException_ReturnsTrue()
{
var result = ApmTransactionManager.ShouldSuppressError(
"untracked-tx",
"System.OperationCanceledException",
"Azure.Messaging.ServiceBus.Amqp.AmqpReceiver+SomeInternalMethod");
Assert.True(result);
}
[Fact]
public void ShouldSuppressError_WithAmqpReceiverCulpritButServiceBusException_ReturnsFalse()
{
var result = ApmTransactionManager.ShouldSuppressError(
"untracked-tx",
"Azure.Messaging.ServiceBus.ServiceBusException",
"Azure.Messaging.ServiceBus.Amqp.AmqpReceiver+SomeInternalMethod");
Assert.False(result);
}
[Fact]
public void ShouldSuppressError_WithNonAmqpCulpritAndTaskCanceledException_ReturnsFalse()
{
var result = ApmTransactionManager.ShouldSuppressError(
null,
"System.Threading.Tasks.TaskCanceledException",
"Some.Other.Namespace.SomeClass+SomeMethod");
Assert.False(result);
}
[Fact]
public void ShouldSuppressError_WithUntrackedIdAndNonCancelledException_ReturnsFalse()
{
var result = ApmTransactionManager.ShouldSuppressError(
"not-tracked",
"System.InvalidOperationException",
"Some.Class+SomeMethod");
Assert.False(result);
}
[Fact]
public void ShouldSuppressError_WithNullTransactionIdAndNullCulprit_ReturnsFalse()
{
var result = ApmTransactionManager.ShouldSuppressError(null, null, null);
Assert.False(result);
}
[Fact]
public void ShouldSuppressError_WhenCapExceeded_CulpritPathStillSuppresses()
{
// Simulate the cap-exceeded scenario: OnReceiveCancelled stops tracking IDs once the
// dictionary is full. Errors for those untracked transactions must still be suppressed
// by the culprit-based path (Case 2).
for (var i = 0; i < 1000; i++)
ApmTransactionManager.AddCancelledTransactionIdForTests($"capped-tx-{i}");
var result = ApmTransactionManager.ShouldSuppressError(
"untracked-due-to-cap",
"System.Threading.Tasks.TaskCanceledException",
"Azure.Messaging.ServiceBus.Amqp.AmqpReceiver+<ReceiveMessagesAsyncInternal>d__45");
Assert.True(result);
}
}