@@ -23,8 +23,8 @@ import Control.Concurrent.MVar
23
23
, readMVar
24
24
)
25
25
import Control.Monad (replicateM_ , replicateM , forever , void , unless , join )
26
+ import Control.Monad.Catch as Ex (catch , finally , mask , onException , try )
26
27
import Control.Exception (SomeException , throwIO , ErrorCall (.. ))
27
- import qualified Control.Exception as Ex (catch )
28
28
import Control.Applicative ((<$>) , (<*>) , pure , (<|>) )
29
29
import qualified Network.Transport as NT (closeEndPoint , EndPointAddress )
30
30
import Control.Distributed.Process
@@ -145,19 +145,20 @@ monitorTestProcess :: ProcessId -- Process to monitor/link to
145
145
-> MVar () -- Signal for successful termination
146
146
-> Process ()
147
147
monitorTestProcess theirAddr mOrL un reason monitorSetup done =
148
- catch (do mRef <- monitorOrLink mOrL theirAddr monitorSetup
149
- case (un, mRef) of
150
- (True , Nothing ) -> do
151
- unlink theirAddr
152
- liftIO $ putMVar done ()
153
- (True , Just ref) -> do
154
- unmonitor ref
155
- liftIO $ putMVar done ()
156
- (False , ref) -> do
157
- ProcessMonitorNotification ref' pid reason' <- expect
158
- True <- return $ Just ref' == ref && pid == theirAddr && mOrL && reason == reason'
159
- liftIO $ putMVar done ()
160
- )
148
+ Ex. catch (do
149
+ mRef <- monitorOrLink mOrL theirAddr monitorSetup
150
+ case (un, mRef) of
151
+ (True , Nothing ) -> do
152
+ unlink theirAddr
153
+ liftIO $ putMVar done ()
154
+ (True , Just ref) -> do
155
+ unmonitor ref
156
+ liftIO $ putMVar done ()
157
+ (False , ref) -> do
158
+ ProcessMonitorNotification ref' pid reason' <- expect
159
+ True <- return $ Just ref' == ref && pid == theirAddr && mOrL && reason == reason'
160
+ liftIO $ putMVar done ()
161
+ )
161
162
(\ (ProcessLinkException pid reason') -> do
162
163
True <- return $ pid == theirAddr && not mOrL && not un && reason == reason'
163
164
liftIO $ putMVar done ()
@@ -651,10 +652,10 @@ testRegistry TestTransport{..} = do
651
652
nsend " ping" (Pong us)
652
653
Ping pid' <- expect
653
654
True <- return $ pingServer == pid'
654
- Left (ProcessRegistrationException " dead" Nothing ) <- try $ register " dead" deadProcess
655
- Left (ProcessRegistrationException " ping" (Just x)) <- try $ register " ping" deadProcess
655
+ Left (ProcessRegistrationException " dead" Nothing ) <- Ex. try $ register " dead" deadProcess
656
+ Left (ProcessRegistrationException " ping" (Just x)) <- Ex. try $ register " ping" deadProcess
656
657
True <- return $ x == pingServer
657
- Left (ProcessRegistrationException " dead" Nothing ) <- try $ unregister " dead"
658
+ Left (ProcessRegistrationException " dead" Nothing ) <- Ex. try $ unregister " dead"
658
659
liftIO $ putMVar done ()
659
660
660
661
takeMVar done
@@ -777,7 +778,7 @@ testSpawnAsyncStrictness TestTransport{..} = do
777
778
runProcess node $ do
778
779
here <- getSelfNode
779
780
780
- ev <- try $ spawnAsync here (error " boom" )
781
+ ev <- Ex. try $ spawnAsync here (error " boom" )
781
782
liftIO $ case ev of
782
783
Right _ -> putMVar done (error " Exception didn't fire" )
783
784
Left (_:: SomeException ) -> putMVar done (return () )
@@ -868,7 +869,7 @@ testUSend usendPrim TestTransport{..} numMessages = do
868
869
processA <- newEmptyMVar
869
870
usendTestOk <- newEmptyMVar
870
871
871
- forkProcess node1 $ flip catch (\ e -> liftIO $ print (e :: SomeException ) ) $ do
872
+ forkProcess node1 $ flip Ex. catch (\ e -> liftIO $ print (e :: SomeException ) ) $ do
872
873
us <- getSelfPid
873
874
liftIO $ putMVar processA us
874
875
them <- expect
@@ -1277,7 +1278,7 @@ testMaskRestoreScope TestTransport{..} = do
1277
1278
parentPid <- newEmptyMVar :: IO (MVar ProcessId )
1278
1279
spawnedPid <- newEmptyMVar :: IO (MVar ProcessId )
1279
1280
1280
- void $ runProcess localNode $ mask $ \ unmask -> do
1281
+ void $ runProcess localNode $ Ex. mask $ \ unmask -> do
1281
1282
getSelfPid >>= liftIO . putMVar parentPid
1282
1283
void $ spawnLocal $ unmask (getSelfPid >>= liftIO . putMVar spawnedPid)
1283
1284
@@ -1306,7 +1307,7 @@ testPrettyExit TestTransport{..} = do
1306
1307
1307
1308
_ <- forkProcess localNode $ do
1308
1309
(die " timeout" )
1309
- `catch` \ ex@ (ProcessExitException from _) ->
1310
+ `Ex. catch` \ ex@ (ProcessExitException from _) ->
1310
1311
let expected = " exit-from=" ++ (show from)
1311
1312
in do
1312
1313
True <- return $ (show ex) == expected
@@ -1480,11 +1481,11 @@ testCallLocal TestTransport{..} = do
1480
1481
spawnLocal $ do
1481
1482
caller <- getSelfPid
1482
1483
send keeper caller
1483
- onException
1484
+ Ex. onException
1484
1485
(callLocal $ do
1485
- onException (do send keeper caller
1486
- expect)
1487
- (do liftIO $ writeIORef ibox True ))
1486
+ Ex. onException (do send keeper caller
1487
+ expect)
1488
+ (do liftIO $ writeIORef ibox True ))
1488
1489
(send keeper () )
1489
1490
caller <- expect
1490
1491
exit caller " test"
@@ -1496,7 +1497,7 @@ testCallLocal TestTransport{..} = do
1496
1497
-- Testing that when the worker raises an exception, the exception is propagated to the parent.
1497
1498
ibox2 <- newIORef False
1498
1499
runProcess node $ do
1499
- r <- try (callLocal $ error " e" >> return () )
1500
+ r <- Ex. try (callLocal $ error " e" >> return () )
1500
1501
liftIO $ writeIORef ibox2 $ case r of
1501
1502
Left (ErrorCall " e" ) -> True
1502
1503
_ -> False
@@ -1514,7 +1515,7 @@ testCallLocal TestTransport{..} = do
1514
1515
send keeper us
1515
1516
() <- expect
1516
1517
liftIO yield)
1517
- `finally` (liftIO $ writeIORef ibox3 True )
1518
+ `Ex. finally` (liftIO $ writeIORef ibox3 True )
1518
1519
liftIO $ putMVar result3 =<< readIORef ibox3
1519
1520
worker <- expect
1520
1521
send worker ()
@@ -1531,8 +1532,8 @@ testCallLocal TestTransport{..} = do
1531
1532
callLocal
1532
1533
((do send keeper caller
1533
1534
expect)
1534
- `finally` (liftIO $ writeIORef ibox4 True ))
1535
- `finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
1535
+ `Ex. finally` (liftIO $ writeIORef ibox4 True ))
1536
+ `Ex. finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
1536
1537
caller <- expect
1537
1538
exit caller " hi!"
1538
1539
True <- takeMVar result4
0 commit comments