Skip to content

Commit

Permalink
refactoring #38 | move waiting logic into dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Mar 11, 2019
1 parent b292211 commit a9a0c8c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/unit/Cardano/Wallet/BlockSyncerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import Data.Time.Units
import Data.Tuple
( swap )
import Test.Hspec
( Arg, Spec, SpecWith, describe, it )
import Test.Hspec.Expectations
( shouldBe )
( Arg, Spec, SpecWith, describe, it, shouldReturn )
import Test.QuickCheck
( Arbitrary (..)
, Property
Expand Down Expand Up @@ -74,11 +72,17 @@ tickingFunctionTest (TickingTime tickTime, Blocks blocks) = monadicIO $ liftIO $
readerChan <- newMVar []
let reader = mkReader readerChan
writer <- mkWriter done blocks
threadId <- forkIO $ tickingFunction writer reader tickTime (BlockHeadersConsumed [])
waitFor done $ tickingFunction writer reader tickTime (BlockHeadersConsumed [])
takeMVar readerChan `shouldReturn` L.nub (reverse blocks)

waitFor
:: MVar ()
-> IO ()
-> IO ()
waitFor done action = do
threadId <- forkIO action
_ <- takeMVar done
killThread threadId
obtainedData <- takeMVar readerChan
obtainedData `shouldBe` L.nub (reverse blocks)

mkWriter
:: MVar ()
Expand Down

0 comments on commit a9a0c8c

Please sign in to comment.