mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-26 21:19:43 +01:00
Make test descriptions more structured and consistent
This commit is contained in:
parent
93e9a92328
commit
2262860af1
2 changed files with 29 additions and 26 deletions
|
@ -38,23 +38,23 @@ dummyMeta :: M.Map ByteString ByteString
|
||||||
dummyMeta = M.fromList [("foo","bar")]
|
dummyMeta = M.fromList [("foo","bar")]
|
||||||
|
|
||||||
testGRPCBracket :: TestTree
|
testGRPCBracket :: TestTree
|
||||||
testGRPCBracket = testCase "No errors starting and stopping GRPC" $
|
testGRPCBracket = testCase "Start/stop GRPC" $
|
||||||
withGRPC $ const $ return ()
|
withGRPC $ const $ return ()
|
||||||
|
|
||||||
testCompletionQueueCreateDestroy :: TestTree
|
testCompletionQueueCreateDestroy :: TestTree
|
||||||
testCompletionQueueCreateDestroy =
|
testCompletionQueueCreateDestroy =
|
||||||
testCase "No errors creating and destroying a CQ" $ withGRPC $ \grpc ->
|
testCase "Create/destroy completion queue" $ withGRPC $ \grpc ->
|
||||||
withCompletionQueue grpc $ const (return ())
|
withCompletionQueue grpc $ const (return ())
|
||||||
|
|
||||||
testServerCreateDestroy :: TestTree
|
testServerCreateDestroy :: TestTree
|
||||||
testServerCreateDestroy =
|
testServerCreateDestroy =
|
||||||
testCase "No errors when starting and stopping a server" $
|
testCase "Server - start/stop" $
|
||||||
withGRPC $ \grpc -> withServer grpc (ServerConfig "localhost" 50051 [])
|
withGRPC $ \grpc -> withServer grpc (ServerConfig "localhost" 50051 [])
|
||||||
(const $ return ())
|
(const $ return ())
|
||||||
|
|
||||||
testClientCreateDestroy :: TestTree
|
testClientCreateDestroy :: TestTree
|
||||||
testClientCreateDestroy =
|
testClientCreateDestroy =
|
||||||
testCase "No errors when starting and stopping a client" $
|
testCase "Client - start/stop" $
|
||||||
withGRPC $ \grpc -> withClient grpc (ClientConfig "localhost" 50051)
|
withGRPC $ \grpc -> withClient grpc (ClientConfig "localhost" 50051)
|
||||||
(const $ return ())
|
(const $ return ())
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ testPayloadLowLevelServerUnregistered grpc = do
|
||||||
Right _ -> return ()
|
Right _ -> return ()
|
||||||
|
|
||||||
testClientRequestNoServer :: TestTree
|
testClientRequestNoServer :: TestTree
|
||||||
testClientRequestNoServer = testCase "request times out when no server " $ do
|
testClientRequestNoServer =
|
||||||
|
testCase "Client - request timeout when server DNE" $
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
withClient grpc (ClientConfig "localhost" 50051) $ \client -> do
|
withClient grpc (ClientConfig "localhost" 50051) $ \client -> do
|
||||||
method <- clientRegisterMethod client "/foo" "localhost" Normal
|
method <- clientRegisterMethod client "/foo" "localhost" Normal
|
||||||
|
@ -115,7 +116,8 @@ testClientRequestNoServer = testCase "request times out when no server " $ do
|
||||||
reqResult @?= (Left GRPCIOTimeout)
|
reqResult @?= (Left GRPCIOTimeout)
|
||||||
|
|
||||||
testServerAwaitNoClient :: TestTree
|
testServerAwaitNoClient :: TestTree
|
||||||
testServerAwaitNoClient = testCase "server wait times out when no client " $ do
|
testServerAwaitNoClient =
|
||||||
|
testCase "Server - registered call handler timeout" $
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
let conf = (ServerConfig "localhost" 50051 [("/foo", "localhost", Normal)])
|
let conf = (ServerConfig "localhost" 50051 [("/foo", "localhost", Normal)])
|
||||||
withServer grpc conf $ \server -> do
|
withServer grpc conf $ \server -> do
|
||||||
|
@ -126,7 +128,7 @@ testServerAwaitNoClient = testCase "server wait times out when no client " $ do
|
||||||
|
|
||||||
testServerUnregisteredAwaitNoClient :: TestTree
|
testServerUnregisteredAwaitNoClient :: TestTree
|
||||||
testServerUnregisteredAwaitNoClient =
|
testServerUnregisteredAwaitNoClient =
|
||||||
testCase "server wait times out when no client -- unregistered method " $ do
|
testCase "Server - unregistered call handler timeout" $
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
let conf = ServerConfig "localhost" 50051 []
|
let conf = ServerConfig "localhost" 50051 []
|
||||||
withServer grpc conf $ \server -> do
|
withServer grpc conf $ \server -> do
|
||||||
|
@ -137,16 +139,17 @@ testServerUnregisteredAwaitNoClient =
|
||||||
Right _ -> return ()
|
Right _ -> return ()
|
||||||
|
|
||||||
testPayloadLowLevel :: TestTree
|
testPayloadLowLevel :: TestTree
|
||||||
testPayloadLowLevel = testCase "LowLevel Haskell library request/response " $ do
|
testPayloadLowLevel =
|
||||||
withGRPC $ \grpc -> do
|
testCase "Client/Server - low-level (registered) request/response" $
|
||||||
withAsync (testPayloadLowLevelServer grpc) $ \a1 -> do
|
withGRPC $ \grpc -> do
|
||||||
withAsync (testPayloadLowLevelClient grpc) $ \a2 -> do
|
withAsync (testPayloadLowLevelServer grpc) $ \a1 -> do
|
||||||
wait a1
|
withAsync (testPayloadLowLevelClient grpc) $ \a2 -> do
|
||||||
wait a2
|
wait a1
|
||||||
|
wait a2
|
||||||
|
|
||||||
testPayloadLowLevelUnregistered :: TestTree
|
testPayloadLowLevelUnregistered :: TestTree
|
||||||
testPayloadLowLevelUnregistered =
|
testPayloadLowLevelUnregistered =
|
||||||
testCase "LowLevel Haskell library unregistered request/response " $ do
|
testCase "Client/Server - low-level unregistered request/response" $ do
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
withAsync (testPayloadLowLevelServerUnregistered grpc) $ \a1 ->
|
withAsync (testPayloadLowLevelServerUnregistered grpc) $ \a1 ->
|
||||||
withAsync (testPayloadLowLevelClientUnregistered grpc) $ \a2 -> do
|
withAsync (testPayloadLowLevelClientUnregistered grpc) $ \a2 -> do
|
||||||
|
@ -155,7 +158,7 @@ testPayloadLowLevelUnregistered =
|
||||||
|
|
||||||
testWithServerCall :: TestTree
|
testWithServerCall :: TestTree
|
||||||
testWithServerCall =
|
testWithServerCall =
|
||||||
testCase "Creating and destroying a call: no errors. " $
|
testCase "Server - Create/destroy call" $
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
let conf = ServerConfig "localhost" 50051 []
|
let conf = ServerConfig "localhost" 50051 []
|
||||||
withServer grpc conf $ \server -> do
|
withServer grpc conf $ \server -> do
|
||||||
|
@ -164,7 +167,7 @@ testWithServerCall =
|
||||||
|
|
||||||
testWithClientCall :: TestTree
|
testWithClientCall :: TestTree
|
||||||
testWithClientCall =
|
testWithClientCall =
|
||||||
testCase "Creating and destroying a client call: no errors. " $
|
testCase "Client - Create/destroy call" $
|
||||||
withGRPC $ \grpc -> do
|
withGRPC $ \grpc -> do
|
||||||
let conf = ClientConfig "localhost" 50051
|
let conf = ClientConfig "localhost" 50051
|
||||||
withClient grpc conf $ \client -> do
|
withClient grpc conf $ \client -> do
|
||||||
|
@ -299,7 +302,7 @@ testPayloadServer = do
|
||||||
-- This is intended to test the low-level C bindings, so we use only a few
|
-- This is intended to test the low-level C bindings, so we use only a few
|
||||||
-- minimal abstractions on top of it.
|
-- minimal abstractions on top of it.
|
||||||
testPayload :: TestTree
|
testPayload :: TestTree
|
||||||
testPayload = testCase "low-level C bindings request/response " $ do
|
testPayload = testCase "Client/Server - End-to-end request/response" $ do
|
||||||
grpcInit
|
grpcInit
|
||||||
withAsync testPayloadServer $ \a1 -> do
|
withAsync testPayloadServer $ \a1 -> do
|
||||||
withAsync testPayloadClient $ \a2 -> do
|
withAsync testPayloadClient $ \a2 -> do
|
||||||
|
|
|
@ -12,7 +12,7 @@ import Test.Tasty
|
||||||
import Test.Tasty.HUnit as HU (testCase, (@?=))
|
import Test.Tasty.HUnit as HU (testCase, (@?=))
|
||||||
|
|
||||||
unsafeTests :: TestTree
|
unsafeTests :: TestTree
|
||||||
unsafeTests = testGroup "Unit tests for unsafe C bindings."
|
unsafeTests = testGroup "Unit tests for unsafe C bindings"
|
||||||
[ roundtripSlice "Hello, world!"
|
[ roundtripSlice "Hello, world!"
|
||||||
, roundtripByteBuffer "Hwaet! We gardena in geardagum..."
|
, roundtripByteBuffer "Hwaet! We gardena in geardagum..."
|
||||||
, testMetadata
|
, testMetadata
|
||||||
|
@ -23,14 +23,14 @@ unsafeTests = testGroup "Unit tests for unsafe C bindings."
|
||||||
]
|
]
|
||||||
|
|
||||||
roundtripSlice :: B.ByteString -> TestTree
|
roundtripSlice :: B.ByteString -> TestTree
|
||||||
roundtripSlice bs = testCase "Slice C bindings roundtrip" $ do
|
roundtripSlice bs = testCase "ByteString slice roundtrip" $ do
|
||||||
slice <- byteStringToSlice bs
|
slice <- byteStringToSlice bs
|
||||||
unslice <- sliceToByteString slice
|
unslice <- sliceToByteString slice
|
||||||
bs HU.@?= unslice
|
bs HU.@?= unslice
|
||||||
freeSlice slice
|
freeSlice slice
|
||||||
|
|
||||||
roundtripByteBuffer :: B.ByteString -> TestTree
|
roundtripByteBuffer :: B.ByteString -> TestTree
|
||||||
roundtripByteBuffer bs = testCase "ByteBuffer C bindings roundtrip" $ do
|
roundtripByteBuffer bs = testCase "ByteBuffer roundtrip" $ do
|
||||||
slice <- byteStringToSlice bs
|
slice <- byteStringToSlice bs
|
||||||
buffer <- grpcRawByteBufferCreate slice 1
|
buffer <- grpcRawByteBufferCreate slice 1
|
||||||
reader <- byteBufferReaderCreate buffer
|
reader <- byteBufferReaderCreate buffer
|
||||||
|
@ -44,7 +44,7 @@ roundtripByteBuffer bs = testCase "ByteBuffer C bindings roundtrip" $ do
|
||||||
freeSlice readSlice
|
freeSlice readSlice
|
||||||
|
|
||||||
testMetadata :: TestTree
|
testMetadata :: TestTree
|
||||||
testMetadata = testCase "metadata setter/getter C bindings roundtrip" $ do
|
testMetadata = testCase "Metadata setter/getter roundtrip" $ do
|
||||||
m <- metadataAlloc 3
|
m <- metadataAlloc 3
|
||||||
setMetadataKeyVal "hello" "world" m 0
|
setMetadataKeyVal "hello" "world" m 0
|
||||||
setMetadataKeyVal "foo" "bar" m 1
|
setMetadataKeyVal "foo" "bar" m 1
|
||||||
|
@ -71,26 +71,26 @@ currTimeMillis t = do
|
||||||
return tMillis
|
return tMillis
|
||||||
|
|
||||||
testNow :: TestTree
|
testNow :: TestTree
|
||||||
testNow = testCase "create and destroy various clock types" $ do
|
testNow = testCase "Create/destroy various clock types" $ do
|
||||||
_ <- currTimeMillis GprClockMonotonic
|
_ <- currTimeMillis GprClockMonotonic
|
||||||
_ <- currTimeMillis GprClockRealtime
|
_ <- currTimeMillis GprClockRealtime
|
||||||
_ <- currTimeMillis GprClockPrecise
|
_ <- currTimeMillis GprClockPrecise
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
testCreateDestroyMetadata :: TestTree
|
testCreateDestroyMetadata :: TestTree
|
||||||
testCreateDestroyMetadata = testCase "create/destroy metadataArrayPtr " $ do
|
testCreateDestroyMetadata = testCase "Create/destroy metadataArrayPtr" $ do
|
||||||
grpcInit
|
grpcInit
|
||||||
withMetadataArrayPtr $ const $ return ()
|
withMetadataArrayPtr $ const $ return ()
|
||||||
grpcShutdown
|
grpcShutdown
|
||||||
|
|
||||||
testCreateDestroyMetadataKeyVals :: TestTree
|
testCreateDestroyMetadataKeyVals :: TestTree
|
||||||
testCreateDestroyMetadataKeyVals = testCase "create/destroy metadata k/vs " $ do
|
testCreateDestroyMetadataKeyVals = testCase "Create/destroy metadata key/values" $ do
|
||||||
grpcInit
|
grpcInit
|
||||||
withMetadataKeyValPtr 10 $ const $ return ()
|
withMetadataKeyValPtr 10 $ const $ return ()
|
||||||
grpcShutdown
|
grpcShutdown
|
||||||
|
|
||||||
testCreateDestroyDeadline :: TestTree
|
testCreateDestroyDeadline :: TestTree
|
||||||
testCreateDestroyDeadline = testCase "create/destroy deadline " $ do
|
testCreateDestroyDeadline = testCase "Create/destroy deadline" $ do
|
||||||
grpcInit
|
grpcInit
|
||||||
withDeadlineSeconds 10 $ const $ return ()
|
withDeadlineSeconds 10 $ const $ return ()
|
||||||
grpcShutdown
|
grpcShutdown
|
||||||
|
|
Loading…
Reference in a new issue