Skip to content

Commit

Permalink
Better treatment of (non)determinism in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Jul 17, 2023
1 parent 357d29a commit 48134cb
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 328 deletions.
1 change: 0 additions & 1 deletion grapesy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ test-suite test-grapesy
-- , tasty-quickcheck >= 0.10 && < 0.11
, text >= 1.2 && < 2.1
, tls >= 1.5 && < 1.8
, unbounded-delays >= 0.1 && < 0.2

executable demo-client
import:
Expand Down
4 changes: 2 additions & 2 deletions src/Network/GRPC/Spec/CustomMetadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ data CustomMetadata =
newtype HeaderName = UnsafeHeaderName {
getHeaderName :: Strict.ByteString
}
deriving stock (Eq)
deriving stock (Eq, Ord)

-- | 'Show' instance relies on the 'HeaderName' pattern synonym
instance Show HeaderName where
Expand Down Expand Up @@ -145,7 +145,7 @@ isValidHeaderName bs = and [
newtype AsciiValue = UnsafeAsciiValue {
getAsciiValue :: Strict.ByteString
}
deriving stock (Eq)
deriving stock (Eq, Ord)

-- | 'Show' instance relies on the 'AsciiValue' pattern synonym
instance Show AsciiValue where
Expand Down
44 changes: 22 additions & 22 deletions test-grapesy/Test/Driver/ClientServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ instance Default ClientServerTest where
, server = []
}

testClientServer :: IO ClientServerTest -> IO String
testClientServer mkTest = do
ClientServerTest{config, client, server} <- mkTest
mRes <- try $ runTestClientServer config client server
case mRes of
Left err
| Just (testFailure :: HUnitFailure) <- fromException err
-> throwIO testFailure

| isExpectedException config err
-> return $ "Got expected error: " ++ show err

| otherwise
-> assertFailure $ concat [
"Unexpected exception of type "
, case err of
SomeException e -> show (typeOf e)
, ": "
, show err
]
Right () ->
return ""
testClientServer :: (forall a. (ClientServerTest -> IO a) -> IO a) -> IO String
testClientServer withTest =
withTest $ \ClientServerTest{config, client, server} -> do
mRes <- try $ runTestClientServer config client server
case mRes of
Left err
| Just (testFailure :: HUnitFailure) <- fromException err
-> throwIO testFailure

| isExpectedException config err
-> return $ "Got expected error: " ++ show err

| otherwise
-> assertFailure $ concat [
"Unexpected exception of type "
, case err of
SomeException e -> show (typeOf e)
, ": "
, show err
]
Right () ->
return ""

Loading

0 comments on commit 48134cb

Please sign in to comment.