@@ -21,7 +21,7 @@ import Control.Monad (replicateM_, replicateM, forever, void, unless)
21
21
import Control.Exception (SomeException , throwIO )
22
22
import qualified Control.Exception as Ex (catch )
23
23
import Control.Applicative ((<$>) , (<*>) , pure , (<|>) )
24
- import qualified Network.Transport as NT (closeEndPoint )
24
+ import qualified Network.Transport as NT (closeEndPoint , EndPointAddress )
25
25
import Control.Distributed.Process
26
26
import Control.Distributed.Process.Internal.Types
27
27
( NodeId (nodeAddress )
@@ -302,19 +302,25 @@ testMonitorRemoteDeadProcess TestTransport{..} mOrL un = do
302
302
testMonitorDisconnect :: TestTransport -> Bool -> Bool -> Assertion
303
303
testMonitorDisconnect TestTransport {.. } mOrL un = do
304
304
processAddr <- newEmptyMVar
305
+ processAddr2 <- newEmptyMVar
305
306
monitorSetup <- newEmptyMVar
306
307
done <- newEmptyMVar
307
308
308
309
forkIO $ do
309
310
localNode <- newLocalNode testTransport initRemoteTable
310
- addr <- forkProcess localNode . liftIO $ threadDelay 1000000
311
+ addr <- forkProcess localNode $ expect
312
+ addr2 <- forkProcess localNode $ return ()
311
313
putMVar processAddr addr
312
314
readMVar monitorSetup
313
315
NT. closeEndPoint (localEndPoint localNode)
316
+ putMVar processAddr2 addr2
314
317
315
318
forkIO $ do
316
319
localNode <- newLocalNode testTransport initRemoteTable
317
320
theirAddr <- readMVar processAddr
321
+ forkProcess localNode $ do
322
+ lc <- liftIO $ readMVar processAddr2
323
+ send lc ()
318
324
runProcess localNode $ do
319
325
monitorTestProcess theirAddr mOrL un DiedDisconnect (Just monitorSetup) done
320
326
@@ -583,17 +589,22 @@ testMonitorLiveNode :: TestTransport -> Assertion
583
589
testMonitorLiveNode TestTransport {.. } = do
584
590
[node1, node2] <- replicateM 2 $ newLocalNode testTransport initRemoteTable
585
591
ready <- newEmptyMVar
592
+ readyr <- newEmptyMVar
586
593
done <- newEmptyMVar
587
594
595
+ p <- forkProcess node1 $ return ()
588
596
forkProcess node2 $ do
589
597
ref <- monitorNode (localNodeId node1)
590
598
liftIO $ putMVar ready ()
599
+ liftIO $ takeMVar readyr
600
+ send p ()
591
601
NodeMonitorNotification ref' nid _ <- expect
592
602
True <- return $ ref == ref' && nid == localNodeId node1
593
603
liftIO $ putMVar done ()
594
604
595
605
takeMVar ready
596
606
closeLocalNode node1
607
+ putMVar readyr ()
597
608
598
609
takeMVar done
599
610
@@ -688,7 +699,6 @@ testReconnect :: TestTransport -> Assertion
688
699
testReconnect TestTransport {.. } = do
689
700
[node1, node2] <- replicateM 2 $ newLocalNode testTransport initRemoteTable
690
701
let nid1 = localNodeId node1
691
- nid2 = localNodeId node2
692
702
processA <- newEmptyMVar
693
703
[sendTestOk, registerTestOk] <- replicateM 2 newEmptyMVar
694
704
@@ -709,7 +719,8 @@ testReconnect TestTransport{..} = do
709
719
send them " message 1" >> liftIO (threadDelay 100000 )
710
720
711
721
-- Simulate network failure
712
- liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
722
+ liftIO $ syncBreakConnection testBreakConnection node1 node2
723
+
713
724
714
725
-- Should not arrive
715
726
send them " message 2"
@@ -734,7 +745,7 @@ testReconnect TestTransport{..} = do
734
745
735
746
736
747
-- Simulate network failure
737
- liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
748
+ liftIO $ syncBreakConnection testBreakConnection node1 node2
738
749
739
750
-- This will happen due to implicit reconnect
740
751
registerRemoteAsync nid1 " b" us
@@ -1320,7 +1331,7 @@ testUnsafeSendChan TestTransport{..} = do
1320
1331
1321
1332
tests :: TestTransport -> IO [Test ]
1322
1333
tests testtrans = return [
1323
- testGroup " Basic features" [
1334
+ testGroup " Basic features" [
1324
1335
testCase " Ping" (testPing testtrans)
1325
1336
, testCase " Math" (testMath testtrans)
1326
1337
, testCase " Timeout" (testTimeout testtrans)
@@ -1356,7 +1367,7 @@ tests testtrans = return [
1356
1367
-- usend
1357
1368
, testCase " USend" (testUSend testtrans 50 )
1358
1369
]
1359
- , testGroup " Monitoring and Linking" [
1370
+ , testGroup " Monitoring and Linking" [
1360
1371
-- Monitoring processes
1361
1372
--
1362
1373
-- The "missing" combinations in the list below don't make much sense, as
@@ -1388,3 +1399,17 @@ tests testtrans = return [
1388
1399
, testCase " Reconnect" (testReconnect testtrans)
1389
1400
]
1390
1401
]
1402
+
1403
+ syncBreakConnection :: (NT. EndPointAddress -> NT. EndPointAddress -> IO () ) -> LocalNode -> LocalNode -> IO ()
1404
+ syncBreakConnection breakConnection nid0 nid1 = do
1405
+ m <- newEmptyMVar
1406
+ _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
1407
+ runProcess nid0 $ do
1408
+ them <- liftIO $ takeMVar m
1409
+ pinger <- spawnLocal $ forever $ send them ()
1410
+ _ <- monitorNode (localNodeId nid1)
1411
+ liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
1412
+ (nodeAddress $ localNodeId nid1)
1413
+ NodeMonitorNotification _ _ _ <- expect
1414
+ kill pinger " finished"
1415
+ return ()
0 commit comments