File: ThreadSpec.hs

package info (click to toggle)
haskell-warp 3.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 300 kB
  • ctags: 2
  • sloc: haskell: 2,890; makefile: 8
file content (26 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# LANGUAGE BangPatterns #-}

module ThreadSpec where

import Control.Concurrent (threadDelay)
import Data.IORef (readIORef, writeIORef, atomicModifyIORef)
import Network.Wai.Handler.Warp.Thread
import Test.Hspec

main :: IO ()
main = hspec spec

spec :: Spec
spec = describe "forkIOwithBreakableForever" $ do
    it "can be breakable" $ do
        ref' <- forkIOwithBreakableForever True $ \ref -> do
            threadDelay 1000
            !_ <- atomicModifyIORef ref (\x -> (False, x))
            return ()
        threadDelay 100000
        readIORef ref' `shouldReturn` False
        _ <- breakForever ref'
        threadDelay 100000
        writeIORef ref' True
        threadDelay 100000
        readIORef ref' `shouldReturn` True