Skip to content
Permalink
Browse files

Revert "tests: Exponentially back off waiting"

This reverts commit cb94323.

The more aggressive (read shorter) initial timeouts could lead to more
failing tests. This is partially because after we've implemented the new
UI methods, we never investigated that the views now share more common
widgets. Widget labels show up in more different views. This leads to
more failures in combination with the aggressive timeouts, because the
assertions still find the same strings in the old views as well as in
the new views.

Therefore, tweaking more with the timeouts will make the tests more
brittle.
  • Loading branch information
romanofski committed Dec 14, 2018
1 parent 8afd454 commit 8d5b6e8d40299cea21483ff384034c36d78b2a8d
Showing with 11 additions and 15 deletions.
  1. +11 −15 test/TestUserAcceptance.hs
@@ -764,7 +764,7 @@ sendKeys :: String -> Condition -> ReaderT Env IO String
sendKeys keys expect = do
sessionName <- getSessionName
liftIO $ callProcess "tmux" $ communicateSessionArgs sessionName keys False
waitForCondition expect defaultCountdown initialBackoffMicroseconds
waitForCondition expect defaultCountdown

sendLiteralKeys :: String -> ReaderT Env IO String
sendLiteralKeys keys = do
@@ -783,8 +783,8 @@ getSessionName = view (envSessionName . ask)
getTestMaildir :: (Monad m) => ReaderT Env m FilePath
getTestMaildir = view (envMaildir . ask)

initialBackoffMicroseconds :: Int
initialBackoffMicroseconds = 20 * 10 ^ (3 :: Int)
holdOffTime :: Int
holdOffTime = 10 ^ (6 :: Int)

-- | convenience function to print captured output to STDERR
debugOutput :: String -> IO ()
@@ -793,15 +793,11 @@ debugOutput out = do
when (isJust d) $ hPutStr stderr ("\n\n" <> out)

-- | wait for the application to render a new interface which we determine with
-- a given condition. We wait a short duration and increase the wait time
-- exponentially until the count down reaches 0. We fail if until then the
-- condition is not met.
waitForCondition ::
Condition
-> Int -- ^ count down value
-> Int -- ^ milliseconds to back off
-> ReaderT Env IO String
waitForCondition cond n backOff = do
-- a given condition. We check up to @n@ times, waiting a short duration
-- between each check, and failing if the tries exhaust with the condition
-- not met.
waitForCondition :: Condition -> Int -> ReaderT Env IO String
waitForCondition cond n = do
out <- capture >>= checkPane
liftIO $ assertBool
( "Wait time exceeded. Condition not met: '" <> show cond
@@ -814,8 +810,8 @@ waitForCondition cond n backOff = do
| checkCondition cond out = pure out
| n <= 0 = pure out
| otherwise = do
liftIO $ threadDelay backOff
waitForCondition cond (n - 1) (backOff * 4)
liftIO $ threadDelay holdOffTime
waitForCondition cond (n - 1)

checkCondition :: Condition -> String -> Bool
checkCondition (Literal s) = (s `isInfixOf`)
@@ -825,7 +821,7 @@ checkCondition (Regex re) = (=~ re)
-- literal string.
--
waitForString :: String -> Int -> ReaderT Env IO String
waitForString substr n = waitForCondition (Literal substr) n initialBackoffMicroseconds
waitForString = waitForCondition . Literal

defaultCountdown :: Int
defaultCountdown = 5

0 comments on commit 8d5b6e8

Please sign in to comment.
You can’t perform that action at this time.