Commit fd233bbb authored by Valentin Reis's avatar Valentin Reis

Updating the tests to allow CSV logging (+ reformatting)

parent 50ffa445
...@@ -52,8 +52,8 @@ behaviorOption = option behavior ...@@ -52,8 +52,8 @@ behaviorOption = option behavior
instance Default StackArgs where instance Default StackArgs where
def = StackArgs def = StackArgs
{ app = AppName "echo" { app = AppName "ls"
, args = AppArgs ["foobar"] , args = AppArgs []
, containerName = ContainerName "testContainer" , containerName = ContainerName "testContainer"
, workingDirectory = WorkingDirectory "_output" , workingDirectory = WorkingDirectory "_output"
, manifestDir = ManifestDir "manifests" , manifestDir = ManifestDir "manifests"
......
...@@ -176,7 +176,6 @@ cmdListenPowerI (ContainerName cn) pb = ...@@ -176,7 +176,6 @@ cmdListenPowerI (ContainerName cn) pb =
data StackOutput = data StackOutput =
FoundMessage FoundMessage
| MessageNotFound
| Died StackI ExitCode | Died StackI ExitCode
data StackI = Daemon | Run | Listen | Progress | Power deriving (Show) data StackI = Daemon | Run | Listen | Progress | Power deriving (Show)
...@@ -211,7 +210,6 @@ runStack a@StackArgs {..} = do ...@@ -211,7 +210,6 @@ runStack a@StackArgs {..} = do
out <- liftIO $ waitAnyCancel asyncs out <- liftIO $ waitAnyCancel asyncs
return $ case snd out of return $ case snd out of
(_ , Left PatternMatched ) -> FoundMessage (_ , Left PatternMatched ) -> FoundMessage
(Run , Right (ExitSuccess, _, _)) -> MessageNotFound
(stacki, Right (e, _, _) ) -> Died stacki e (stacki, Right (e, _, _) ) -> Died stacki e
where where
tupleToAsync tupleToAsync
......
...@@ -17,15 +17,10 @@ opts :: StackArgs -> Parser (Shell ()) ...@@ -17,15 +17,10 @@ opts :: StackArgs -> Parser (Shell ())
opts sa = hsubparser opts sa = hsubparser
( command "clean" ( command "clean"
(info (pure $ clean sa) (progDesc "Clean sockets, logfiles.")) (info (pure $ clean sa) (progDesc "Clean sockets, logfiles."))
<> commandTest DaemonOnly <> (mconcat $ fmap commandTest [(minBound :: TestType) ..])
<> commandTest DaemonAndApp
<> commandTest TestHello
<> commandTest TestListen
<> commandTest TestPerfwrapper
<> commandTest TestPower
<> commandTests [TestHello, TestListen, TestPerfwrapper] <> commandTests [TestHello, TestListen, TestPerfwrapper]
"tests" "tests"
"Run all tests" "Run hardware-independent CI tests"
<> help <> help
"Type of test to run. There are extensive options under each action,\ "Type of test to run. There are extensive options under each action,\
\ but be careful, these do not all have the same defaults. The default\ \ but be careful, these do not all have the same defaults. The default\
...@@ -40,10 +35,18 @@ opts sa = hsubparser ...@@ -40,10 +35,18 @@ opts sa = hsubparser
commandTests ttypes cmdStr descStr = commandTests ttypes cmdStr descStr =
command cmdStr $ info (pure $ mapM_ (doTest sa) ttypes) (progDesc descStr) command cmdStr $ info (pure $ mapM_ (doTest sa) ttypes) (progDesc descStr)
data TestType = DaemonOnly | DaemonAndApp | TestHello | TestListen | TestPerfwrapper | TestPower deriving Show data TestType =
DaemonOnly
| DaemonAndApp
| CsvLogs
| TestHello
| TestListen
| TestPerfwrapper
| TestPower deriving (Enum,Bounded,Show)
data TestSpec = TestSpec data TestSpec = TestSpec
{ stackArgsUpdate :: StackArgs -> StackArgs { stackArgsUpdate :: StackArgs -> StackArgs
, isTest :: IsTest
, description :: String } , description :: String }
doTest :: StackArgs -> TestType -> Shell () doTest :: StackArgs -> TestType -> Shell ()
...@@ -57,7 +60,7 @@ doOverridenTest ttype = doSpec spec where spec = configureTest ttype ...@@ -57,7 +60,7 @@ doOverridenTest ttype = doSpec spec where spec = configureTest ttype
doSpec :: TestSpec -> StackArgs -> Shell () doSpec :: TestSpec -> StackArgs -> Shell ()
doSpec spec stackArgs = do doSpec spec stackArgs = do
printTest $ T.pack $ description spec printTest $ T.pack $ description spec
fullStack stackArgs fullStack (isTest spec) stackArgs
printSuccess "Test Successful." printSuccess "Test Successful."
configureTest :: TestType -> TestSpec configureTest :: TestType -> TestSpec
...@@ -65,11 +68,24 @@ configureTest = \case ...@@ -65,11 +68,24 @@ configureTest = \case
DaemonOnly -> TestSpec DaemonOnly -> TestSpec
{ stackArgsUpdate = \sa -> sa { daemon = daemonBehavior } { stackArgsUpdate = \sa -> sa { daemon = daemonBehavior }
, description = "Set up and launch the daemon in synchronous mode." , description = "Set up and launch the daemon in synchronous mode."
, isTest = IsTest False
} }
DaemonAndApp -> TestSpec DaemonAndApp -> TestSpec
{ stackArgsUpdate = \sa -> sa
{ daemon = daemonBehavior
, cmdrun = runBehavior
, cmdlistenprogress = JustRun (StdOutLog "progress.csv")
(StdErrLog "progress.log")
, cmdlistenpower = JustRun (StdOutLog "power.csv") (StdErrLog "power.log")
}
, description = "Set up and start daemon, run a command in a container."
, isTest = IsTest False
}
CsvLogs -> TestSpec
{ stackArgsUpdate = \sa -> { stackArgsUpdate = \sa ->
sa { daemon = daemonBehavior, cmdrun = runBehavior } sa { daemon = daemonBehavior, cmdrun = runBehavior }
, description = "Set up and start daemon, run a command in a container." , description = "Set up and start daemon, run a command in a container."
, isTest = IsTest False
} }
TestHello -> TestSpec TestHello -> TestSpec
{ stackArgsUpdate = \sa -> sa { stackArgsUpdate = \sa -> sa
...@@ -82,6 +98,7 @@ configureTest = \case ...@@ -82,6 +98,7 @@ configureTest = \case
} }
, description = "1: Setup stack and check that a hello world app sends \ , description = "1: Setup stack and check that a hello world app sends \
\message back to cmd." \message back to cmd."
, isTest = IsTest True
} }
TestListen -> TestSpec TestListen -> TestSpec
{ stackArgsUpdate = \sa -> sa { stackArgsUpdate = \sa -> sa
...@@ -93,6 +110,7 @@ configureTest = \case ...@@ -93,6 +110,7 @@ configureTest = \case
} }
, description = "2: Setup stack and check that argo-perf-wrapper sends\ , description = "2: Setup stack and check that argo-perf-wrapper sends\
\ at least one message to the daemon." \ at least one message to the daemon."
, isTest = IsTest True
} }
TestPerfwrapper -> TestSpec TestPerfwrapper -> TestSpec
{ stackArgsUpdate = \sa -> sa { stackArgsUpdate = \sa -> sa
...@@ -106,6 +124,7 @@ configureTest = \case ...@@ -106,6 +124,7 @@ configureTest = \case
, description = "3: Setup stack and check that argo-perf-wrapper sends\ , description = "3: Setup stack and check that argo-perf-wrapper sends\
\ at least one *performance* message to cmd listen through the\ \ at least one *performance* message to cmd listen through the\
\ daemon." \ daemon."
, isTest = IsTest True
} }
TestPower -> TestSpec TestPower -> TestSpec
{ stackArgsUpdate = \sa -> sa { stackArgsUpdate = \sa -> sa
...@@ -118,28 +137,34 @@ configureTest = \case ...@@ -118,28 +137,34 @@ configureTest = \case
, description = "4: Setup stack and check that argo-perf-wrapper sends\ , description = "4: Setup stack and check that argo-perf-wrapper sends\
\ at least one *power* message to cmd listen through the\ \ at least one *power* message to cmd listen through the\
\ daemon." \ daemon."
, isTest = IsTest True
} }
where where
msg = "someComplicatedMessage" msg = "someComplicatedMessage"
daemonBehavior = JustRun (StdOutLog "daemon_out.log") (StdErrLog "daemon_err.log") daemonBehavior =
runBehavior = JustRun (StdOutLog "cmd_run_out.log") (StdErrLog "cmd_run_err.log") JustRun (StdOutLog "daemon_out.log") (StdErrLog "daemon_err.log")
runBehavior =
JustRun (StdOutLog "cmd_run_out.log") (StdErrLog "cmd_run_err.log")
listentestBehavior t = SucceedTestOnMessage listentestBehavior t = SucceedTestOnMessage
t t
(StdOutLog "cmd_listen_out.log") (StdOutLog "cmd_listen_out.log")
(StdErrLog "cmd_listen_err.log") (StdErrLog "cmd_listen_err.log")
fullStack :: StackArgs -> Shell () newtype IsTest = IsTest Bool
fullStack a@StackArgs {..} = runStack a >>= \case
FoundMessage -> printSuccess "Found message!\n" fullStack :: IsTest -> StackArgs -> Shell ()
MessageNotFound -> printError "Message not found.\n" >> exit (ExitFailure 1) fullStack (IsTest b) a@StackArgs {..} = runStack a >>= \case
Died stacki ExitSuccess -> FoundMessage -> printSuccess "Found message!\n"
printError (repr stacki <> " died before a message could be found.\n") Died stacki errorcode -> if b
>> exit (ExitFailure 1) then
Died stacki (ExitFailure errcode) -> printError printError
( repr stacki ( repr stacki
<> "`daemon` died unexpectedly with error code.\n" <> " died before a message could be found:"
<> repr errcode <> repr errorcode
) <> "\n"
)
>> exit (ExitFailure 1)
else exit (ExitSuccess)
clean :: StackArgs -> Shell () clean :: StackArgs -> Shell ()
clean StackArgs {..} = cleanLeftovers workingDirectory clean StackArgs {..} = cleanLeftovers workingDirectory
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment