Skip to content

Commit 86e329e

Browse files
committed
Reworked some plugin priorities and split plugin unit tests into same structure.
1 parent a1168fe commit 86e329e

16 files changed

+1016
-868
lines changed

src/Exceptionless/Plugins/Default/015_PrivateInformationPlugin.cs renamed to src/Exceptionless/Plugins/Default/016_SetEnvironmentUserPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Exceptionless.Dependency;
33

44
namespace Exceptionless.Plugins.Default {
5-
[Priority(15)]
5+
[Priority(16)]
66
public class SetEnvironmentUserPlugin : IEventPlugin {
77
public void Run(EventPluginContext context) {
88
if (!context.Client.Configuration.IncludeUserName)

src/Exceptionless/Plugins/Default/1000_CancelSessionsWithNoUserPlugin.cs renamed to src/Exceptionless/Plugins/Default/900_CancelSessionsWithNoUserPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Exceptionless.Dependency;
33

44
namespace Exceptionless.Plugins.Default {
5-
[Priority(1000)]
5+
[Priority(900)]
66
public class CancelSessionsWithNoUserPlugin : IEventPlugin {
77
public void Run(EventPluginContext context) {
88
if (!context.Event.IsSessionStart())

src/Exceptionless/Plugins/Default/1010_DuplicateCheckerPlugin.cs renamed to src/Exceptionless/Plugins/Default/910_DuplicateCheckerPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Exceptionless.Models;
88

99
namespace Exceptionless.Plugins.Default {
10-
[Priority(1010)]
10+
[Priority(910)]
1111
public class DuplicateCheckerPlugin : IEventPlugin, IDisposable {
1212
private const string LOG_SOURCE = nameof(DuplicateCheckerPlugin);
1313
private static readonly Type _logSourceType = typeof(DuplicateCheckerPlugin);

test/Exceptionless.Tests/Configuration/ConfigurationTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Exceptionless.Configuration;
88
using Exceptionless.Dependency;
9+
using Exceptionless.Logging;
910
using Exceptionless.Models;
1011
using Exceptionless.Storage;
1112
using Exceptionless.Submission;
@@ -179,5 +180,43 @@ public void CanGetLogSettingsMultithreaded() {
179180
while (!result.IsCompleted)
180181
Thread.Yield();
181182
}
183+
184+
[Fact]
185+
public void LogLevels_GetMinLogLevel_Settings_Order() {
186+
var settings = new SettingsDictionary {{"@@log:", "Info"}, {"@@log:*", "Debug"}};
187+
Assert.Equal(LogLevel.Info, settings.GetMinLogLevel(null));
188+
Assert.Equal(LogLevel.Info, settings.GetMinLogLevel(String.Empty));
189+
Assert.Equal(LogLevel.Debug, settings.GetMinLogLevel("*"));
190+
191+
settings = new SettingsDictionary {{"@@log:*", "Debug"}, {"@@log:", "Info"}};
192+
Assert.Equal(LogLevel.Info, settings.GetMinLogLevel(String.Empty));
193+
Assert.Equal(LogLevel.Debug, settings.GetMinLogLevel("*"));
194+
195+
settings = new SettingsDictionary {
196+
{ "@@log:*", "Fatal" },
197+
{ "@@log:", "Debug" },
198+
{ "@@log:abc*", "Off" },
199+
{ "@@log:abc.de*", "Debug" },
200+
{ "@@log:abc.def*", "Info" },
201+
{ "@@log:abc.def.ghi", "Trace" }
202+
};
203+
204+
Assert.Equal(LogLevel.Fatal, settings.GetMinLogLevel("other"));
205+
Assert.Equal(LogLevel.Debug, settings.GetMinLogLevel(null));
206+
Assert.Equal(LogLevel.Debug, settings.GetMinLogLevel(String.Empty));
207+
Assert.Equal(LogLevel.Off, settings.GetMinLogLevel("abc"));
208+
Assert.Equal(LogLevel.Info, settings.GetMinLogLevel("abc.def"));
209+
Assert.Equal(LogLevel.Trace, settings.GetMinLogLevel("abc.def.ghi"));
210+
211+
settings = new SettingsDictionary {
212+
{ "@@log:abc.def.ghi", "Trace" },
213+
{ "@@log:abc.def*", "Info" },
214+
{ "@@log:abc*", "Off" }
215+
};
216+
217+
Assert.Equal(LogLevel.Off, settings.GetMinLogLevel("abc"));
218+
Assert.Equal(LogLevel.Info, settings.GetMinLogLevel("abc.def"));
219+
Assert.Equal(LogLevel.Trace, settings.GetMinLogLevel("abc.def.ghi"));
220+
}
182221
}
183222
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using Exceptionless.Dependency;
3+
using Exceptionless.Plugins;
4+
using Exceptionless.Plugins.Default;
5+
using Exceptionless.Models;
6+
using Exceptionless.Submission;
7+
using Exceptionless.Tests.Utility;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace Exceptionless.Tests.Plugins {
12+
public class HandleAggregateExceptionsPluginTests : PluginTestBase {
13+
public HandleAggregateExceptionsPluginTests(ITestOutputHelper output) : base(output) { }
14+
15+
[Fact]
16+
public void SingleInnerException() {
17+
var client = CreateClient();
18+
var plugin = new HandleAggregateExceptionsPlugin();
19+
20+
var exceptionOne = new Exception("one");
21+
var exceptionTwo = new Exception("two");
22+
23+
var context = new EventPluginContext(client, new Event());
24+
context.ContextData.SetException(exceptionOne);
25+
plugin.Run(context);
26+
Assert.False(context.Cancel);
27+
28+
context = new EventPluginContext(client, new Event());
29+
context.ContextData.SetException(new AggregateException(exceptionOne));
30+
plugin.Run(context);
31+
Assert.False(context.Cancel);
32+
Assert.Equal(exceptionOne, context.ContextData.GetException());
33+
34+
context = new EventPluginContext(client, new Event());
35+
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
36+
plugin.Run(context);
37+
Assert.True(context.Cancel);
38+
}
39+
40+
[Fact]
41+
public void MultipleInnerException() {
42+
var submissionClient = new InMemorySubmissionClient();
43+
var client = new ExceptionlessClient("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw");
44+
client.Configuration.Resolver.Register<ISubmissionClient>(submissionClient);
45+
46+
var plugin = new HandleAggregateExceptionsPlugin();
47+
var exceptionOne = new Exception("one");
48+
var exceptionTwo = new Exception("two");
49+
50+
var context = new EventPluginContext(client, new Event());
51+
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
52+
plugin.Run(context);
53+
Assert.True(context.Cancel);
54+
55+
client.ProcessQueue();
56+
Assert.Equal(2, submissionClient.Events.Count);
57+
}
58+
}
59+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System;
2+
using Exceptionless.Plugins;
3+
using Exceptionless.Plugins.Default;
4+
using Exceptionless.Models;
5+
using Xunit;
6+
using Xunit.Abstractions;
7+
8+
namespace Exceptionless.Tests.Plugins {
9+
public class EventExclusionPluginTests : PluginTestBase {
10+
public EventExclusionPluginTests(ITestOutputHelper output) : base(output) { }
11+
12+
[Fact]
13+
public void EventExclusions() {
14+
var client = CreateClient();
15+
var plugin = new EventExclusionPlugin();
16+
17+
// ignore any event that has a value of 2
18+
client.Configuration.AddEventExclusion(e => e.Value.GetValueOrDefault() != 2);
19+
20+
var ev = new Event { Value = 1 };
21+
var context = new EventPluginContext(client, ev);
22+
plugin.Run(context);
23+
Assert.False(context.Cancel);
24+
25+
ev.Value = 2;
26+
context = new EventPluginContext(client, ev);
27+
plugin.Run(context);
28+
Assert.True(context.Cancel);
29+
}
30+
31+
[Theory]
32+
[InlineData(null, null, null, null, false)]
33+
[InlineData("Test", null, null, null, false)]
34+
[InlineData("Test", "Trace", null, null, false)]
35+
[InlineData("Test", "Off", null, null, true)]
36+
[InlineData("Test", "Abc", null, null, false)]
37+
[InlineData(null, "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix, "Off", true)]
38+
[InlineData(null, "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Off", true)]
39+
[InlineData("", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix, "Off", true)] // Becomes Global Log Level
40+
[InlineData("", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Off", true)]
41+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", true)]
42+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "false", true)]
43+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "no", true)]
44+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "0", true)]
45+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "true", false)]
46+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "yes", false)]
47+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "1", false)]
48+
[InlineData("Test", "Info", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", false)]
49+
[InlineData("Test", "Trace", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Debug", true)]
50+
[InlineData("Test", "Warn", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Debug", false)]
51+
[InlineData("Test", "Warn", SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Off", true)]
52+
public void LogLevels(string source, string level, string settingKey, string settingValue, bool cancelled) {
53+
var client = CreateClient();
54+
if (settingKey != null)
55+
client.Configuration.Settings.Add(settingKey, settingValue);
56+
57+
var ev = new Event { Type = Event.KnownTypes.Log, Source = source };
58+
if (!String.IsNullOrEmpty(level))
59+
ev.SetProperty(Event.KnownDataKeys.Level, level);
60+
61+
var context = new EventPluginContext(client, ev);
62+
var plugin = new EventExclusionPlugin();
63+
plugin.Run(context);
64+
Assert.Equal(cancelled, context.Cancel);
65+
}
66+
67+
[Theory]
68+
[InlineData(null, null, null, null, false)]
69+
[InlineData("usage", null, null, null, false)]
70+
[InlineData("usage", "test", null, null, false)]
71+
[InlineData("usage", "test", "@@usage:Test", "true", false)]
72+
[InlineData("usage", "test", "@@usage:Test", "false", true)]
73+
[InlineData("usage", "EX-FEAT: 1234567890", "@@usage:EX-FEAT: 1234567890", "false", true)]
74+
[InlineData("usage", "test", "@@usage:*", "false", true)]
75+
[InlineData("404", null, "@@404:*", "false", true)]
76+
[InlineData("404", null, "@@404:", "false", true)]
77+
[InlineData("404", "", "@@404:", "false", true)]
78+
[InlineData("404", "/unknown", "@@404:*", "false", true)]
79+
[InlineData("404", "/unknown", "@@404:/unknown", "false", true)]
80+
[InlineData("404", "/unknown", "@@404:/unknown", "true", false)]
81+
[InlineData("404", "/example.php", "@@404:*.php", "false", true)]
82+
public void SourceType(string type, string source, string settingKey, string settingValue, bool cancelled) {
83+
var client = CreateClient();
84+
if (settingKey != null)
85+
client.Configuration.Settings.Add(settingKey, settingValue);
86+
87+
var ev = new Event { Type = type, Source = source };
88+
var context = new EventPluginContext(client, ev);
89+
var plugin = new EventExclusionPlugin();
90+
plugin.Run(context);
91+
Assert.Equal(cancelled, context.Cancel);
92+
Assert.Equal(source, ev.Source);
93+
}
94+
95+
[Theory]
96+
[InlineData(null, null, null, null, false)]
97+
[InlineData("Test", null, null, null, false)]
98+
[InlineData("Test", "Trace", null, null, true)]
99+
[InlineData("Test", "Warn", null, null, false)]
100+
[InlineData("Test", "Error", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", false)]
101+
[InlineData("Test", "Debug", SettingsDictionary.KnownKeys.LogLevelPrefix + "Test", "Debug", false)]
102+
public void LogLevelsWithInfoDefault(string source, string level, string settingKey, string settingValue, bool cancelled) {
103+
var client = CreateClient();
104+
client.Configuration.Settings.Add(SettingsDictionary.KnownKeys.LogLevelPrefix + "*", "Info");
105+
if (settingKey != null)
106+
client.Configuration.Settings.Add(settingKey, settingValue);
107+
108+
var ev = new Event { Type = Event.KnownTypes.Log, Source = source };
109+
if (!String.IsNullOrEmpty(level))
110+
ev.SetProperty(Event.KnownDataKeys.Level, level);
111+
112+
var context = new EventPluginContext(client, ev);
113+
var plugin = new EventExclusionPlugin();
114+
plugin.Run(context);
115+
Assert.Equal(cancelled, context.Cancel);
116+
}
117+
118+
[Theory]
119+
[InlineData(null, false)]
120+
[InlineData("@@error:TestException", false)]
121+
[InlineData("@@error:Exception", false)]
122+
[InlineData("@@error:System.Exception", true)]
123+
[InlineData("@@error:*Exception", true)]
124+
[InlineData("@@error:*", true)]
125+
public void ExceptionType(string settingKey, bool cancelled) {
126+
var client = CreateClient();
127+
if (settingKey != null)
128+
client.Configuration.Settings.Add(settingKey, Boolean.FalseString);
129+
130+
var plugin = new EventExclusionPlugin();
131+
var context = new EventPluginContext(client, new Event());
132+
context.ContextData.SetException(GetException());
133+
plugin.Run(context);
134+
Assert.Equal(cancelled, context.Cancel);
135+
136+
context.ContextData.SetException(GetNestedSimpleException());
137+
plugin.Run(context);
138+
Assert.Equal(cancelled, context.Cancel);
139+
}
140+
}
141+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System.Collections.Generic;
2+
using Exceptionless.Dependency;
3+
using Exceptionless.Plugins;
4+
using Exceptionless.Plugins.Default;
5+
using Exceptionless.Models;
6+
using Exceptionless.Models.Data;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Exceptionless.Tests.Plugins {
11+
public class ConfigurationDefaultsPluginTests : PluginTestBase {
12+
public ConfigurationDefaultsPluginTests(ITestOutputHelper output) : base(output) { }
13+
14+
[Fact]
15+
public void EnsureNoDuplicateTagsOrData() {
16+
var client = CreateClient();
17+
var context = new EventPluginContext(client, new Event());
18+
19+
var plugin = new ConfigurationDefaultsPlugin();
20+
plugin.Run(context);
21+
Assert.Empty(context.Event.Tags);
22+
23+
client.Configuration.DefaultTags.Add(Event.KnownTags.Critical);
24+
plugin.Run(context);
25+
Assert.Single(context.Event.Tags);
26+
Assert.Empty(context.Event.Data);
27+
28+
client.Configuration.DefaultData.Add("Message", new { Exceptionless = "Is Awesome!" });
29+
for (int index = 0; index < 2; index++) {
30+
plugin.Run(context);
31+
Assert.Single(context.Event.Tags);
32+
Assert.Single(context.Event.Data);
33+
}
34+
}
35+
36+
[Fact]
37+
public void IgnoredProperties() {
38+
var client = CreateClient();
39+
client.Configuration.DefaultData.Add("Message", "Test");
40+
41+
var context = new EventPluginContext(client, new Event());
42+
var plugin = new ConfigurationDefaultsPlugin();
43+
plugin.Run(context);
44+
Assert.Single(context.Event.Data);
45+
Assert.Equal("Test", context.Event.Data["Message"]);
46+
47+
client.Configuration.AddDataExclusions("Ignore*");
48+
client.Configuration.DefaultData.Add("Ignored", "Test");
49+
plugin.Run(context);
50+
Assert.Single(context.Event.Data);
51+
Assert.Equal("Test", context.Event.Data["Message"]);
52+
}
53+
54+
[Fact]
55+
public void SerializedProperties() {
56+
var client = CreateClient();
57+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.EnvironmentInfo, new EnvironmentInfo { MachineName = "blake" });
58+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.Error, new Error { Message = "blake" });
59+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.Level, "Debug");
60+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.ManualStackingInfo, "blake");
61+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.RequestInfo, new RequestInfo { Host = "blake" });
62+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.SimpleError, new SimpleError { Message = "blake" });
63+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.SubmissionMethod, "test");
64+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.TraceLog, new List<string>());
65+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.UserDescription, new UserDescription("[email protected]", "blake"));
66+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.UserInfo, new UserInfo("blake"));
67+
client.Configuration.DefaultData.Add(Event.KnownDataKeys.Version, "1.0");
68+
69+
var serializer = client.Configuration.Resolver.GetJsonSerializer();
70+
var context = new EventPluginContext(client, new Event());
71+
var plugin = new ConfigurationDefaultsPlugin();
72+
plugin.Run(context);
73+
Assert.Equal(11, context.Event.Data.Count);
74+
Assert.True(context.Event.Data[Event.KnownDataKeys.EnvironmentInfo] is string);
75+
Assert.Equal("blake", context.Event.GetEnvironmentInfo().MachineName);
76+
Assert.Equal("blake", context.Event.GetEnvironmentInfo(serializer).MachineName);
77+
Assert.True(context.Event.Data[Event.KnownDataKeys.Error] is string);
78+
Assert.Equal("blake", context.Event.GetError().Message);
79+
Assert.Equal("blake", context.Event.GetError(serializer).Message);
80+
Assert.Equal("Debug", context.Event.Data[Event.KnownDataKeys.Level]);
81+
Assert.Equal("blake", context.Event.Data[Event.KnownDataKeys.ManualStackingInfo]);
82+
Assert.True(context.Event.Data[Event.KnownDataKeys.RequestInfo] is string);
83+
Assert.Equal("blake", context.Event.GetRequestInfo().Host);
84+
Assert.Equal("blake", context.Event.GetRequestInfo(serializer).Host);
85+
Assert.True(context.Event.Data[Event.KnownDataKeys.SimpleError] is string);
86+
Assert.Equal("blake", context.Event.GetSimpleError().Message);
87+
Assert.Equal("blake", context.Event.GetSimpleError(serializer).Message);
88+
Assert.Equal("test", context.Event.Data[Event.KnownDataKeys.SubmissionMethod]);
89+
Assert.True(context.Event.Data[Event.KnownDataKeys.TraceLog] is string);
90+
Assert.True(context.Event.Data[Event.KnownDataKeys.UserDescription] is string);
91+
Assert.Equal("blake", context.Event.GetUserDescription().Description);
92+
Assert.Equal("blake", context.Event.GetUserDescription(serializer).Description);
93+
Assert.True(context.Event.Data[Event.KnownDataKeys.UserInfo] is string);
94+
Assert.Equal("blake", context.Event.GetUserIdentity().Identity);
95+
Assert.Equal("blake", context.Event.GetUserIdentity(serializer).Identity);
96+
Assert.Equal("1.0", context.Event.Data[Event.KnownDataKeys.Version]);
97+
98+
context.Event.SetUserIdentity(new UserInfo("blake"));
99+
Assert.Equal("blake", context.Event.GetUserIdentity().Identity);
100+
Assert.Equal("blake", context.Event.GetUserIdentity(serializer).Identity);
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)