From 44866bdc819b928d4767ef1bd80bdd8ce930152f Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 7 Oct 2018 18:40:52 +0100 Subject: [PATCH 1/4] Do not dispose of stream Do not dispose of the stream as it is owned by the TcpClient. --- src/JustEat.StatsD.Tests/IntegrationTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/JustEat.StatsD.Tests/IntegrationTests.cs b/src/JustEat.StatsD.Tests/IntegrationTests.cs index 702fb8c3..6187ea0b 100644 --- a/src/JustEat.StatsD.Tests/IntegrationTests.cs +++ b/src/JustEat.StatsD.Tests/IntegrationTests.cs @@ -89,11 +89,10 @@ private static async Task SendCommandAsync(string command) int bytesRead; - using (var stream = client.GetStream()) - { - await stream.WriteAsync(input); - bytesRead = await stream.ReadAsync(output); - } + var stream = client.GetStream(); + + await stream.WriteAsync(input); + bytesRead = await stream.ReadAsync(output); output = output.AsSpan(0, bytesRead).ToArray(); From b94c34a216c98a6a89cf1bf9b1c5ee9f1977658d Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 7 Oct 2018 20:26:56 +0100 Subject: [PATCH 2/4] Increase statsd flush interval Increase the statsd flush interval for metrics to 2 minutes to stop metrics published by the integration tests being dropped before they're read for the assertions. The default was 10 seconds. --- src/JustEat.StatsD.Tests/statsdconfig.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/JustEat.StatsD.Tests/statsdconfig.js b/src/JustEat.StatsD.Tests/statsdconfig.js index 3dd800e5..abf1512a 100644 --- a/src/JustEat.StatsD.Tests/statsdconfig.js +++ b/src/JustEat.StatsD.Tests/statsdconfig.js @@ -1,5 +1,6 @@ { graphiteHost: "", port: 8125, - backends: [] + backends: [], + flushInterval: 120000 } From 68bfe5aeb2bdec1dae88550b43dc7505dc4a2120 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 7 Oct 2018 21:36:08 +0100 Subject: [PATCH 3/4] Delay before reading Delay after the last write before trying to read the stats back in the integration tests' assertions. --- src/JustEat.StatsD.Tests/IntegrationTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/JustEat.StatsD.Tests/IntegrationTests.cs b/src/JustEat.StatsD.Tests/IntegrationTests.cs index 6187ea0b..c2283518 100644 --- a/src/JustEat.StatsD.Tests/IntegrationTests.cs +++ b/src/JustEat.StatsD.Tests/IntegrationTests.cs @@ -57,6 +57,9 @@ public static async Task Can_Send_Metrics_To_StatsD() publisher.Decrement(1, 0, "red", "green"); // 7 publisher.Decrement(4, 1, "red", "green"); // 3 + // Allow enough time for metrics to be registered + await Task.Delay(TimeSpan.FromSeconds(0.5)); + // Assert var result = await SendCommandAsync("counters"); result.Value(config.Prefix + ".apple").ShouldBe(1); From 6b35519c376ce8ac5ec1f096a5af9d7f77da12c5 Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 8 Oct 2018 10:40:56 +0100 Subject: [PATCH 4/4] Up the wait before asserting Up the wait before asserting on the metrics to 1 second as it appears that sometimes AppVeyor can be a bit slow. --- src/JustEat.StatsD.Tests/IntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JustEat.StatsD.Tests/IntegrationTests.cs b/src/JustEat.StatsD.Tests/IntegrationTests.cs index c2283518..84a7dcae 100644 --- a/src/JustEat.StatsD.Tests/IntegrationTests.cs +++ b/src/JustEat.StatsD.Tests/IntegrationTests.cs @@ -58,7 +58,7 @@ public static async Task Can_Send_Metrics_To_StatsD() publisher.Decrement(4, 1, "red", "green"); // 3 // Allow enough time for metrics to be registered - await Task.Delay(TimeSpan.FromSeconds(0.5)); + await Task.Delay(TimeSpan.FromSeconds(1.0)); // Assert var result = await SendCommandAsync("counters");