@@ -2,9 +2,9 @@
22module TestTransport where
33
44import Prelude hiding (catch, (>>=), (>>), return, fail)
5−import TestAuxiliary (forkTry, runTests)
5+import TestAuxiliary (forkTry, runTests, trySome)
66import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar, readMVar)
7−import Control.Exception (evaluate, try, SomeException)
7+import Control.Exception (evaluate, throw)
88import Control.Monad (replicateM, replicateM_, when, guard, forM_)
99import Control.Monad.Error ()
1010import Network.Transport hiding (connect)
@@ -745,13 +745,43 @@ testExceptionOnReceive newTransport = do
745745 Right endpoint1 <- newEndPoint transport
746746 closeEndPoint endpoint1
747747 EndPointClosed <- receive endpoint1
748− Left _ <- (try :: IO a -> IO (Either SomeException a)) (receive endpoint1 >>= evaluate)
748+ Left _ <- trySome (receive endpoint1 >>= evaluate)
749749
750750 -- Test two: when we close the entire transport
751751 Right endpoint2 <- newEndPoint transport
752752 closeTransport transport
753753 EndPointClosed <- receive endpoint2
754− Left _ <- (try :: IO a -> IO (Either SomeException a)) (receive endpoint2 >>= evaluate)
754+ Left _ <- trySome (receive endpoint2 >>= evaluate)
755+
756+ return ()
757+
758+testSendException :: IO (Either String Transport) -> IO ()
759+testSendException newTransport = do
760+ Right transport <- newTransport
761+ Right endpoint1 <- newEndPoint transport
762+ Right endpoint2 <- newEndPoint transport
763+
764+ -- Connect endpoint1 to endpoint2
765+ Right conn <- connect endpoint1 (address endpoint2) ReliableOrdered
766+ ConnectionOpened _ _ _ <- receive endpoint2
767+
768+ -- Send an exceptional value
769+ Left (TransportError SendFailed _) <- send conn (throw $ userError "uhoh")
770+
771+ -- This will have been as a failure to send by endpoint1, which will
772+ -- therefore have closed the socket. In turn this will have caused endpoint2
773+ -- to report that the connection was lost
774+ ErrorEvent (TransportError (EventConnectionLost _ []) _) <- receive endpoint1
775+ ErrorEvent (TransportError (EventConnectionLost _ [_]) _) <- receive endpoint2
776+
777+ -- A new connection will re-establish the connection
778+ Right conn2 <- connect endpoint1 (address endpoint2) ReliableOrdered
779+ send conn2 ["ping"]
780+ close conn2
781+
782+ ConnectionOpened _ _ _ <- receive endpoint2
783+ Received _ ["ping"] <- receive endpoint2
784+ ConnectionClosed _ <- receive endpoint2
755785
756786 return ()
757787
@@ -775,6 +805,7 @@ testTransport newTransport = do
775805 , ("CloseTransport", testCloseTransport newTransport)
776806 , ("ConnectClosedEndPoint", testConnectClosedEndPoint transport)
777807 , ("ExceptionOnReceive", testExceptionOnReceive newTransport)
808+ , ("SendException", testSendException newTransport)
778809 ]
779810 where
780811 numPings = 10000 :: Int