Skip to content

Commit

Permalink
test for abortConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Nov 29, 2024
1 parent cce6bc0 commit 984c5bb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/IOSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ spec = do
describe "concurrency" $ do
it "can handle multiple clients" $ do
withPipe (Randomly 20) $ testMultiSendRecv cc sc waitS 500
describe "abortConnection" $ do
it "can abort connection" $ do
withPipe (Randomly 20) $ testAbort cc sc waitS

consumeBytes :: Stream -> Int -> IO ()
consumeBytes _ 0 = return ()
Expand Down Expand Up @@ -201,3 +204,30 @@ testMultiSendRecv cc sc waitS times = do
assertEndOfStream strm
putMVar (mvars !! n) ()
loop conn

appErr :: QUICException -> Bool
appErr (ApplicationProtocolErrorIsReceived _ _) = True
appErr _ = False

testAbort :: C.ClientConfig -> ServerConfig -> IO () -> IO ()
testAbort cc sc waitS = do
E.bracket (forkIO server) killThread $ \_ ->
client `shouldThrow` appErr
where
client = do
waitS
C.run cc $ \conn -> do
strm <- stream conn
sendStream strm "foo"
void $ recvStream strm 10
server = run sc loop
where
loop conn = do
_strm <- acceptStream conn
void $
forkIO $
abortConnection
conn
(ApplicationProtocolError 1)
"testing abortConnection"
loop conn

0 comments on commit 984c5bb

Please sign in to comment.