Skip to content

Commit

Permalink
Try using custom repeatedHspec helper
Browse files Browse the repository at this point in the history
It looked like `hspec $ replicateM` didn't finish the /whole/ first test
run before starting the second, which would be bad.
  • Loading branch information
Anviking committed Nov 24, 2020
1 parent 1ad10c4 commit e5567f3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/shelley/test/integration/Main.hs
Expand Up @@ -77,7 +77,7 @@ import Control.Concurrent.MVar
import Control.Exception
( throwIO )
import Control.Monad
( replicateM_ )
( replicateM )
import Control.Monad.IO.Class
( liftIO )
import Control.Tracer
Expand All @@ -97,7 +97,7 @@ import Network.HTTP.Client
, responseTimeoutMicro
)
import System.Environment
( lookupEnv )
( getArgs, lookupEnv, withArgs )
import System.FilePath
( (</>) )
import System.IO
Expand All @@ -107,7 +107,7 @@ import Test.Hspec
import Test.Hspec.Extra
( aroundAll )
import Test.Hspec.Runner
( hspec )
( defaultConfig, evaluateSummary, readConfig, runSpec )
import Test.Integration.Faucet
( genRewardAccounts, mirMnemonics, shelleyIntegrationTestFunds )
import Test.Integration.Framework.Context
Expand Down Expand Up @@ -159,7 +159,7 @@ main = withUtf8Encoding $ withTracers $ \tracers -> do
-- rebuild.hs script set it.
repetitions <- maybe 1 (const 10) <$> lookupEnv "NIGHTLY_BUILD"

hspec $ replicateM_ repetitions $ do
repeatedHspec repetitions $ do
describe "No backend required" $
parallelIf (not nix) $ describe "Miscellaneous CLI tests" $
MiscellaneousCLI.spec @t
Expand Down Expand Up @@ -201,6 +201,14 @@ main = withUtf8Encoding $ withTracers $ \tracers -> do
parallelIf :: forall a. Bool -> SpecWith a -> SpecWith a
parallelIf flag = if flag then parallel else id

-- Runs a @Spec@ in /sequence/ n times, and at the end, concatenates the
-- results.
repeatedHspec n spec =
getArgs
>>= readConfig defaultConfig
>>= withArgs [] . fmap mconcat . replicateM n . runSpec spec
>>= evaluateSummary

specWithServer
:: (Tracer IO TestsLog, Tracers IO)
-> SpecWith (Context Shelley)
Expand Down

0 comments on commit e5567f3

Please sign in to comment.