@@ -691,6 +691,43 @@ testUnidirectionalError nextPort = do
691691
692692 takeMVar clientDone
693693
694+testInvalidCloseConnection :: IO N.ServiceName -> IO ()
695+testInvalidCloseConnection nextPort = do
696+ Right (transport, internals) <- nextPort >>= createTransportExposeInternals "127.0.0.1"
697+ serverAddr <- newEmptyMVar
698+ clientDone <- newEmptyMVar
699+ serverDone <- newEmptyMVar
700+
701+ -- Server
702+ forkTry $ do
703+ Right endpoint <- newEndPoint transport
704+ putMVar serverAddr (address endpoint)
705+
706+ ConnectionOpened _ _ _ <- receive endpoint
707+
708+ -- At this point the client sends an invalid request, so we terminate the
709+ -- connection
710+ ErrorEvent (TransportError (EventConnectionLost _ [_]) _) <- receive endpoint
711+
712+ putMVar serverDone ()
713+
714+ -- Client
715+ forkTry $ do
716+ Right endpoint <- newEndPoint transport
717+ let ourAddr = address endpoint
718+
719+ -- Connect so that we have a TCP connection
720+ theirAddr <- readMVar serverAddr
721+ Right _ <- connect endpoint theirAddr ReliableOrdered defaultConnectHints
722+
723+ -- Get a handle on the TCP connection and manually send an invalid CloseConnection request
724+ Right sock <- socketBetween internals ourAddr theirAddr
725+ sendMany sock [encodeInt32 CloseConnection, encodeInt32 (12345 :: Int)]
726+
727+ putMVar clientDone ()
728+
729+ mapM_ takeMVar [clientDone, serverDone]
730+
694731main :: IO ()
695732main = do
696733 portMVar <- newEmptyMVar
@@ -708,5 +745,6 @@ main = do
708745 , ("BreakTransport", testBreakTransport nextPort)
709746 , ("Reconnect", testReconnect nextPort)
710747 , ("UnidirectionalError", testUnidirectionalError nextPort)
748+ , ("InvalidCloseConnection", testInvalidCloseConnection nextPort)
711749 ]
712750 testTransport (either (Left . show) (Right) <$> nextPort >>= createTransport "127.0.0.1")