Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/StatsdClient/Worker/AsynchronousWorker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace StatsdClient.Worker
Expand Down Expand Up @@ -111,6 +112,15 @@ private void Dequeue()
}
}
}
#if NETFRAMEWORK
catch (ThreadAbortException e)
{
Debug.WriteLine(e.Message);
// This is the defined behavior of a ThreadAbortException, but it doesn't happen on
// the .NET Framework in 64-bit release builds using RyuJIT
throw;
}
#endif
catch (Exception e)
{
Debug.WriteLine(e.Message);
Expand Down
2 changes: 1 addition & 1 deletion tests/StatsdClient.Tests/StatsdClient.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>StatsdClient.snk</AssemblyOriginatorKeyFile>
<NoWarn>0618</NoWarn>
Expand Down
4 changes: 2 additions & 2 deletions tests/StatsdClient.Tests/TelemetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private void AssertTelemetryReceived(Dictionary<string, int> expectedResults)
_telemetry.Flush();
foreach (var m in _metrics)
{
var nameWithoutTags = m.Split("|")[0];
var part = nameWithoutTags.Split(":");
var nameWithoutTags = m.Split('|')[0];
var part = nameWithoutTags.Split(':');
var metricName = part[0];
var metricValue = int.Parse(part[1]);

Expand Down
36 changes: 36 additions & 0 deletions tests/StatsdClient.Tests/Worker/AsynchronousWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ public void DisposeNotBlock()
worker.Dispose();
}

#if NETFRAMEWORK
/// <summary>
/// This test can only fail when run on the .NET Framework in 64-bit release build using RyuJIT.
/// </summary>
[Test]
public void ThreadAbortExceptionExitsWorker()
{
var domain = AppDomain.CreateDomain("ThreadAbortExceptionExitsWorkerTest");

var domainDelegate = (AppDomainDelegate)domain.CreateInstanceFromAndUnwrap(
typeof(AppDomainDelegate).Assembly.Location,
typeof(AppDomainDelegate).FullName);

domainDelegate.Execute();

Assert.DoesNotThrow(() => AppDomain.Unload(domain));
}
#endif

private AsynchronousWorker<int> CreateWorker(int workerThreadCount = 2)
{
var worker = new AsynchronousWorker<int>(
Expand All @@ -92,5 +111,22 @@ private AsynchronousWorker<int> CreateWorker(int workerThreadCount = 2)
_workers.Add(worker);
return worker;
}

#if NETFRAMEWORK
private class AppDomainDelegate : MarshalByRefObject
{
public void Execute()
{
// This intentionally avoids referencing AsynchronousWorkerTests types
// because the assembly would fail to load
_ = new AsynchronousWorker<int>(
new Mock<IAsynchronousWorkerHandler<int>>().Object,
new Mock<IWaiter>().Object,
1,
10,
null);
}
}
#endif
}
}
4 changes: 3 additions & 1 deletion tests/StatsdClient.Tests/utils/AbstractServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Tests.Utils
{
internal abstract class AbstractServer : IDisposable
{
private static readonly char[] MessageSplitChars = new[] { '\n' };

private readonly ManualResetEventSlim _serverStop = new ManualResetEventSlim(false);
private readonly List<string> _messagesReceived = new List<string>();
private Task _receiver;
Expand Down Expand Up @@ -52,7 +54,7 @@ private void ReadFromServer(int bufferSize)
if (count.HasValue && count.Value > 0)
{
var message = System.Text.Encoding.UTF8.GetString(buffer, 0, count.Value);
_messagesReceived.AddRange(message.Split("\n", StringSplitOptions.RemoveEmptyEntries));
_messagesReceived.AddRange(message.Split(MessageSplitChars, StringSplitOptions.RemoveEmptyEntries));
}
else
{
Expand Down