From 289d3cc65045037a5d9777857b247a7755fe47e6 Mon Sep 17 00:00:00 2001 From: Maor Rosenfeld Date: Thu, 23 Feb 2017 09:03:17 +0200 Subject: [PATCH] Get rid of Thread.Sleep everywhere and see if Travis can handle it --- src/IntegrationTests/Log4net/Log4netPerfTests.cs | 1 - src/IntegrationTests/Log4net/Log4netSanityTests.cs | 2 +- src/IntegrationTests/NLog/NLogPerfTests.cs | 2 -- src/IntegrationTests/NLog/NLogSanityTests.cs | 1 - .../Shipper/ShipperThreadHandlingTests.cs | 2 +- src/UnitTests/Log4net/LogzioAppenderTests.cs | 10 +--------- src/UnitTests/Shipping/ShipperTests.cs | 2 +- 7 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/IntegrationTests/Log4net/Log4netPerfTests.cs b/src/IntegrationTests/Log4net/Log4netPerfTests.cs index b918121..f097587 100644 --- a/src/IntegrationTests/Log4net/Log4netPerfTests.cs +++ b/src/IntegrationTests/Log4net/Log4netPerfTests.cs @@ -50,7 +50,6 @@ public void MeasurePerfForLog4net() Console.WriteLine("Total time: " + stopwatch.Elapsed); stopwatch.Elapsed.Should().BeLessOrEqualTo(TimeSpan.FromMilliseconds(100)); - Thread.Sleep(logsAmount); //Make sure the logs are added to the queue before we flush everything new Bootstraper().Resolve().WaitForSendLogsTask(); logzioAppender.Close(); diff --git a/src/IntegrationTests/Log4net/Log4netSanityTests.cs b/src/IntegrationTests/Log4net/Log4netSanityTests.cs index 7e233cc..d4534d5 100644 --- a/src/IntegrationTests/Log4net/Log4netSanityTests.cs +++ b/src/IntegrationTests/Log4net/Log4netSanityTests.cs @@ -41,7 +41,7 @@ public void Sanity() var logger = LogManager.GetLogger(typeof (Log4netSanityTests)); logger.Info("Just a random log line"); - Thread.Sleep(200); + new Bootstraper().Resolve().WaitForSendLogsTask(); logzioAppender.Close(); LogManager.Shutdown(); diff --git a/src/IntegrationTests/NLog/NLogPerfTests.cs b/src/IntegrationTests/NLog/NLogPerfTests.cs index 90f52d3..35ff140 100644 --- a/src/IntegrationTests/NLog/NLogPerfTests.cs +++ b/src/IntegrationTests/NLog/NLogPerfTests.cs @@ -59,8 +59,6 @@ public void Perf() stopwatch.Elapsed.Should().BeLessOrEqualTo(TimeSpan.FromMilliseconds(100)); - Thread.Sleep(logsAmount * 2); //Make sure the logs are added to the queue before we flush everything - new Bootstraper().Resolve().WaitForSendLogsTask(); LogManager.Shutdown(); diff --git a/src/IntegrationTests/NLog/NLogSanityTests.cs b/src/IntegrationTests/NLog/NLogSanityTests.cs index e562db1..b8c33b9 100644 --- a/src/IntegrationTests/NLog/NLogSanityTests.cs +++ b/src/IntegrationTests/NLog/NLogSanityTests.cs @@ -46,7 +46,6 @@ public void Sanity() var logger = LogManager.GetCurrentClassLogger(); logger.Info("Hello"); - Thread.Sleep(100); new Bootstraper().Resolve().WaitForSendLogsTask(); LogManager.Shutdown(); diff --git a/src/IntegrationTests/Shipper/ShipperThreadHandlingTests.cs b/src/IntegrationTests/Shipper/ShipperThreadHandlingTests.cs index e3d1cf8..9cf6550 100644 --- a/src/IntegrationTests/Shipper/ShipperThreadHandlingTests.cs +++ b/src/IntegrationTests/Shipper/ShipperThreadHandlingTests.cs @@ -43,7 +43,7 @@ public void Ship_SendLogsInDelay_CreatesNewThreadCorrectly() _shipper.Ship(GetLogging(), options); _shipper.Flush(options); - Thread.Sleep(TimeSpan.FromSeconds(2)); + _shipper.Ship(GetLogging(), options); _shipper.Flush(options); diff --git a/src/UnitTests/Log4net/LogzioAppenderTests.cs b/src/UnitTests/Log4net/LogzioAppenderTests.cs index fc3dd5d..0daab99 100644 --- a/src/UnitTests/Log4net/LogzioAppenderTests.cs +++ b/src/UnitTests/Log4net/LogzioAppenderTests.cs @@ -1,5 +1,4 @@ -using System.Threading; -using log4net.Core; +using log4net.Core; using Logzio.DotNet.Core.InternalLogger; using Logzio.DotNet.Core.Shipping; using Logzio.DotNet.Log4net; @@ -26,7 +25,6 @@ public void Append_Appending_CallsShipperWithCorrectValues() { _target.DoAppend(GetLoggingEventWithSomeData()); _target.Close(); - SleepJustABit(); _shipper.Received().Ship(Arg.Is(x => (string) x.LogData["domain"] == "Such domain"), Arg.Any()); } @@ -37,7 +35,6 @@ public void Append_AppendingWithCustomFields_CallsShipperWithCorrectValues() _target.AddCustomField(new LogzioAppenderCustomField { Key = "DatKey", Value = "DatVal"}); _target.DoAppend(GetLoggingEventWithSomeData()); _target.Close(); - SleepJustABit(); _shipper.Received().Ship(Arg.Is(x => (string) x.LogData["DatKey"] == "DatVal"), Arg.Any()); } @@ -50,10 +47,5 @@ private LoggingEvent GetLoggingEventWithSomeData() Message = "That's a message alright" }); } - - private void SleepJustABit() - { - Thread.Sleep(50); - } } } \ No newline at end of file diff --git a/src/UnitTests/Shipping/ShipperTests.cs b/src/UnitTests/Shipping/ShipperTests.cs index efcd7e4..f42429d 100644 --- a/src/UnitTests/Shipping/ShipperTests.cs +++ b/src/UnitTests/Shipping/ShipperTests.cs @@ -85,7 +85,7 @@ public void Ship_BufferTimeoutReached_LogWasSent() _bulkSender.DidNotReceiveWithAnyArgs().Send(Arg.Any>(), Arg.Any()); - Thread.Sleep(TimeSpan.FromMilliseconds(30)); + Thread.Sleep(TimeSpan.FromMilliseconds(30)); //wait for the actual timeout _bulkSender.Received().Send(Arg.Is>(x => x.Count == 2), Arg.Any()); }