From b004856ee4383fd479ddd4a230c42457c76d8827 Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Mon, 25 Jun 2018 19:49:50 +0200 Subject: [PATCH] Fix tests --- .../Monad => Effect}/Aff/Reattempt.purs | 2 +- test/Main.purs | 31 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) rename src/{Control/Monad => Effect}/Aff/Reattempt.purs (96%) diff --git a/src/Control/Monad/Aff/Reattempt.purs b/src/Effect/Aff/Reattempt.purs similarity index 96% rename from src/Control/Monad/Aff/Reattempt.purs rename to src/Effect/Aff/Reattempt.purs index ba47cec..37e3784 100644 --- a/src/Control/Monad/Aff/Reattempt.purs +++ b/src/Effect/Aff/Reattempt.purs @@ -1,4 +1,4 @@ -module Control.Monad.Aff.Reattempt where +module Effect.Aff.Reattempt where import Prelude diff --git a/test/Main.purs b/test/Main.purs index abef010..695b4cf 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,14 +1,8 @@ module Test.Main where import Prelude - +import Effect.Aff import Control.Alt ((<|>)) -import Control.Monad.Aff (Aff, attempt, delay) -import Control.Monad.Aff.AVar (makeVar, takeVar, putVar, AVar, AVAR) -import Control.Monad.Aff.Reattempt (reattempt) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) -import Control.Monad.Eff.Ref (REF) import Control.Parallel.Class (parallel, sequential) import Control.Plus (empty) import Data.Array (head, tail) @@ -18,12 +12,15 @@ import Data.Maybe (maybe, fromMaybe) import Data.Newtype (unwrap) import Data.Time.Duration (Milliseconds(..)) import Data.Unfoldable (replicate) +import Effect (Effect) +import Effect.Aff.AVar (new, take, put, AVar) +import Effect.Aff.Reattempt (reattempt) +import Effect.Console (log) import Test.Unit (test, suite) import Test.Unit.Assert (assert) -import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) -failAffsForDurationAndNumberOfAttempts ∷ ∀ e. Milliseconds → Int → Array (Aff e Unit) +failAffsForDurationAndNumberOfAttempts ∷ Milliseconds → Int → Array (Aff Unit) failAffsForDurationAndNumberOfAttempts timeout attemptCount = seq where seq = replicate attemptCount do @@ -31,13 +28,13 @@ failAffsForDurationAndNumberOfAttempts timeout attemptCount = seq empty interval = Milliseconds (unwrap timeout / toNumber attemptCount) -affDouble ∷ ∀ e. AVar (Array (Aff (avar ∷ AVAR | e) Unit)) → Aff (avar ∷ AVAR | e) Unit +affDouble ∷ AVar (Array (Aff Unit)) -> Aff Unit affDouble affsVar = do - affs ← takeVar affsVar - putVar (fromMaybe [] (tail affs)) affsVar - maybe (pure unit) id $ head affs + affs ← take affsVar + put (fromMaybe [] (tail affs)) affsVar + maybe (pure unit) identity $ head affs -main ∷ ∀ eff. Eff (console ∷ CONSOLE, testOutput ∷ TESTOUTPUT, ref ∷ REF, avar ∷ AVAR | eff) Unit +main ∷ Effect Unit main = runTest do test "When the Aff never succeeds the returned Aff should fail" do result ← attempt $ reattempt (Milliseconds 100.0) do @@ -46,7 +43,7 @@ main = runTest do assert "The returned Aff did not fail" $ Either.isLeft result test "When the timeout will elapse before any attempts to run the Aff are successful the returned Aff should fail" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 1000.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 1000.0) 10 result ← attempt $ reattempt (Milliseconds 100.0) (affDouble seq) assert "The returned Aff did not fail" $ Either.isLeft result @@ -59,12 +56,12 @@ main = runTest do suite "When the Aff will succeed during an attempt started before the timeout will elapse" do test "The returned Aff should be successful" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 result ← attempt $ reattempt (Milliseconds 100000000.0) (affDouble seq) assert "The returned Aff failed" $ Either.isRight result test "The returned Aff should not wait for the timeout to elapse in order to succeed" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 let parReattempt = parallel (reattempt (Milliseconds 100000000.0) (affDouble seq) $> true) parLater = parallel do