@@ -365,9 +365,13 @@ testSendToTerminated transport = do
365testTimeout :: NT.Transport -> Assertion
365testTimeout :: NT.Transport -> Assertion
366testTimeout transport = do
366testTimeout transport = do
367 localNode <- newLocalNode transport initRemoteTable
367 localNode <- newLocalNode transport initRemoteTable
368+ done <- newEmptyMVar
368 runProcess localNode $ do
370 runProcess localNode $ do
369 Nothing <- receiveTimeout 1000000 [match (\(Add _ _ _) -> return ())]
371 Nothing <- receiveTimeout 1000000 [match (\(Add _ _ _) -> return ())]
370− return ()
372+ liftIO $ putMVar done ()
372-- | Test zero timeout
376-- | Test zero timeout
373testTimeout0 :: NT.Transport -> Assertion
377testTimeout0 :: NT.Transport -> Assertion
@@ -526,6 +530,7 @@ testMergeChannels transport = do
526testTerminate :: NT.Transport -> Assertion
530testTerminate :: NT.Transport -> Assertion
527testTerminate transport = do
531testTerminate transport = do
528 localNode <- newLocalNode transport initRemoteTable
532 localNode <- newLocalNode transport initRemoteTable
533+ done <- newEmptyMVar
530 pid <- forkProcess localNode $ do
535 pid <- forkProcess localNode $ do
531 liftIO $ threadDelay 100000
536 liftIO $ threadDelay 100000
@@ -535,11 +540,14 @@ testTerminate transport = do
535 ref <- monitor pid
540 ref <- monitor pid
536 ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
541 ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
537 True <- return $ ref == ref' && pid == pid' && ex == show ProcessTerminationException
542 True <- return $ ref == ref' && pid == pid' && ex == show ProcessTerminationException
538− return ()
543+ liftIO $ putMVar done ()
540testMonitorNode :: NT.Transport -> Assertion
547testMonitorNode :: NT.Transport -> Assertion
541testMonitorNode transport = do
548testMonitorNode transport = do
542 [node1, node2] <- replicateM 2 $ newLocalNode transport initRemoteTable
549 [node1, node2] <- replicateM 2 $ newLocalNode transport initRemoteTable
550+ done <- newEmptyMVar
544 closeLocalNode node1
552 closeLocalNode node1
@@ -547,7 +555,9 @@ testMonitorNode transport = do
547 ref <- monitorNode (localNodeId node1)
555 ref <- monitorNode (localNodeId node1)
548 NodeMonitorNotification ref' nid DiedDisconnect <- expect
556 NodeMonitorNotification ref' nid DiedDisconnect <- expect
549 True <- return $ ref == ref' && nid == localNodeId node1
557 True <- return $ ref == ref' && nid == localNodeId node1
550− return ()
558+ liftIO $ putMVar done ()
552testMonitorChannel :: NT.Transport -> Assertion
562testMonitorChannel :: NT.Transport -> Assertion
553testMonitorChannel transport = do
563testMonitorChannel transport = do
@@ -573,6 +583,7 @@ testMonitorChannel transport = do
573testRegistry :: NT.Transport -> Assertion
583testRegistry :: NT.Transport -> Assertion
574testRegistry transport = do
584testRegistry transport = do
575 node <- newLocalNode transport initRemoteTable
585 node <- newLocalNode transport initRemoteTable
586+ done <- newEmptyMVar
577 pingServer <- forkProcess node ping
588 pingServer <- forkProcess node ping
@@ -584,12 +595,15 @@ testRegistry transport = do
584 nsend "ping" (Pong us)
595 nsend "ping" (Pong us)
585 Ping pid' <- expect
596 Ping pid' <- expect
586 True <- return $ pingServer == pid'
597 True <- return $ pingServer == pid'
587− return ()
598+ liftIO $ putMVar done ()
589testRemoteRegistry :: NT.Transport -> Assertion
602testRemoteRegistry :: NT.Transport -> Assertion
590testRemoteRegistry transport = do
603testRemoteRegistry transport = do
591 node1 <- newLocalNode transport initRemoteTable
604 node1 <- newLocalNode transport initRemoteTable
592 node2 <- newLocalNode transport initRemoteTable
605 node2 <- newLocalNode transport initRemoteTable
606+ done <- newEmptyMVar
594 pingServer <- forkProcess node1 ping
608 pingServer <- forkProcess node1 ping
@@ -606,11 +620,14 @@ testRemoteRegistry transport = do
606 nsendRemote nid1 "ping" (Pong us)
620 nsendRemote nid1 "ping" (Pong us)
607 Ping pid' <- expect
621 Ping pid' <- expect
608 True <- return $ pingServer == pid'
622 True <- return $ pingServer == pid'
609− return ()
623+ liftIO $ putMVar done ()
611testSpawnLocal :: NT.Transport -> Assertion
627testSpawnLocal :: NT.Transport -> Assertion
612testSpawnLocal transport = do
628testSpawnLocal transport = do
613 node <- newLocalNode transport initRemoteTable
629 node <- newLocalNode transport initRemoteTable
630+ done <- newEmptyMVar
615 runProcess node $ do
632 runProcess node $ do
616 us <- getSelfPid
633 us <- getSelfPid
@@ -624,7 +641,10 @@ testSpawnLocal transport = do
624 send us ()
641 send us ()
626 send pid sport
643 send pid sport
627− expect
644+ () <- expect
645+ liftIO $ putMVar done ()
629testReconnect :: NT.Transport -> TransportInternals -> Assertion
649testReconnect :: NT.Transport -> TransportInternals -> Assertion
630testReconnect transport transportInternals = do
650testReconnect transport transportInternals = do
@@ -841,66 +861,87 @@ testReceiveChanFeatures transport = do
841testKillLocal :: NT.Transport -> Assertion
861testKillLocal :: NT.Transport -> Assertion
842testKillLocal transport = do
862testKillLocal transport = do
843 localNode <- newLocalNode transport initRemoteTable
863 localNode <- newLocalNode transport initRemoteTable
864+ done <- newEmptyMVar
845 pid <- forkProcess localNode $ do
866 pid <- forkProcess localNode $ do
846− liftIO $ threadDelay 100000
867+ liftIO $ threadDelay 1000000
848 runProcess localNode $ do
869 runProcess localNode $ do
849 ref <- monitor pid
870 ref <- monitor pid
850 kill pid "TestKill"
872 kill pid "TestKill"
851 ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
873 ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
852− True <- return $ ref == ref' && pid == pid' && ex == "TestKill"
874+ True <- return $ ref == ref' && pid == pid' && ex == "Kill by " ++ show us ++ ": TestKill"
853− return ()
875+ liftIO $ putMVar done ()
855testKillRemote :: NT.Transport -> Assertion
879testKillRemote :: NT.Transport -> Assertion
856testKillRemote transport = do
880testKillRemote transport = do
857 node1 <- newLocalNode transport initRemoteTable
881 node1 <- newLocalNode transport initRemoteTable
858 node2 <- newLocalNode transport initRemoteTable
882 node2 <- newLocalNode transport initRemoteTable
883+ done <- newEmptyMVar
860 pid <- forkProcess node1 $ do
885 pid <- forkProcess node1 $ do
861− liftIO $ threadDelay 100000
886+ liftIO $ threadDelay 1000000
863 runProcess node2 $ do
888 runProcess node2 $ do
864 ref <- monitor pid
889 ref <- monitor pid
865 kill pid "TestKill"
891 kill pid "TestKill"
866− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
892+ ProcessMonitorNotification ref' pid' (DiedException reason) <- expect
867− True <- return $ ref == ref' && pid == pid' && ex == "TestKill"
893+ True <- return $ ref == ref' && pid == pid' && reason == "Kill by " ++ show us ++ ": TestKill"
868− return ()
894+ liftIO $ putMVar done ()
870testExitLocal :: NT.Transport -> Assertion
898testExitLocal :: NT.Transport -> Assertion
871testExitLocal transport = do
899testExitLocal transport = do
872 localNode <- newLocalNode transport initRemoteTable
900 localNode <- newLocalNode transport initRemoteTable
901+ supervisedDone <- newEmptyMVar
902+ supervisorDone <- newEmptyMVar
874 pid <- forkProcess localNode $ do
904 pid <- forkProcess localNode $ do
875 (liftIO $ threadDelay 100000)
905 (liftIO $ threadDelay 100000)
876− `catchExit` \from reason -> do
906+ `catchExit` \_from reason -> do
877− say $ "Got " ++ reason ++ " from " ++ show from
907+ -- TODO: should verify that 'from' has the right value
878− return ()
908+ True <- return $ reason == "TestExit"
909+ liftIO $ putMVar supervisedDone ()
880 runProcess localNode $ do
911 runProcess localNode $ do
881 ref <- monitor pid
912 ref <- monitor pid
882 exit pid "TestExit"
913 exit pid "TestExit"
914+ -- This time the client catches the exception, so it dies normally
883− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
915+ ProcessMonitorNotification ref' pid' DiedNormal <- expect
884− True <- return $ ref == ref' && pid == pid' && ex == "TestExit"
916+ True <- return $ ref == ref' && pid == pid'
885− return ()
917+ liftIO $ putMVar supervisorDone ()
919+ takeMVar supervisedDone
920+ takeMVar supervisorDone
887testExitRemote :: NT.Transport -> Assertion
922testExitRemote :: NT.Transport -> Assertion
888testExitRemote transport = do
923testExitRemote transport = do
889 node1 <- newLocalNode transport initRemoteTable
924 node1 <- newLocalNode transport initRemoteTable
890 node2 <- newLocalNode transport initRemoteTable
925 node2 <- newLocalNode transport initRemoteTable
926+ supervisedDone <- newEmptyMVar
927+ supervisorDone <- newEmptyMVar
892 pid <- forkProcess node1 $ do
929 pid <- forkProcess node1 $ do
893 (liftIO $ threadDelay 100000)
930 (liftIO $ threadDelay 100000)
894− `catchExit` \from reason -> do
931+ `catchExit` \_from reason -> do
895− say $ "Got " ++ reason ++ " from " ++ show from
932+ -- TODO: should verify that 'from' has the right value
896− return ()
933+ True <- return $ reason == "TestExit"
934+ liftIO $ putMVar supervisedDone ()
898 runProcess node2 $ do
936 runProcess node2 $ do
899 ref <- monitor pid
937 ref <- monitor pid
900 exit pid "TestExit"
938 exit pid "TestExit"
901− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
939+ ProcessMonitorNotification ref' pid' DiedNormal <- expect
902− True <- return $ ref == ref' && pid == pid' && ex == "TestExit"
940+ True <- return $ ref == ref' && pid == pid'
903− return ()
941+ liftIO $ putMVar supervisorDone ()
943+ takeMVar supervisedDone
944+ takeMVar supervisorDone
905tests :: (NT.Transport, TransportInternals) -> [Test]
946tests :: (NT.Transport, TransportInternals) -> [Test]
906tests (transport, transportInternals) = [
947tests (transport, transportInternals) = [