From 3cbe494cb7025445b4e294afd3bfbb990b337fa9 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 7 Nov 2019 15:36:39 +1000 Subject: [PATCH 1/2] tests: Fix Network.Wai.Middleware.LoggingSpec on Windows --- lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs b/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs index 3969456d72e..50e55c2e087 100644 --- a/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs +++ b/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs @@ -192,6 +192,7 @@ spec = describe "Logging Middleware" , replicate (n - i) (get ctx "/get") ] void $ mapConcurrently id reqs + threadDelay 1000000 -- let iohk-monitoring flush the logs entries <- readTVarIO (logs ctx) let index = Map.fromList $ catMaybes [ (loName l,) <$> captureTime l | l <- entries ] @@ -267,6 +268,8 @@ postIlled ctx path body = do expectLogs :: Context -> [(Severity, String)] -> IO () expectLogs ctx expectations = do + threadDelay 1000000 -- let iohk-monitoring flush the logs + entries <- reverse <$> readTVarIO (logs ctx) when (length entries /= length expectations) $ From 6b730206176874d28219f09aa80cf89874cbfc2f Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 11 Nov 2019 13:12:36 +1000 Subject: [PATCH 2/2] tests: Disable a failing LoggingSpec on Windows --- .../test/unit/Network/Wai/Middleware/LoggingSpec.hs | 6 ++++-- lib/test-utils/src/Test/Utils/Windows.hs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs b/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs index 50e55c2e087..01fe819065b 100644 --- a/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs +++ b/lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs @@ -97,6 +97,8 @@ import Test.QuickCheck ( Arbitrary (..), choose, property ) import Test.QuickCheck.Monadic ( monadicIO ) +import Test.Utils.Windows + ( pendingOnWindows, whenWindows ) import qualified Data.Aeson as Aeson import qualified Data.Map.Strict as Map @@ -192,10 +194,10 @@ spec = describe "Logging Middleware" , replicate (n - i) (get ctx "/get") ] void $ mapConcurrently id reqs - threadDelay 1000000 -- let iohk-monitoring flush the logs entries <- readTVarIO (logs ctx) let index = Map.fromList $ catMaybes [ (loName l,) <$> captureTime l | l <- entries ] + pendingOnWindows "Disabled on windows due to race with log flushing" Map.size (Map.filter (> (200*ms)) index) `shouldBe` 1 where setup :: IO Context @@ -268,7 +270,7 @@ postIlled ctx path body = do expectLogs :: Context -> [(Severity, String)] -> IO () expectLogs ctx expectations = do - threadDelay 1000000 -- let iohk-monitoring flush the logs + whenWindows $ threadDelay 1000000 -- let iohk-monitoring flush the logs entries <- reverse <$> readTVarIO (logs ctx) diff --git a/lib/test-utils/src/Test/Utils/Windows.hs b/lib/test-utils/src/Test/Utils/Windows.hs index bc5d85997dc..f3eaf8215ce 100644 --- a/lib/test-utils/src/Test/Utils/Windows.hs +++ b/lib/test-utils/src/Test/Utils/Windows.hs @@ -8,6 +8,8 @@ module Test.Utils.Windows ( skipOnWindows + , pendingOnWindows + , whenWindows ) where import Prelude @@ -19,9 +21,15 @@ import Control.Monad import System.Info ( os ) import Test.Hspec.Core.Spec - ( ResultStatus (..) ) + ( ResultStatus (..), pendingWith ) import Test.Hspec.Expectations ( Expectation, HasCallStack ) skipOnWindows :: HasCallStack => String -> Expectation -skipOnWindows _reason = when (os == "mingw32") $ throwIO Success +skipOnWindows _reason = whenWindows $ throwIO Success + +pendingOnWindows :: HasCallStack => String -> Expectation +pendingOnWindows reason = whenWindows $ pendingWith reason + +whenWindows :: IO () -> IO () +whenWindows = when (os == "mingw32")