diff --git a/Directory.Build.props b/Directory.Build.props index 901474c..3b30462 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,20 +1,21 @@ - 2.9.2 + 2.9.4 - + - + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb $(MSBuildThisFileDirectory)justeat-oss.snk JUSTEAT_OSS + $(MSBuildThisFileDirectory)JustEat.StatsD.ruleset Just Eat Copyright (c) Just Eat 2015-$([System.DateTime]::Now.ToString(yyyy)) true diff --git a/JustEat.StatsD.ruleset b/JustEat.StatsD.ruleset new file mode 100644 index 0000000..89ac087 --- /dev/null +++ b/JustEat.StatsD.ruleset @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/JustEat.StatsD.sln b/JustEat.StatsD.sln index adb4d52..37d30d4 100644 --- a/JustEat.StatsD.sln +++ b/JustEat.StatsD.sln @@ -1,6 +1,7 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29215.179 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{06BE4D4A-B0DF-465D-9BAC-6CC3C9779A37}" ProjectSection(SolutionItems) = preProject @@ -13,12 +14,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{06BE4D build.sh = build.sh CHANGELOG.md = CHANGELOG.md Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets global.json = global.json + JustEat.StatsD.ruleset = JustEat.StatsD.ruleset LICENSE = LICENSE README.md = README.md - version.props = version.props - Directory.Build.targets = Directory.Build.targets ReferenceAssemblies.props = ReferenceAssemblies.props + version.props = version.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JustEat.StatsD", "src\JustEat.StatsD\JustEat.StatsD.csproj", "{6A338D71-E28B-455A-9E9D-3667EE659542}" diff --git a/src/JustEat.StatsD/SocketTransport.cs b/src/JustEat.StatsD/SocketTransport.cs index b0c00d9..8e5b846 100644 --- a/src/JustEat.StatsD/SocketTransport.cs +++ b/src/JustEat.StatsD/SocketTransport.cs @@ -50,7 +50,10 @@ public void Send(in ArraySegment metric) return; } +#pragma warning disable CA2000 var pool = GetPool(endpoint); +#pragma warning restore CA2000 + var socket = pool.PopOrCreate(); try diff --git a/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj b/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj index 9de6edd..8b3e7e8 100644 --- a/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj +++ b/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/tests/JustEat.StatsD.Tests/SocketTransportTests.cs b/tests/JustEat.StatsD.Tests/SocketTransportTests.cs index 3cf253f..9d1356e 100644 --- a/tests/JustEat.StatsD.Tests/SocketTransportTests.cs +++ b/tests/JustEat.StatsD.Tests/SocketTransportTests.cs @@ -22,8 +22,10 @@ public static void ValidSocketTransportCanBeConstructed() public static void SocketTransportCanSendOverUdpWithoutError() { // using block not used here so the finalizer gets some code coverage - var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp); - transport.Send("teststat:1|c"); + using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp)) + { + transport.Send("teststat:1|c"); + } } [Fact] diff --git a/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs b/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs index 41aa2a1..e6ed55e 100644 --- a/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs +++ b/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs @@ -18,16 +18,17 @@ public static void Decrement_Sends_Multiple_Metrics() Prefix = "red", }; - var publisher = new StatsDPublisher(config, mock.Object); - - // Act - publisher.Decrement(10, "black"); - publisher.Decrement(-10, "yellow"); - publisher.Decrement(10, 1, "pink"); - publisher.Decrement(-10, 1, "orange"); - publisher.Decrement(10, 1, new[] { "white", "blue" }); - publisher.Decrement(10, 1, new List() { "green", "red" }); - publisher.Decrement(10, 1, null as IEnumerable); + using (var publisher = new StatsDPublisher(config, mock.Object)) + { + // Act + publisher.Decrement(10, "black"); + publisher.Decrement(-10, "yellow"); + publisher.Decrement(10, 1, "pink"); + publisher.Decrement(-10, 1, "orange"); + publisher.Decrement(10, 1, new[] { "white", "blue" }); + publisher.Decrement(10, 1, new List() { "green", "red" }); + publisher.Decrement(10, 1, null as IEnumerable); + } // Assert mock.Verify((p) => p.Send(It.Ref>.IsAny), Times.Exactly(8)); @@ -44,16 +45,17 @@ public static void Increment_Sends_Multiple_Metrics() Prefix = "red", }; - var publisher = new StatsDPublisher(config, mock.Object); - - // Act - publisher.Increment(10, "black"); - publisher.Increment(-10, "yellow"); - publisher.Increment(10, 1, "pink"); - publisher.Increment(-10, 1, "orange"); - publisher.Increment(10, 1, new[] { "white", "blue" }); - publisher.Increment(10, 1, new List() { "green", "red" }); - publisher.Increment(10, 1, null as IEnumerable); + using (var publisher = new StatsDPublisher(config, mock.Object)) + { + // Act + publisher.Increment(10, "black"); + publisher.Increment(-10, "yellow"); + publisher.Increment(10, 1, "pink"); + publisher.Increment(-10, 1, "orange"); + publisher.Increment(10, 1, new[] { "white", "blue" }); + publisher.Increment(10, 1, new List() { "green", "red" }); + publisher.Increment(10, 1, null as IEnumerable); + } // Assert mock.Verify((p) => p.Send(It.Ref>.IsAny), Times.Exactly(8)); @@ -66,23 +68,24 @@ public static void Metrics_Not_Sent_If_Array_Is_Null_Or_Empty() var mock = new Mock(); var config = new StatsDConfiguration(); - var publisher = new StatsDPublisher(config, mock.Object); - - // Act - publisher.Decrement(-1, 1, null as string[]); - publisher.Increment(-1, 1, null as string[]); - publisher.Decrement(1, 1, null as string[]); - publisher.Increment(1, 1, null as string[]); - publisher.Decrement(1, 1, Array.Empty()); - publisher.Increment(1, 1, Array.Empty()); - publisher.Decrement(-1, 1, Array.Empty()); - publisher.Increment(-1, 1, Array.Empty()); - publisher.Decrement(-1, 1, new List()); - publisher.Increment(-1, 1, new List()); - publisher.Decrement(1, 1, null as IEnumerable); - publisher.Increment(1, 1, null as IEnumerable); - publisher.Decrement(1, 1, new[] { string.Empty }); - publisher.Increment(1, 1, new[] { string.Empty }); + using (var publisher = new StatsDPublisher(config, mock.Object)) + { + // Act + publisher.Decrement(-1, 1, null as string[]); + publisher.Increment(-1, 1, null as string[]); + publisher.Decrement(1, 1, null as string[]); + publisher.Increment(1, 1, null as string[]); + publisher.Decrement(1, 1, Array.Empty()); + publisher.Increment(1, 1, Array.Empty()); + publisher.Decrement(-1, 1, Array.Empty()); + publisher.Increment(-1, 1, Array.Empty()); + publisher.Decrement(-1, 1, new List()); + publisher.Increment(-1, 1, new List()); + publisher.Decrement(1, 1, null as IEnumerable); + publisher.Increment(1, 1, null as IEnumerable); + publisher.Decrement(1, 1, new[] { string.Empty }); + publisher.Increment(1, 1, new[] { string.Empty }); + } // Assert mock.Verify((p) => p.Send(It.IsAny>()), Times.Never()); @@ -95,11 +98,12 @@ public static void Metrics_Not_Sent_If_No_Metrics() var mock = new Mock(); var config = new StatsDConfiguration(); - var publisher = new StatsDPublisher(config, mock.Object); - - // Act - publisher.Decrement(1, 0, new[] { "foo" }); - publisher.Increment(1, 0, new[] { "bar" }); + using (var publisher = new StatsDPublisher(config, mock.Object)) + { + // Act + publisher.Decrement(1, 0, new[] { "foo" }); + publisher.Increment(1, 0, new[] { "bar" }); + } // Assert mock.Verify((p) => p.Send(It.IsAny>()), Times.Never());