From 2d7c4a553e2a9005c6d3445f427cd1bd3e1bf75d Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Mon, 1 Aug 2022 15:41:11 +0200 Subject: [PATCH 1/5] Run RTS DDB test using Tasty --- compiler/test.hs | 32 +++++++++++++++++++ test/Makefile | 18 +---------- .../{test_db_app.act => rts/ddb_test_app.act} | 4 +-- test/test_db.py | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) rename test/{test_db_app.act => rts/ddb_test_app.act} (91%) diff --git a/compiler/test.hs b/compiler/test.hs index 726584980..2bc1983ff 100644 --- a/compiler/test.hs +++ b/compiler/test.hs @@ -51,6 +51,7 @@ main = do , regressionSegfaultTests , rtsAutoTests , rtsTests + , rtsDDBTests , stdlibAutoTests , stdlibTests ] @@ -140,6 +141,35 @@ rtsTests = (returnCode, cmdOut, cmdErr) <- runThing "--rts-wthreads" "../test/rts/argv7.act" assertEqual "RTS wthreads error retCode" (ExitFailure 1) returnCode assertEqual "RTS wthreads error cmdErr" "ERROR: --rts-wthreads requires an argument.\n" cmdErr + + ] + +rtsDDBTests = + testGroup "RTS DDB" + [ + testCase "DDB: db app test" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_app.act" + let cmd = "./test_db.py TestDbApps.test_app" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + assertEqual "DB client test success retCode" ExitSuccess returnCode + + , testCase "DDB: TCP server resume" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_server.act" + let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_server" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + assertEqual "DB client test success retCode" ExitSuccess returnCode + + , after AllFinish "TCP server resume" $ + testCase "DDB: TCP client resume" $ do + testBuild "" ExitSuccess False "../test/rts/ddb_test_server.act" + testBuild "" ExitSuccess False "../test/rts/ddb_test_client.act" + let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_client" + wd = "../test" + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + assertEqual "DB server test success retCode" ExitSuccess returnCode + ] stdlibTests = @@ -151,6 +181,8 @@ stdlibTests = ] + + -- Creates testgroup from .act files found in specified directory --createTests :: String -> String -> List -> TestTree createTests name dir allExpFail fails testFunc = do diff --git a/test/Makefile b/test/Makefile index 5199a2de3..39c834b9d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,30 +10,14 @@ test: ddb-tests: $(MAKE) $(DDB_TESTS) -DDB_TESTS=test_db_app test_db_app_no_quorum test_db_app_recovery test_db_app_resume_tcp_client test_db_app_resume_tcp_server +DDB_TESTS=test_db_app_no_quorum .PHONY: $(DDB_TESTS) -# Starts up a database cluster, checks membership is ok before proceeding to run -# a simple app. We do not really verify that the RTS uses the database - we -# assume it does and would fail catastrohpically if it encounters an error. -test_db_app: - $(ACTONC) --root main test_db_app.act - ./test_db.py TestDbApps.test_app - test_db_app_no_quorum: @echo "Skipping because this is essentially broken" #$(ACTONC) --root main test_db_app.act #./test_db.py TestDbAppsNoQuorum -test_db_app_resume_tcp_server: - $(ACTONC) --root main --dev rts/ddb_test_server.act - ./test_db.py TestDbApps.test_app_resume_tcp_server - -test_db_app_resume_tcp_client: - $(ACTONC) --root main --dev rts/ddb_test_server.act - $(ACTONC) --root main --dev rts/ddb_test_client.act - ./test_db.py TestDbApps.test_app_resume_tcp_client - # Expect 9 threads given 7 workers + main process + IO rts/wthreads1: diff --git a/test/test_db_app.act b/test/rts/ddb_test_app.act similarity index 91% rename from test/test_db_app.act rename to test/rts/ddb_test_app.act index 697963d9e..806101184 100644 --- a/test/test_db_app.act +++ b/test/rts/ddb_test_app.act @@ -1,7 +1,7 @@ # Basic test case of the Acton RTS together with the database backend. We want # to focus on things that lead to database interaction, so in essence calling -# actor methods / sending methods and execution of continuations. We also want -# to test the timer queue. +# actor methods / sending methods and execution of continuations, including +# using an "after" statement to test the timer queue. # # main -> Foo."init" -> timerQ after 0 -> Foo.callback() -> main.final() -> exit diff --git a/test/test_db.py b/test/test_db.py index 38c8d75df..fa3bfa9d4 100755 --- a/test/test_db.py +++ b/test/test_db.py @@ -379,7 +379,7 @@ def tearDown(self): def test_app(self): - cmd = ["./test_db_app", "--rts-verbose", + cmd = ["./rts/ddb_test_app", "--rts-verbose", "--rts-ddb-replication", str(self.replication_factor) ] + get_db_args(self.dbc.port_chunk, self.replication_factor) self.p = subprocess.run(cmd, capture_output=True, timeout=3) From 87619af22e1a22294ae990cca8d0fc523dfd5e6a Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Mon, 1 Aug 2022 15:46:41 +0200 Subject: [PATCH 2/5] Fix worker threads test --- test/Makefile | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test/Makefile b/test/Makefile index 39c834b9d..d583bbbfd 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,17 +1,10 @@ MK_PATH:=$(shell dirname $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) ACTONC=$(MK_PATH)/dist/bin/actonc --cpedantic -DDB_SERVER=../dist/bin/actondb -TESTS= \ - $(DDB_TESTS) +TESTS=test_db_app_no_quorum rts/wthreads1 test: $(MAKE) $(TESTS) - -ddb-tests: - $(MAKE) $(DDB_TESTS) - -DDB_TESTS=test_db_app_no_quorum -.PHONY: $(DDB_TESTS) +.PHONY: $(TESTS) test_db_app_no_quorum: @echo "Skipping because this is essentially broken" @@ -19,7 +12,7 @@ test_db_app_no_quorum: #./test_db.py TestDbAppsNoQuorum -# Expect 9 threads given 7 workers + main process + IO +# Expect 10 threads given 7 workers + main process + IO + new IO rts/wthreads1: - $(ACTONC) --root main $@.act - ./$@ --rts-wthreads 7 & PID=$$! && ps -o thcount $${PID} | tail -n1 | awk '{ print $$1 }' | grep "^9$$" + $(ACTONC) $@.act + ./$@ --rts-wthreads 7 & PID=$$! && ps -o thcount $${PID} | tail -n1 | awk '{ print $$1 }' | grep "^10$$" From 7395beaf002cf078b478744be107deb7af4ed9dc Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Mon, 1 Aug 2022 16:23:16 +0200 Subject: [PATCH 3/5] Use Tasty for RTS thread count test This removes test/Makefile since all tests have been moved to be run by Tasty! Yay! The thread count is a pretty good example for how the shell is pretty useful for this kind of tests. DSLs aren't that bad after all... --- Makefile | 1 - compiler/test.hs | 22 +++++++++++++++++++++- test/Makefile | 18 ------------------ 3 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 test/Makefile diff --git a/Makefile b/Makefile index 057ae558a..271101756 100644 --- a/Makefile +++ b/Makefile @@ -349,7 +349,6 @@ rts: $(ARCHIVES) test: cd compiler && stack test $(MAKE) -C backend test - $(MAKE) -C test test-builtins: cd compiler && stack test --ta '-p "Builtins"' diff --git a/compiler/test.hs b/compiler/test.hs index 2bc1983ff..16a1b3d8f 100644 --- a/compiler/test.hs +++ b/compiler/test.hs @@ -4,7 +4,6 @@ import Data.List.Split import Data.Maybe import Data.Ord import Data.Time.Clock.POSIX - import System.Directory import System.Directory.Recursive import System.Exit @@ -142,6 +141,27 @@ rtsTests = assertEqual "RTS wthreads error retCode" (ExitFailure 1) returnCode assertEqual "RTS wthreads error cmdErr" "ERROR: --rts-wthreads requires an argument.\n" cmdErr + , testCase "thread count" $ do + -- check the number of threads, which should be 10, consisting of 7 + -- worker threads (as specified on command line), IO+new IO & main + testBuild "" ExitSuccess False "../test/rts/wthreads1.act" + (pin, pout, perr, ph) <- runInteractiveProcess "../test/rts/wthreads1" ["--rts-wthreads=7"] Nothing Nothing + mpid <- getPid ph + case mpid of + Just pid -> do +#if defined(darwin_HOST_OS) + let cmd = "ps -M " ++ show pid ++ " | tail -n +2 | wc -l" +#else + let cmd = "ps -o thcount " ++ show pid +#endif + (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd) "" + let tCount = read (last $ lines cmdOut)::Int + assertEqual "RTS thread count" 10 tCount + Nothing -> do + assertFailure "whtreads1 program should be running" + terminateProcess ph + waitForProcess ph + return () ] rtsDDBTests = diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index d583bbbfd..000000000 --- a/test/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -MK_PATH:=$(shell dirname $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) -ACTONC=$(MK_PATH)/dist/bin/actonc --cpedantic -TESTS=test_db_app_no_quorum rts/wthreads1 -test: - $(MAKE) $(TESTS) - -.PHONY: $(TESTS) - -test_db_app_no_quorum: - @echo "Skipping because this is essentially broken" - #$(ACTONC) --root main test_db_app.act - #./test_db.py TestDbAppsNoQuorum - - -# Expect 10 threads given 7 workers + main process + IO + new IO -rts/wthreads1: - $(ACTONC) $@.act - ./$@ --rts-wthreads 7 & PID=$$! && ps -o thcount $${PID} | tail -n1 | awk '{ print $$1 }' | grep "^10$$" From fbe3b66092f0290a222bc565bc1ac0c02ebda0dc Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Tue, 2 Aug 2022 13:40:20 +0200 Subject: [PATCH 4/5] Slight delay --- compiler/test.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/test.hs b/compiler/test.hs index 16a1b3d8f..3e2968260 100644 --- a/compiler/test.hs +++ b/compiler/test.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +import Control.Concurrent import Data.List import Data.List.Split import Data.Maybe @@ -146,6 +147,7 @@ rtsTests = -- worker threads (as specified on command line), IO+new IO & main testBuild "" ExitSuccess False "../test/rts/wthreads1.act" (pin, pout, perr, ph) <- runInteractiveProcess "../test/rts/wthreads1" ["--rts-wthreads=7"] Nothing Nothing + threadDelay 100000 mpid <- getPid ph case mpid of Just pid -> do From d6e16dcdab8172e7d54aca04fd2faf0177f3419d Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Tue, 2 Aug 2022 15:55:05 +0200 Subject: [PATCH 5/5] Add debug output --- compiler/test.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/test.hs b/compiler/test.hs index 3e2968260..c4bdc6845 100644 --- a/compiler/test.hs +++ b/compiler/test.hs @@ -174,6 +174,9 @@ rtsDDBTests = let cmd = "./test_db.py TestDbApps.test_app" wd = "../test" (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) assertEqual "DB client test success retCode" ExitSuccess returnCode , testCase "DDB: TCP server resume" $ do @@ -181,6 +184,9 @@ rtsDDBTests = let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_server" wd = "../test" (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) assertEqual "DB client test success retCode" ExitSuccess returnCode , after AllFinish "TCP server resume" $ @@ -190,6 +196,9 @@ rtsDDBTests = let cmd = "./test_db.py TestDbApps.test_app_resume_tcp_client" wd = "../test" (returnCode, cmdOut, cmdErr) <- readCreateProcessWithExitCode (shell $ cmd){ cwd = Just wd } "" + iff (returnCode /= ExitSuccess) ( + putStrLn("\nERROR: when running test application\nSTDOUT: " ++ cmdOut ++ "\nSTDERR: " ++ cmdErr) + ) assertEqual "DB server test success retCode" ExitSuccess returnCode ]