From ed6d95dde5f12727cfa06b851c70b07cb415e9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 14 Sep 2025 21:02:50 +0200 Subject: Support zero timeout Changelog: Support zero as a timeout multiplyer --- src/Test.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Test.hs') diff --git a/src/Test.hs b/src/Test.hs index ce88052..18933b1 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -10,6 +10,7 @@ import Control.Concurrent.MVar import Control.Monad.Except import Control.Monad.Reader +import Data.Bifunctor import Data.Scientific import Data.Text (Text) import Data.Typeable @@ -67,15 +68,17 @@ instance ObjectType TestRun MultiplyTimeout where type ConstructorArgs MultiplyTimeout = Scientific createObject oid timeout - | timeout > 0 = do + | timeout >= 0 = do var <- asks (teTimeout . fst) - liftIO $ modifyMVar_ var $ return . (* timeout) + liftIO $ modifyMVar_ var $ return . + (if timeout == 0 then second (+ 1) else first (* timeout)) return $ Object oid $ MultiplyTimeout timeout | otherwise = do - outLine OutputError Nothing "timeout must be positive" + outLine OutputError Nothing "timeout must not be negative" throwError Failed destroyObject Object { objImpl = MultiplyTimeout timeout } = do var <- asks (teTimeout . fst) - liftIO $ modifyMVar_ var $ return . (/ timeout) + liftIO $ modifyMVar_ var $ return . + (if timeout == 0 then second (subtract 1) else first (/ timeout)) -- cgit v1.2.3