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