packages feed

festung-0.9.1.1: tests/Festung/Concurrency/GigSpec.hs

module Festung.Concurrency.GigSpec (spec) where

import Test.Hspec

import Control.Concurrent
import Festung.Concurrency.Job
import Festung.Concurrency.Gig


newSquareGig :: Int -> IO (Job (Command Int Int))
newSquareGig timeout = newGig_ timeout handler
    where handler (Command n responder) = putMVar responder (n * n)


noTimeout :: Int
noTimeout = 2 * 60 * 1000 * 1000 -- Two minutes is a long timeout


spec :: Spec
spec =
    describe "newGig" $ do
        it "Starts a new gig" $ do
            job <- newSquareGig noTimeout
            isJobRunning job `shouldReturn` True

        it "Processes messages" $ do
            job  <- newSquareGig noTimeout
            sendCommand job 2 `shouldReturn` Just 4