Skip to content

Commit 9ecdd20

Browse files
committed
Fix tests.
According to semantics network failures is guaranteed to be noticed by network-transport iff communication happened after connection failure. Tests were adjusted to appreciate such semantics.
1 parent f8c6977 commit 9ecdd20

File tree

1 file changed

+13
-1
lines changed
  • src/Control/Distributed/Process/Tests

1 file changed

+13
-1
lines changed

src/Control/Distributed/Process/Tests/CH.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,25 @@ testMonitorRemoteDeadProcess TestTransport{..} mOrL un = do
302302
testMonitorDisconnect :: TestTransport -> Bool -> Bool -> Assertion
303303
testMonitorDisconnect TestTransport{..} mOrL un = do
304304
processAddr <- newEmptyMVar
305+
processAddr2 <- newEmptyMVar
305306
monitorSetup <- newEmptyMVar
306307
done <- newEmptyMVar
307308

308309
forkIO $ do
309310
localNode <- newLocalNode testTransport initRemoteTable
310311
addr <- forkProcess localNode . liftIO $ threadDelay 1000000
312+
addr2 <- forkProcess localNode $ return ()
311313
putMVar processAddr addr
312314
readMVar monitorSetup
313315
NT.closeEndPoint (localEndPoint localNode)
316+
putMVar processAddr2 addr2
314317

315318
forkIO $ do
316319
localNode <- newLocalNode testTransport initRemoteTable
317320
theirAddr <- readMVar processAddr
321+
forkProcess localNode $ do
322+
lc <- liftIO $ readMVar processAddr2
323+
send lc ()
318324
runProcess localNode $ do
319325
monitorTestProcess theirAddr mOrL un DiedDisconnect (Just monitorSetup) done
320326

@@ -583,17 +589,22 @@ testMonitorLiveNode :: TestTransport -> Assertion
583589
testMonitorLiveNode TestTransport{..} = do
584590
[node1, node2] <- replicateM 2 $ newLocalNode testTransport initRemoteTable
585591
ready <- newEmptyMVar
592+
readyr <- newEmptyMVar
586593
done <- newEmptyMVar
587594

595+
p <- forkProcess node1 $ return ()
588596
forkProcess node2 $ do
589597
ref <- monitorNode (localNodeId node1)
590598
liftIO $ putMVar ready ()
599+
liftIO $ takeMVar readyr
600+
send p ()
591601
NodeMonitorNotification ref' nid _ <- expect
592602
True <- return $ ref == ref' && nid == localNodeId node1
593603
liftIO $ putMVar done ()
594604

595605
takeMVar ready
596606
closeLocalNode node1
607+
putMVar readyr ()
597608

598609
takeMVar done
599610

@@ -734,7 +745,8 @@ testReconnect TestTransport{..} = do
734745

735746

736747
-- Simulate network failure
737-
liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
748+
liftIO $ do testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
749+
threadDelay 1000000
738750

739751
-- This will happen due to implicit reconnect
740752
registerRemoteAsync nid1 "b" us

0 commit comments

Comments
 (0)