Skip to content

Commit

Permalink
Add test for #257
Browse files Browse the repository at this point in the history
The problem is fixed in latest `http2`
(`7036a3429fb08bfcd5947230c37d1f3e63dfb3a6`).  See
kazu-yamamoto/http2#151 for the `http2` bug report.

Closes #257.
  • Loading branch information
edsko committed Nov 16, 2024
1 parent 3e2be47 commit ab47c7d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package grapesy
benchmarks: True
flags: +build-demo +build-stress-test

source-repository-package
type: git
location: https://github.com/kazu-yamamoto/http2
tag: 7036a3429fb08bfcd5947230c37d1f3e63dfb3a6

--
-- ghc 9.10
--
Expand Down
1 change: 1 addition & 0 deletions grapesy/grapesy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ test-suite test-grapesy
Test.Sanity.EndOfStream
Test.Sanity.Exception
Test.Sanity.Interop
Test.Sanity.Reclamation
Test.Sanity.StreamingType.CustomFormat
Test.Sanity.StreamingType.NonStreaming
Test.Util
Expand Down
2 changes: 2 additions & 0 deletions grapesy/test-grapesy/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Test.Sanity.Disconnect qualified as Disconnect
import Test.Sanity.EndOfStream qualified as EndOfStream
import Test.Sanity.Exception qualified as Exception
import Test.Sanity.Interop qualified as Interop
import Test.Sanity.Reclamation qualified as Reclamation
import Test.Sanity.StreamingType.CustomFormat qualified as StreamingType.CustomFormat
import Test.Sanity.StreamingType.NonStreaming qualified as StreamingType.NonStreaming

Expand All @@ -38,6 +39,7 @@ main = do
, Compression.tests
, Exception.tests
, Interop.tests
, Reclamation.tests
, BrokenDeployments.tests
]
, testGroup "Prop" [
Expand Down
61 changes: 61 additions & 0 deletions grapesy/test-grapesy/Test/Sanity/Reclamation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module Test.Sanity.Reclamation (tests) where

import Control.Exception
import Control.Monad
import Test.Tasty
import Test.Tasty.HUnit

import Network.GRPC.Client qualified as Client
import Network.GRPC.Common
import Network.GRPC.Common.Protobuf
import Network.GRPC.Server qualified as Server

import Test.Driver.ClientServer

import Proto.API.Ping

tests :: TestTree
tests = testGroup "Test.Sanity.Reclamation" [
testCase "serverException1" serverException1
, testCase "serverException2" serverException2
]

{-------------------------------------------------------------------------------
Server-side exception
-------------------------------------------------------------------------------}

-- | Handler that throws immediately
brokenHandler :: Server.Call Ping -> IO ()
brokenHandler _call = throwIO $ DeliberateException $ userError "Broken handler"

serverException1 :: Assertion
serverException1 = testClientServer $ ClientServerTest {
config = def
, server = [Server.someRpcHandler $ Server.mkRpcHandler brokenHandler]
, client = \params testServer delimitTestScope -> delimitTestScope $
replicateM_ 1000 $ do
Client.withConnection params testServer $ \conn ->
Client.withRPC conn def (Proxy @Ping) $ \call -> do
resp <- try $ Client.recvFinalOutput call
case resp of
Left GrpcException{} -> return ()
Right _ -> assertFailure "Unexpected response"
}

serverException2 :: Assertion
serverException2 = testClientServer $ ClientServerTest {
config = def
, server = [Server.someRpcHandler $ Server.mkRpcHandler brokenHandler]
, client = \params testServer delimitTestScope -> delimitTestScope $
replicateM_ 1000 $
Client.withConnection params testServer $ \conn ->
Client.withRPC conn def (Proxy @Ping) $ \call -> do

-- The only difference between serverException1 is this line:
Client.sendFinalInput call defMessage

resp <- try $ Client.recvFinalOutput call
case resp of
Left GrpcException{} -> return ()
Right _ -> assertFailure "Unexpected response"
}

0 comments on commit ab47c7d

Please sign in to comment.