on e80fd0c help sign in
34 lines 906 B history raw
1module Control.AutoUpdateSpec (spec) where
3import Test.Hspec
4import Test.Hspec.QuickCheck
5import Data.IORef
6import Control.Concurrent (threadDelay)
7import Control.Monad (replicateM_, forM_)
8import Control.AutoUpdate
10spec :: Spec
11spec = do
12 prop "incrementer" $ \st' -> do
13 let st = abs st' `mod` 10000
14 ref <- newIORef 0
15 next <- mkAutoUpdate defaultUpdateSettings
16 { updateAction = atomicModifyIORef ref $ \i ->
17 let i' = succ i in i' `seq` (i', i')
18 , updateSpawnThreshold = st
19 , updateFreq = 10000
20 }
22 forM_ [1..st + 1] $ \i -> do
23 j <- next
24 j `shouldBe` i
26 replicateM_ 50 $ do
27 i <- next
28 i `shouldBe` st + 2
30 threadDelay 60000
31 last1 <- readIORef ref
32 threadDelay 20000
33 last2 <- readIORef ref
34 last2 `shouldBe` last1