From 45f6edb07e642bce7a6829c523c984f754a44a1e Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:19:00 +0300 Subject: [PATCH 1/3] tests: detect and mark hung tests as failed --- tests/Test.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/Test.hs b/tests/Test.hs index cd2b0d8c3..cf2c36ddb 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -16,6 +16,7 @@ import CoreTests.RetryIntervalTests import CoreTests.TRcvQueuesTests import CoreTests.UtilTests import CoreTests.VersionRangeTests +import Data.Maybe (fromMaybe) import FileDescriptionTests (fileDescriptionTests) import GHC.IO.Exception (IOException (..)) import qualified GHC.IO.Exception as IOException @@ -27,7 +28,10 @@ import Simplex.Messaging.Transport (TLS, Transport (..)) import Simplex.Messaging.Transport.WebSockets (WS) import System.Directory (createDirectoryIfMissing, removeDirectoryRecursive) import System.Environment (setEnv) +import System.Timeout (timeout) import Test.Hspec +import Test.Hspec.Core.Spec +import Test.Hspec.Runner (configPrintSlowItems, defaultConfig, hspecWith) import XFTPAgent import XFTPCLI import XFTPServerTests (xftpServerTests) @@ -41,9 +45,10 @@ main = do withGlobalLogging logCfg $ do setEnv "APNS_KEY_ID" "H82WD9K9AQ" setEnv "APNS_KEY_FILE" "./tests/fixtures/AuthKey_H82WD9K9AQ.p8" - hspec + hspecWith defaultConfig {configPrintSlowItems = Just 10} . before_ (createDirectoryIfMissing False "tests/tmp") . after_ (eventuallyRemove "tests/tmp" 3) + . deadline (120 * 100000) $ do describe "Agent SQLite schema dump" schemaDumpTest describe "Core tests" $ do @@ -78,3 +83,11 @@ eventuallyRemove path retries = case retries of _ -> E.throwIO ioe where action = removeDirectoryRecursive path + +-- | Abort tests after a reasonable deadline. +deadline :: Int -> SpecWith b -> SpecWith b +deadline limit = mapSpecItem_ $ \item@Item {itemLocation, itemExample} -> + item + { itemExample = \params aw pc -> + fromMaybe (Result "timed out" . Failure itemLocation $ Reason "time limit") <$> timeout limit (itemExample params aw pc) + } From cdb3746ce7da0c5b4a94c16973822d911494d59d Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:00:19 +0300 Subject: [PATCH 2/3] fix deadline --- tests/Test.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Test.hs b/tests/Test.hs index cf2c36ddb..ffca6d21b 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -48,7 +48,7 @@ main = do hspecWith defaultConfig {configPrintSlowItems = Just 10} . before_ (createDirectoryIfMissing False "tests/tmp") . after_ (eventuallyRemove "tests/tmp" 3) - . deadline (120 * 100000) + . deadline (90 * 1000000) $ do describe "Agent SQLite schema dump" schemaDumpTest describe "Core tests" $ do From 12c801c7f292151bd04e8523e7e0434a24f08a14 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:13:45 +0300 Subject: [PATCH 3/3] increase deadline to 2m --- tests/Test.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Test.hs b/tests/Test.hs index ffca6d21b..38e658436 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -48,7 +48,7 @@ main = do hspecWith defaultConfig {configPrintSlowItems = Just 10} . before_ (createDirectoryIfMissing False "tests/tmp") . after_ (eventuallyRemove "tests/tmp" 3) - . deadline (90 * 1000000) + . deadline (120 * 1000000) $ do describe "Agent SQLite schema dump" schemaDumpTest describe "Core tests" $ do