Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix Network.Wai.Middleware.LoggingSpec on Windows #974

Merged
merged 2 commits into from
Nov 11, 2019
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
5 changes: 5 additions & 0 deletions lib/core/test/unit/Network/Wai/Middleware/LoggingSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -195,6 +197,7 @@ spec = describe "Logging Middleware"
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
Expand Down Expand Up @@ -267,6 +270,8 @@ postIlled ctx path body = do

expectLogs :: Context -> [(Severity, String)] -> IO ()
expectLogs ctx expectations = do
whenWindows $ threadDelay 1000000 -- let iohk-monitoring flush the logs

entries <- reverse <$> readTVarIO (logs ctx)

when (length entries /= length expectations) $
Expand Down
12 changes: 10 additions & 2 deletions lib/test-utils/src/Test/Utils/Windows.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

module Test.Utils.Windows
( skipOnWindows
, pendingOnWindows
, whenWindows
) where

import Prelude
Expand All @@ -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")