Skip to content

Commit

Permalink
refactor(runtime): simplify SPSC test, thanks Daniel
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Oct 18, 2021
1 parent 365ca49 commit 368e0c0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/runtime-prototype/test/DisruptorTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ unit_ringBufferSingleProducerSingleConsumer = do
backPressure () = return ()
ep <- newEventProducer rb production backPressure ()
let handler seen n _snr endOfBatch
| n `Set.member` seen = error (show n ++ " appears twice")
| otherwise = do
| n /= seen = error (show n ++ " appears twice")
| otherwise = do
putStrLn ("consumer got: " ++ show n ++
if endOfBatch then ". End of batch!" else "")
return (Set.insert n seen)
ec <- newEventConsumer rb handler Set.empty [] (Sleep 1000)
return (succ seen)
ec <- newEventConsumer rb handler 0 [] (Sleep 1000)

setGatingSequences rb [Exists ec]

Expand Down Expand Up @@ -118,15 +118,9 @@ unit_ringBufferSingleProducerSingleConsumer = do
shutdownConsumer ec
seen <- wait aec
putStrLn "Done consuming!"
assert (increasingByOneFrom 0 (Set.toList seen))
where
atLeastThisManyEvents = 1000

increasingByOneFrom :: Int -> [Int] -> Bool
increasingByOneFrom n [] = n >= atLeastThisManyEvents && n < atLeastThisManyEvents + 500
increasingByOneFrom n (i : is) | n == i = increasingByOneFrom (n + 1) is
| otherwise = False

unit_ringBufferFiveProducersOneConsumer :: Assertion
unit_ringBufferFiveProducersOneConsumer = do
rb <- newRingBuffer MultiProducer 128
Expand Down

0 comments on commit 368e0c0

Please sign in to comment.