on master help sign in
Clarified client-facing interface
commitbdf4d4a6e67c7cee96b72550d06bb920c78b4667 authorSamuel Schlesinger <samuel@simspace.com> dateSun 13 Sep 2020, 15:41 (6 years ago) parentde39a1f
3 files changed+14−12
README.md+1−2 src/Roboservant/StateMachine.hs+10−5 test/Spec.hs+3−5
README.md+1−2
@@ -29,9 +29,8 @@ type FooApi =
2929From the tests:
3030
3131```
32− let reifiedApi = RS.toReifiedApi (RS.flattenServer @Foo.FooApi Foo.fooServer) (Proxy @(Endpoints Foo.FooApi))
3332 assert "should find an error in Foo" . not
34− =<< checkSequential (Group "Foo" [("Foo", RS.prop_sequential reifiedApi)])
33+ =<< checkSequential (Group "Foo" [("Foo", RS.prop_sequential @Foo.FooApi Foo.fooServer)])
3534```
3635
3736We have a server that blows up if the value of the int in a `Foo` ever gets above 10. Note:
src/Roboservant/StateMachine.hs+10−5
@@ -16,7 +16,10 @@
1616{-# LANGUAGE TypeOperators #-}
1717{-# LANGUAGE UndecidableInstances #-}
1818
19−module Roboservant.StateMachine where
19+module Roboservant.StateMachine
20+( prop_sequential
21+, prop_concurrent
22+) where
2023
2124import Control.Monad.Except (runExceptT)
2225import Control.Monad.IO.Class (MonadIO, liftIO)
@@ -223,8 +226,9 @@ callEndpoint staticRoutes =
223226 -- , Ensure (no-500 here)
224227 ]
225228
226−prop_sequential :: ReifiedApi -> Property
227−prop_sequential reifiedApi = do
229+prop_sequential :: forall api. (FlattenServer api, ToReifiedApi (Endpoints api)) => Server api -> Property
230+prop_sequential server = do
231+ let reifiedApi = toReifiedApi (flattenServer @api server) (Proxy @(Endpoints api))
228232 property $ do
229233 let initialState = State mempty
230234 actions <-
@@ -235,8 +239,9 @@ prop_sequential reifiedApi = do
235239 [callEndpoint reifiedApi]
236240 executeSequential initialState actions
237241
238−prop_concurrent :: ReifiedApi -> Property
239−prop_concurrent reifiedApi =
242+prop_concurrent :: forall api. (FlattenServer api, ToReifiedApi (Endpoints api)) => Server api -> Property
243+prop_concurrent server =
244+ let reifiedApi = toReifiedApi (flattenServer @api server) (Proxy @(Endpoints api)) in
240245 let initialState = State mempty
241246 in withTests 1000 . withRetries 10 . property $ do
242247 actions <-
test/Spec.hs+3−5
@@ -17,15 +17,13 @@ assert err False = ioError $ userError err
1717-- | This is horribly laid out, sorry. Will fix at some point.
1818main :: IO ()
1919main = do
20− let reifiedApi = RS.toReifiedApi (RS.flattenServer @Foo.FooApi Foo.fooServer) (Proxy @(Endpoints Foo.FooApi))
2120 assert "should find an error in Foo" . not
22− =<< checkSequential (Group "Foo" [("Foo", RS.prop_sequential reifiedApi)])
21+ =<< checkSequential (Group "Foo" [("Foo", RS.prop_sequential @Foo.FooApi Foo.fooServer)])
2322 -- The UnsafeIO checker does not actually really use the contextually aware stuff, though it
2423 -- could: it's mostly here to show how to test for concurrency problems.
2524 unsafeServer <- UnsafeIO.makeServer
26− let unsafeApi = RS.toReifiedApi (RS.flattenServer @UnsafeIO.UnsafeApi unsafeServer) (Proxy @(Endpoints UnsafeIO.UnsafeApi))
2725 -- this will not detect the error, as it requires concurrency.
28− assert "should find nothing" =<< checkSequential (Group "Unsafe" [("Sequential", RS.prop_sequential unsafeApi)])
26+ assert "should find nothing" =<< checkSequential (Group "Unsafe" [("Sequential", RS.prop_sequential @UnsafeIO.UnsafeApi unsafeServer)])
2927 -- this will!
3028 assert "should find with parallel check" . not
31− =<< checkSequential (Group "Unsafe" [("Parallel", RS.prop_concurrent unsafeApi)])
29+ =<< checkSequential (Group "Unsafe" [("Parallel", RS.prop_concurrent @UnsafeIO.UnsafeApi unsafeServer)])