on wai-extra/2.1.0.1 help sign in
typeable/wai/warp/test/ThreadSpec.hs
26 lines 741 B history raw
1{-# LANGUAGE BangPatterns #-}
3module ThreadSpec where
5import Control.Concurrent (threadDelay)
6import Data.IORef (readIORef, writeIORef, atomicModifyIORef)
7import Network.Wai.Handler.Warp.Thread
8import Test.Hspec
10main :: IO ()
11main = hspec spec
13spec :: Spec
14spec = describe "forkIOwithBreakableForever" $ do
15 it "can be breakable" $ do
16 ref' <- forkIOwithBreakableForever True $ \ref -> do
17 threadDelay 1000
18 !_ <- atomicModifyIORef ref (\x -> (False, x))
19 return ()
20 threadDelay 100000
21 readIORef ref' `shouldReturn` False
22 _ <- breakForever ref'
23 threadDelay 100000
24 writeIORef ref' True
25 threadDelay 100000
26 readIORef ref' `shouldReturn` True