packages feed

failure-detector-0: tests/Distributed/Failure/Test/Properties.hs

module Distributed.Failure.Test.Properties where

import Test.QuickCheck

import Distributed.Failure.Class

{- | We test that we eventually will decide a remote process is dead,
     after its been alive but stops responding.

     As a proxy for infinity, we'll claim that we should have detected it as dead if we don't
     hear from it for a year.
-}
eventuallyDead :: FailureDetector d => d -> [(Positive Double)] -> Property
eventuallyDead d0 liveLog =
  all (\(Positive t) -> t < (60*60*24*7)) liveLog ==>
      let d1 = foldl observe d0 . map (fromRational . toRational . getPositive) $ liveLog
          wasLife = not .  suspected d1 $ 0
          endsDead = suspected d1 $ 60*60*24*7*52
      in wasLife && endsDead