@@ -2,9 +2,9 @@
2module TestTransport where
2module TestTransport where
4import Prelude hiding (catch, (>>=), (>>), return, fail)
4import Prelude hiding (catch, (>>=), (>>), return, fail)
5−import TestAuxiliary (forkTry, runTests)
5+import TestAuxiliary (forkTry, runTests, trySome)
6import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar, readMVar)
6import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar, readMVar)
7−import Control.Exception (evaluate, try, SomeException)
7+import Control.Exception (evaluate, throw)
8import Control.Monad (replicateM, replicateM_, when, guard, forM_)
8import Control.Monad (replicateM, replicateM_, when, guard, forM_)
9import Control.Monad.Error ()
9import Control.Monad.Error ()
10import Network.Transport hiding (connect)
10import Network.Transport hiding (connect)
@@ -745,13 +745,43 @@ testExceptionOnReceive newTransport = do
745 Right endpoint1 <- newEndPoint transport
745 Right endpoint1 <- newEndPoint transport
746 closeEndPoint endpoint1
746 closeEndPoint endpoint1
747 EndPointClosed <- receive endpoint1
747 EndPointClosed <- receive endpoint1
748− Left _ <- (try :: IO a -> IO (Either SomeException a)) (receive endpoint1 >>= evaluate)
748+ Left _ <- trySome (receive endpoint1 >>= evaluate)
750 -- Test two: when we close the entire transport
750 -- Test two: when we close the entire transport
751 Right endpoint2 <- newEndPoint transport
751 Right endpoint2 <- newEndPoint transport
752 closeTransport transport
752 closeTransport transport
753 EndPointClosed <- receive endpoint2
753 EndPointClosed <- receive endpoint2
754− Left _ <- (try :: IO a -> IO (Either SomeException a)) (receive endpoint2 >>= evaluate)
754+ Left _ <- trySome (receive endpoint2 >>= evaluate)
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
764+ -- Connect endpoint1 to endpoint2
765+ Right conn <- connect endpoint1 (address endpoint2) ReliableOrdered
766+ ConnectionOpened _ _ _ <- receive endpoint2
768+ -- Send an exceptional value
769+ Left (TransportError SendFailed _) <- send conn (throw $ userError "uhoh")
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
777+ -- A new connection will re-establish the connection
778+ Right conn2 <- connect endpoint1 (address endpoint2) ReliableOrdered
782+ ConnectionOpened _ _ _ <- receive endpoint2
783+ Received _ ["ping"] <- receive endpoint2
784+ ConnectionClosed _ <- receive endpoint2
756 return ()
786 return ()
@@ -775,6 +805,7 @@ testTransport newTransport = do
775 , ("CloseTransport", testCloseTransport newTransport)
805 , ("CloseTransport", testCloseTransport newTransport)
776 , ("ConnectClosedEndPoint", testConnectClosedEndPoint transport)
806 , ("ConnectClosedEndPoint", testConnectClosedEndPoint transport)
777 , ("ExceptionOnReceive", testExceptionOnReceive newTransport)
807 , ("ExceptionOnReceive", testExceptionOnReceive newTransport)
808+ , ("SendException", testSendException newTransport)
780 numPings = 10000 :: Int
811 numPings = 10000 :: Int