From fd233bbbb8000dcdd5a3d831ae87dc1030bec59d Mon Sep 17 00:00:00 2001 From: Valentin Reis Date: Wed, 9 Jan 2019 09:52:28 -0600 Subject: [PATCH] Updating the tests to allow CSV logging (+ reformatting) --- argo/src/Argo/Args.hs | 4 +-- argo/src/Argo/Stack.hs | 2 -- argotk/argotk.hs | 71 ++++++++++++++++++++++++++++-------------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/argo/src/Argo/Args.hs b/argo/src/Argo/Args.hs index f820893..1559b97 100644 --- a/argo/src/Argo/Args.hs +++ b/argo/src/Argo/Args.hs @@ -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" diff --git a/argo/src/Argo/Stack.hs b/argo/src/Argo/Stack.hs index b144b6e..a579996 100644 --- a/argo/src/Argo/Stack.hs +++ b/argo/src/Argo/Stack.hs @@ -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 diff --git a/argotk/argotk.hs b/argotk/argotk.hs index 0c9ceb0..c966c53 100755 --- a/argotk/argotk.hs +++ b/argotk/argotk.hs @@ -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 -- 2.26.2