Skip to content

Commit

Permalink
LauncherSpec: No need for external scripts
Browse files Browse the repository at this point in the history
Changed this for the nix build. Alternatively, we could have provided
coreutils and bash so that the scripts can run. But I think it's
neater without external shell scripts.
  • Loading branch information
rvl committed Oct 22, 2019
1 parent b87ad16 commit b346c52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 0 additions & 4 deletions lib/launcher/test/data/forever.sh

This file was deleted.

3 changes: 0 additions & 3 deletions lib/launcher/test/data/once.sh

This file was deleted.

27 changes: 18 additions & 9 deletions lib/launcher/test/unit/Cardano/LauncherSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ spec = do

it "1st process exits with 0, others are cancelled" $ do
let commands =
[ Command "./test/data/once.sh" ["0"] (pure ()) Inherit
, Command "./test/data/forever.sh" [] (pure ()) Inherit
[ mockCommand 0 (pure ())
, foreverCommand
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 0)
code `shouldBe` ExitSuccess

it "2nd process exits with 0, others are cancelled" $ do
let commands =
[ Command "./test/data/forever.sh" [] (pure ()) Inherit
, Command "./test/data/once.sh" ["0"] (pure ()) Inherit
[ foreverCommand
, mockCommand 0 (pure ())
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 1)
code `shouldBe` ExitSuccess

it "1st process exits with 14, others are cancelled" $ do
let commands =
[ Command "./test/data/once.sh" ["14"] (pure ()) Inherit
, Command "./test/data/forever.sh" [] (pure ()) Inherit
[ mockCommand 14 (pure ())
, foreverCommand
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 0)
code `shouldBe` (ExitFailure 14)

it "2nd process exits with 14, others are cancelled" $ do
let commands =
[ Command "./test/data/forever.sh" [] (pure ()) Inherit
, Command "./test/data/once.sh" ["14"] (pure ()) Inherit
[ foreverCommand
, mockCommand 14 (pure ())
]
(ProcessHasExited name code) <- launch nullTracer commands
name `shouldBe` cmdName (commands !! 1)
Expand All @@ -78,7 +78,7 @@ spec = do
mvar <- newEmptyMVar
let before = putMVar mvar "executed"
let commands =
[ Command "./test/data/once.sh" ["0"] before Inherit
[ mockCommand 0 before
]
(ProcessHasExited _ code) <- launch nullTracer commands
code `shouldBe` ExitSuccess
Expand All @@ -90,3 +90,12 @@ spec = do
]
ProcessDidNotStart name _exc <- launch nullTracer commands
name `shouldBe` "foobar"

-- | A command that will run for a short time then exit with the given status.
mockCommand :: Int -> IO () -> Command
mockCommand exitStatus before =
Command "sh" ["-c", "sleep 1; exit " ++ show exitStatus] before Inherit

-- | A command that will run for longer than the other commands.
foreverCommand :: Command
foreverCommand = Command "sleep" ["30"] (pure ()) Inherit

0 comments on commit b346c52

Please sign in to comment.