@@ -22,6 +22,7 @@ import Network.HTTP.Types (methodGet, methodHead, parseMethod,
2222 renderStdMethod, status100, status200,
2323 status201, status300, status401,
2424 status405, status500)
25+import System.Clock (toNanoSecs, Clock(Monotonic), getTime, diffTimeSpec)
2526import Prelude.Compat
2627
2728import Servant.QuickCheck.Internal.ErrorTypes
@@ -40,6 +41,22 @@ not500 :: ResponsePredicate
4041not500 = ResponsePredicate $ \resp ->
4142 when (responseStatus resp == status500) $ fail "not500"
4243
44+-- | [__Optional__]
45+--
46+-- This function checks that the response from the server does not take longer
47+-- than the specified number of nanoseconds.
48+--
49+-- #SINCE#
50+notLongerThan :: Integer -> RequestPredicate
51+notLongerThan maxAllowed
52+ = RequestPredicate $ \req mgr -> do
53+ start <- getTime Monotonic
54+ resp <- httpLbs req mgr
55+ end <- getTime Monotonic
56+ when (toNanoSecs (end `diffTimeSpec` start) > maxAllowed) $
57+ throw $ PredicateFailure "notLongerThan" (Just req) resp
58+ return []
59+
4360-- | [__Best Practice__]
4461--
4562-- Returning anything other than an object when returning JSON is considered
@@ -126,7 +143,7 @@ createContainsValidLocation
126143-- * If-Unmodified-Since header: <https://tools.ietf.org/html/rfc7232#section-3.4 RFC 7232 Section 3.4>
127144-- * Date format: <https://tools.ietf.org/html/rfc2616#section-3.3 RFC 2616 Section 3.3>
128145--
129−-- #SINCECURRENT#
146+-- #SINCE#
130147getsHaveLastModifiedHeader :: RequestPredicate
131148getsHaveLastModifiedHeader
132149 = RequestPredicate $ \req mgr ->