auto-update 0.1.1.1 → 0.1.1.2
raw patch · 3 files changed
+40/−2 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- auto-update.cabal +2/−1
- test/Control/AutoUpdateSpec.hs +1/−1
- test/Control/ReaperSpec.hs +37/−0
auto-update.cabal view
@@ -1,5 +1,5 @@ name: auto-update-version: 0.1.1.1+version: 0.1.1.2 synopsis: Efficiently run periodic, on-demand actions description: A common problem is the desire to have an action run at a scheduled interval, but only if it is needed. For example, instead of having every web request result in a new @getCurrentTime@ call, we'd like to have a single worker thread run every second, updating an @IORef@. However, if the request frequency is less than once per second, this is a pessimization, and worse, kills idle GC.@@ -25,6 +25,7 @@ test-suite spec main-is: Spec.hs other-modules: Control.AutoUpdateSpec+ Control.ReaperSpec hs-source-dirs: test type: exitcode-stdio-1.0 build-depends: base, auto-update, hspec
test/Control/AutoUpdateSpec.hs view
@@ -10,7 +10,7 @@ spec :: Spec spec = do prop "incrementer" $ \st' -> do- let st = abs st'+ let st = abs st' `mod` 10000 ref <- newIORef 0 next <- mkAutoUpdate defaultUpdateSettings { updateAction = atomicModifyIORef ref $ \i ->
+ test/Control/ReaperSpec.hs view
@@ -0,0 +1,37 @@+module Control.ReaperSpec (spec) where++import Control.Reaper+import Control.Concurrent+import Test.Hspec+import Test.Hspec.QuickCheck+import Data.IORef++type Item = (Int, IORef Int)++action = mkListAction $ \(i, ref) -> do+ modifyIORef ref succ+ return $ if i > 1+ then Just (pred i, ref)+ else Nothing++spec :: Spec+spec = prop "works" $ \is -> do+ reaper <- mkReaper defaultReaperSettings+ { reaperAction = action+ , reaperDelay = 1000+ }++ let mkTestCase i = do+ ref <- newIORef 0+ let expected = (abs i `mod` 10) + 1+ reaperAdd reaper (expected, ref)+ return (expected, ref)+ testCases <- mapM mkTestCase is++ let test (expected, ref) = do+ actual <- readIORef ref+ actual `shouldBe` (expected :: Int)+ threadDelay 100000+ mapM_ test testCases+ [] <- reaperRead reaper+ return ()