diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-21 13:58:46 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-06-21 15:59:51 +0200 |
commit | 06df252ce401f7701f1d830d1867fedda1b36d05 (patch) | |
tree | 5e5a044a71a6fa8f151ce581afa1aae34cbaf4e9 /src/Test.hs | |
parent | b7eb345a88df9ee87080fe776722f12e911b773f (diff) |
Multiply-timeout command
Changelog: Added `multiply_timeout` command
Diffstat (limited to 'src/Test.hs')
-rw-r--r-- | src/Test.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Test.hs b/src/Test.hs index 6c44e94..3e98efa 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -2,13 +2,20 @@ module Test ( Test(..), TestStep(..), TestBlock(..), + + MultiplyTimeout(..), ) where +import Control.Concurrent.MVar +import Control.Monad.Except +import Control.Monad.Reader + import Data.Scientific import Data.Text (Text) import Data.Typeable import Network +import Output import Process import Run.Monad import Script.Expr @@ -52,3 +59,23 @@ data TestStep a where instance Typeable a => ExprType (TestBlock a) where textExprType _ = "test block" textExprValue _ = "<test block>" + + +data MultiplyTimeout = MultiplyTimeout Scientific + +instance ObjectType TestRun MultiplyTimeout where + type ConstructorArgs MultiplyTimeout = Scientific + + createObject oid timeout + | timeout > 0 = do + var <- asks (teTimeout . fst) + liftIO $ modifyMVar_ var $ return . (* timeout) + return $ Object oid $ MultiplyTimeout timeout + + | otherwise = do + outLine OutputError Nothing "timeout must be positive" + throwError Failed + + destroyObject Object { objImpl = MultiplyTimeout timeout } = do + var <- asks (teTimeout . fst) + liftIO $ modifyMVar_ var $ return . (/ timeout) |