| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hedgehog.Extras.Test.TestWatchdog
Description
This module provides a test watchdog - an utility monitoring test cases and killing them if they don't
finish in time. Watchdog thread runs in the background, and after specified timeout, it throws
WatchdogException to the target thread. A user is able to kickWatchdog, which delays the killing and
poisonWatchdog which stops the watchdog.
To wrap a test case in a watchdog just use
runWithWatchdog watchdogConfig $ \watchdog -> do -- body of your test case
Synopsis
- runWithWatchdog_ :: (HasCallStack, MonadBaseControl IO m) => WatchdogConfig -> (HasCallStack => m a) -> m a
- runWithWatchdog :: (HasCallStack, MonadBaseControl IO m) => WatchdogConfig -> (HasCallStack => Watchdog -> m a) -> m a
- runWithDefaultWatchdog_ :: (HasCallStack, MonadBaseControl IO m) => (HasCallStack => m a) -> m a
- runWithDefaultWatchdog :: (HasCallStack, MonadBaseControl IO m) => (HasCallStack => Watchdog -> m a) -> m a
- kickWatchdog :: MonadIO m => Watchdog -> m ()
- poisonWatchdog :: MonadIO m => Watchdog -> m ()
- data Watchdog
- newtype WatchdogConfig = WatchdogConfig {}
- newtype WatchdogException = WatchdogException {}
- makeWatchdog :: MonadBase IO m => WatchdogConfig -> ThreadId -> m Watchdog
- runWatchdog :: (HasCallStack, MonadBase IO m) => Watchdog -> m ()
Wrap in watchdog
Arguments
| :: (HasCallStack, MonadBaseControl IO m) | |
| => WatchdogConfig | configuration |
| -> (HasCallStack => m a) | a test case to be wrapped in watchdog |
| -> m a |
Execute a test case with a watchdog.
Arguments
| :: (HasCallStack, MonadBaseControl IO m) | |
| => WatchdogConfig | configuration |
| -> (HasCallStack => Watchdog -> m a) | a test case to be wrapped in watchdog |
| -> m a |
Execute a test case with a watchdog.
runWithDefaultWatchdog_ Source #
Arguments
| :: (HasCallStack, MonadBaseControl IO m) | |
| => (HasCallStack => m a) | a test case to be wrapped in watchdog |
| -> m a |
Execute a test case with watchdog with default config.
runWithDefaultWatchdog Source #
Arguments
| :: (HasCallStack, MonadBaseControl IO m) | |
| => (HasCallStack => Watchdog -> m a) | a test case to be wrapped in watchdog |
| -> m a |
Execute a test case with watchdog with default config.
Watchdog control
kickWatchdog :: MonadIO m => Watchdog -> m () Source #
Enqueue a kick for the watchdog. It will extend the timeout by another one defined in the watchdog configuration.
poisonWatchdog :: MonadIO m => Watchdog -> m () Source #
Enqueue a poison pill for the watchdog. It will stop the watchdog after all timeouts.
Types
A watchdog instance. See the module header for more detailed description.
newtype WatchdogConfig Source #
Configuration for the watchdog.
Constructors
| WatchdogConfig | |
Fields
| |
newtype WatchdogException Source #
An exception thrown to the test case thread.
Constructors
| WatchdogException | |
Fields | |
Instances
| Exception WatchdogException Source # | |
Defined in Hedgehog.Extras.Test.TestWatchdog Methods toException :: WatchdogException -> SomeException # | |
| Show WatchdogException Source # | |
Defined in Hedgehog.Extras.Test.TestWatchdog Methods showsPrec :: Int -> WatchdogException -> ShowS # show :: WatchdogException -> String # showList :: [WatchdogException] -> ShowS # | |
Low level API
There is also a lower-level API available, giving the ability to provide target thread ID, which watchdog will try to kill.
Arguments
| :: MonadBase IO m | |
| => WatchdogConfig | |
| -> ThreadId | thread id which will get killed after all kicks expire |
| -> m Watchdog |
Create manually a new watchdog, providing the target thread ID. After all watchdog timeouts expire,
the target thread will get WatchdogException thrown to it asynchronously (using throwTo).
runWatchdog :: (HasCallStack, MonadBase IO m) => Watchdog -> m () Source #
Run watchdog in a loop in the current thread. Usually this function should be used with withAsync
to run it in the background.