@@ -42,9 +42,12 @@ import Control.Distributed.Process.Internal.Types
42 , createUnencodedMessage
42 , createUnencodedMessage
44import Control.Distributed.Process.Node
44import Control.Distributed.Process.Node
45+import Control.Distributed.Process.Debug
46+import Control.Distributed.Process.Management.Internal.Types
47+import Control.Distributed.Process.Tests.Internal.Utils (shouldBe)
45import Control.Distributed.Process.Serializable (Serializable)
48import Control.Distributed.Process.Serializable (Serializable)
47−import Test.HUnit (Assertion, assertFailure)
50+import Test.HUnit (Assertion, assertBool, assertFailure)
48import Test.Framework (Test, testGroup)
51import Test.Framework (Test, testGroup)
49import Test.Framework.Providers.HUnit (testCase)
52import Test.Framework.Providers.HUnit (testCase)
50import Control.Rematch hiding (match)
53import Control.Rematch hiding (match)
@@ -80,12 +83,47 @@ ping = do
80 send partner (Ping self)
83 send partner (Ping self)
86+verifyClient :: String -> MVar Bool -> IO ()
87+verifyClient s b = takeMVar b >>= assertBool s
89+expectPing :: MVar Bool -> Process ()
90+expectPing mv = expect >>= liftIO . putMVar mv . checkPing
92+ checkPing (Ping _) = True
83-- | Quick and dirty synchronous version of whereisRemoteAsync
95-- | Quick and dirty synchronous version of whereisRemoteAsync
84whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
96whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
85whereisRemote nid string = do
97whereisRemote nid string = do
86 whereisRemoteAsync nid string
98 whereisRemoteAsync nid string
87− WhereIsReply _ mPid <- expect
100+ match (\(WhereIsReply _ mPid) -> return mPid)
103+verifyWhereIsRemote :: NodeId -> String -> Process ProcessId
104+verifyWhereIsRemote n s = whereisRemote n s >>= maybe (die "remote name not found") return
106+waitForExit :: ProcessId -> Process DiedReason
107+waitForExit pid = monitor pid >>= waitForDown
109+waitForDown :: MonitorRef -> Process DiedReason
111+ receiveWait [ matchIf (\(ProcessMonitorNotification ref' _ _) -> ref == ref')
112+ (\(ProcessMonitorNotification _ _ dr) -> return dr) ]
114+syncBreakConnection :: (NT.EndPointAddress -> NT.EndPointAddress -> IO ()) -> LocalNode -> LocalNode -> IO ()
115+syncBreakConnection breakConnection nid0 nid1 = do
117+ _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
118+ runProcess nid0 $ do
119+ them <- liftIO $ takeMVar m
120+ pinger <- spawnLocal $ forever $ send them ()
121+ _ <- monitorNode (localNodeId nid1)
122+ liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
123+ (nodeAddress $ localNodeId nid1)
124+ NodeMonitorNotification _ _ _ <- expect
125+ kill pinger "finished"
88− return mPid
126+ return ()
90data Add = Add ProcessId Double Double deriving (Typeable)
128data Add = Add ProcessId Double Double deriving (Typeable)
91data Divide = Divide ProcessId Double Double deriving (Typeable)
129data Divide = Divide ProcessId Double Double deriving (Typeable)
@@ -160,12 +198,18 @@ monitorTestProcess theirAddr mOrL un reason monitorSetup done =
160 unmonitor ref
198 unmonitor ref
161 liftIO $ putMVar done ()
199 liftIO $ putMVar done ()
162 (False, ref) -> do
200 (False, ref) -> do
163− ProcessMonitorNotification ref' pid reason' <- expect
202+ match (\(ProcessMonitorNotification ref' pid reason') -> do
204+ assertBool "Bad Monitor Signal"
164− True <- return $ Just ref' == ref && pid == theirAddr && mOrL && reason == reason'
205+ (Just ref' == ref && pid == theirAddr &&
206+ mOrL && reason == reason')
165− liftIO $ putMVar done ()
207+ putMVar done ())
167 (\(ProcessLinkException pid reason') -> do
210 (\(ProcessLinkException pid reason') -> do
211+ (liftIO $ assertBool "link exception unmatched" $
168− True <- return $ pid == theirAddr && not mOrL && not un && reason == reason'
212+ pid == theirAddr && not mOrL && not un && reason == reason')
169 liftIO $ putMVar done ()
213 liftIO $ putMVar done ()
@@ -196,8 +240,10 @@ testPing TestTransport{..} = do
196 pid <- getSelfPid
240 pid <- getSelfPid
197 replicateM_ numPings $ do
241 replicateM_ numPings $ do
198 send pingServer (Pong pid)
242 send pingServer (Pong pid)
199− Ping _ <- expect
243+ p <- expect
200− return ()
245+ Ping _ -> return ()
246+ _ -> die "Unexpected message"
202 putMVar clientDone ()
248 putMVar clientDone ()
@@ -284,7 +330,7 @@ testMonitorLocalDeadProcess TestTransport{..} mOrL un = do
284 runProcess localNode $ do
330 runProcess localNode $ do
285 monitor theirAddr
331 monitor theirAddr
286 -- wait for the process to die
332 -- wait for the process to die
287− ProcessMonitorNotification _ _ _ <- expect
333+ expect :: Process ProcessMonitorNotification
288 monitorTestProcess theirAddr mOrL un DiedUnknownId Nothing done
334 monitorTestProcess theirAddr mOrL un DiedUnknownId Nothing done
290 takeMVar done
336 takeMVar done
@@ -358,14 +404,17 @@ testMath TestTransport{..} = do
358 runProcess localNode $ do
404 runProcess localNode $ do
359 pid <- getSelfPid
405 pid <- getSelfPid
360 send mathServer (Add pid 1 2)
406 send mathServer (Add pid 1 2)
361− 3 <- expect :: Process Double
407+ three <- expect :: Process Double
362 send mathServer (Divide pid 8 2)
408 send mathServer (Divide pid 8 2)
363− 4 <- expect :: Process Double
409+ four <- expect :: Process Double
364 send mathServer (Divide pid 8 0)
410 send mathServer (Divide pid 8 0)
365− DivByZero <- expect
411+ divByZ <- expect
366− liftIO $ putMVar clientDone ()
412+ liftIO $ putMVar clientDone (three, four, divByZ)
368− takeMVar clientDone
414+ res <- takeMVar clientDone
416+ (3, 4, DivByZero) -> return ()
417+ _ -> error $ "Something went horribly wrong"
370-- | Send first message (i.e. connect) to an already terminated process
419-- | Send first message (i.e. connect) to an already terminated process
371-- (without monitoring); then send another message to a second process on
420-- (without monitoring); then send another message to a second process on
@@ -393,11 +442,9 @@ testSendToTerminated TestTransport{..} = do
393 pid <- getSelfPid
442 pid <- getSelfPid
394 send server1 "Hi"
443 send server1 "Hi"
395 send server2 (Pong pid)
444 send server2 (Pong pid)
397− True <- return $ pid' == server2
398− liftIO $ putMVar clientDone ()
445+ expectPing clientDone
400− takeMVar clientDone
447+ verifyClient "Expected Ping from server" clientDone
402-- | Test (non-zero) timeout
449-- | Test (non-zero) timeout
403testTimeout :: TestTransport -> Assertion
450testTimeout :: TestTransport -> Assertion
@@ -406,10 +453,10 @@ testTimeout TestTransport{..} = do
406 done <- newEmptyMVar
453 done <- newEmptyMVar
408 runProcess localNode $ do
455 runProcess localNode $ do
409− Nothing <- receiveTimeout 1000000 [match (\(Add _ _ _) -> return ())]
456+ res <- receiveTimeout 1000000 [match (\Add{} -> return ())]
410− liftIO $ putMVar done ()
457+ liftIO $ putMVar done $ res == Nothing
412− takeMVar done
459+ verifyClient "Expected receiveTimeout to timeout..." done
414-- | Test zero timeout
461-- | Test zero timeout
415testTimeout0 :: TestTransport -> Assertion
462testTimeout0 :: TestTransport -> Assertion
@@ -437,10 +484,9 @@ testTimeout0 TestTransport{..} = do
437 -- is not interested in, and then a single message that it wants
484 -- is not interested in, and then a single message that it wants
438 replicateM_ 10000 $ send server "Irrelevant message"
485 replicateM_ 10000 $ send server "Irrelevant message"
439 send server (Pong pid)
486 send server (Pong pid)
441− liftIO $ putMVar clientDone ()
487+ expectPing clientDone
443− takeMVar clientDone
489+ verifyClient "Expected Ping from server" clientDone
445-- | Test typed channels
491-- | Test typed channels
446testTypedChannels :: TestTransport -> Assertion
492testTypedChannels :: TestTransport -> Assertion
@@ -463,10 +509,10 @@ testTypedChannels TestTransport{..} = do
463 runProcess localNode $ do
509 runProcess localNode $ do
464 (clientSendPort, rport) <- newChan
510 (clientSendPort, rport) <- newChan
465 sendChan serverSendPort (clientSendPort, 5)
511 sendChan serverSendPort (clientSendPort, 5)
466− False <- receiveChan rport
512+ ch <- receiveChan rport
467− liftIO $ putMVar clientDone ()
513+ liftIO $ putMVar clientDone $ ch == False
469− takeMVar clientDone
515+ verifyClient "Expected channel to send 'False'" clientDone
471-- | Test merging receive ports
517-- | Test merging receive ports
472testMergeChannels :: TestTransport -> Assertion
518testMergeChannels :: TestTransport -> Assertion
@@ -489,9 +535,8 @@ testMergeChannels TestTransport{..} = do
489 rs <- mapM charChannel "abc"
535 rs <- mapM charChannel "abc"
490 m <- mergePorts biased rs
536 m <- mergePorts biased rs
491 xs <- replicateM 9 $ receiveChan m
537 xs <- replicateM 9 $ receiveChan m
492− True <- return $ xs == expected
493− liftIO $ putMVar done ()
538+ liftIO $ putMVar done $ xs == expected
494− takeMVar done
539+ verifyClient "Expected single layer merge to match expected ordering" done
496 -- Two layers of merging
541 -- Two layers of merging
497 testNested :: LocalNode -> Bool -> Bool -> String -> IO ()
542 testNested :: LocalNode -> Bool -> Bool -> String -> IO ()
@@ -502,9 +547,8 @@ testMergeChannels TestTransport{..} = do
502 ms <- mapM (mergePorts biasedInner) rss
547 ms <- mapM (mergePorts biasedInner) rss
503 m <- mergePorts biasedOuter ms
548 m <- mergePorts biasedOuter ms
504 xs <- replicateM (9 * 3) $ receiveChan m
549 xs <- replicateM (9 * 3) $ receiveChan m
505− True <- return $ xs == expected
550+ liftIO $ putMVar done $ xs == expected
506− liftIO $ putMVar done ()
551+ verifyClient "Expected nested channels to match expeted ordering" done
509 -- Test that if no messages are (immediately) available, the scheduler makes no difference
553 -- Test that if no messages are (immediately) available, the scheduler makes no difference
510 testBlocked :: LocalNode -> Bool -> IO ()
554 testBlocked :: LocalNode -> Bool -> IO ()
@@ -513,43 +557,45 @@ testMergeChannels TestTransport{..} = do
513 done <- newEmptyMVar
557 done <- newEmptyMVar
515 forkProcess localNode $ do
559 forkProcess localNode $ do
516− [sa, sb, sc] <- liftIO $ mapM readMVar vs
560+ ss <- liftIO $ mapM readMVar vs
517− mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
563+ mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
518− [ -- a, b, c
564+ [ -- a, b, c
519− (sa, 'a')
565+ (sa, 'a')
520− , (sb, 'b')
566+ , (sb, 'b')
521− , (sc, 'c')
567+ , (sc, 'c')
522− -- a, c, b
568+ -- a, c, b
523− , (sa, 'a')
569+ , (sa, 'a')
524− , (sc, 'c')
570+ , (sc, 'c')
525− , (sb, 'b')
571+ , (sb, 'b')
526− -- b, a, c
572+ -- b, a, c
527− , (sb, 'b')
573+ , (sb, 'b')
528− , (sa, 'a')
574+ , (sa, 'a')
529− , (sc, 'c')
575+ , (sc, 'c')
530− -- b, c, a
576+ -- b, c, a
531− , (sb, 'b')
577+ , (sb, 'b')
532− , (sc, 'c')
578+ , (sc, 'c')
533− , (sa, 'a')
579+ , (sa, 'a')
534− -- c, a, b
580+ -- c, a, b
535− , (sc, 'c')
581+ , (sc, 'c')
536− , (sa, 'a')
582+ , (sa, 'a')
537− , (sb, 'b')
583+ , (sb, 'b')
538− -- c, b, a
584+ -- c, b, a
539− , (sc, 'c')
585+ , (sc, 'c')
540− , (sb, 'b')
586+ , (sb, 'b')
541− , (sa, 'a')
587+ , (sa, 'a')
589+ _ -> die "Something went horribly wrong"
544 forkProcess localNode $ do
591 forkProcess localNode $ do
545 (ss, rs) <- unzip <$> replicateM 3 newChan
592 (ss, rs) <- unzip <$> replicateM 3 newChan
546 liftIO $ mapM_ (uncurry putMVar) $ zip vs ss
593 liftIO $ mapM_ (uncurry putMVar) $ zip vs ss
547 m <- mergePorts biased rs
594 m <- mergePorts biased rs
548 xs <- replicateM (6 * 3) $ receiveChan m
595 xs <- replicateM (6 * 3) $ receiveChan m
549− True <- return $ xs == "abcacbbacbcacabcba"
550− liftIO $ putMVar done ()
596+ liftIO $ putMVar done $ xs == "abcacbbacbcacabcba"
552− takeMVar done
598+ verifyClient "Expected merged ports to match expected ordering" done
554 mergePorts :: Serializable a => Bool -> [ReceivePort a] -> Process (ReceivePort a)
600 mergePorts :: Serializable a => Bool -> [ReceivePort a] -> Process (ReceivePort a)
555 mergePorts True = mergePortsBiased
601 mergePorts True = mergePortsBiased
@@ -567,8 +613,9 @@ testTerminate TestTransport{..} = do
567 localNode <- newLocalNode testTransport initRemoteTable
613 localNode <- newLocalNode testTransport initRemoteTable
568 runProcess localNode $ do
614 runProcess localNode $ do
569 e <- try terminate :: Process (Either ProcessTerminationException ())
615 e <- try terminate :: Process (Either ProcessTerminationException ())
570− True <- return $ either show show e == show ProcessTerminationException
616+ if either show show e == show ProcessTerminationException
571− return ()
617+ then return ()
618+ else die "Unexpected result from terminate"
573testMonitorNode :: TestTransport -> Assertion
620testMonitorNode :: TestTransport -> Assertion
574testMonitorNode TestTransport{..} = do
621testMonitorNode TestTransport{..} = do
@@ -579,11 +626,12 @@ testMonitorNode TestTransport{..} = do
580 runProcess node2 $ do
627 runProcess node2 $ do
581 ref <- monitorNode (localNodeId node1)
628 ref <- monitorNode (localNodeId node1)
582− NodeMonitorNotification ref' nid DiedDisconnect <- expect
630+ match (\(NodeMonitorNotification ref' nid DiedDisconnect) ->
583− True <- return $ ref == ref' && nid == localNodeId node1
631+ return $ ref == ref' && nid == localNodeId node1)
584− liftIO $ putMVar done ()
632+ ] >>= liftIO . putMVar done
586− takeMVar done
634+ verifyClient "Expected NodeMonitorNotification with matching ref & nodeId" done
588testMonitorLiveNode :: TestTransport -> Assertion
636testMonitorLiveNode :: TestTransport -> Assertion
589testMonitorLiveNode TestTransport{..} = do
637testMonitorLiveNode TestTransport{..} = do
@@ -598,15 +646,16 @@ testMonitorLiveNode TestTransport{..} = do
598 liftIO $ putMVar ready ()
646 liftIO $ putMVar ready ()
599 liftIO $ takeMVar readyr
647 liftIO $ takeMVar readyr
600 send p ()
648 send p ()
601− NodeMonitorNotification ref' nid _ <- expect
650+ match (\(NodeMonitorNotification ref' nid _) ->
602− True <- return $ ref == ref' && nid == localNodeId node1
651+ (return $ ref == ref' && nid == localNodeId node1))
603− liftIO $ putMVar done ()
652+ ] >>= liftIO . putMVar done
605 takeMVar ready
654 takeMVar ready
606 closeLocalNode node1
655 closeLocalNode node1
607 putMVar readyr ()
656 putMVar readyr ()
609− takeMVar done
658+ verifyClient "Expected NodeMonitorNotification for LIVE node" done
611testMonitorChannel :: TestTransport -> Assertion
660testMonitorChannel :: TestTransport -> Assertion
612testMonitorChannel TestTransport{..} = do
661testMonitorChannel TestTransport{..} = do
@@ -616,18 +665,20 @@ testMonitorChannel TestTransport{..} = do
616 pid <- forkProcess node1 $ do
665 pid <- forkProcess node1 $ do
617 sport <- expect :: Process (SendPort ())
666 sport <- expect :: Process (SendPort ())
618 ref <- monitorPort sport
667 ref <- monitorPort sport
619− PortMonitorNotification ref' port' reason <- expect
668+ receiveWait [
620− -- reason might be DiedUnknownId if the receive port is GCed before the
669+ -- reason might be DiedUnknownId if the receive port is GCed before the
621− -- monitor is established (TODO: not sure that this is reasonable)
670+ -- monitor is established (TODO: not sure that this is reasonable)
671+ match (\(PortMonitorNotification ref' port' reason) ->
672+ return $ ref' == ref && port' == sendPortId sport &&
622− return $ ref' == ref && port' == sendPortId sport && (reason == DiedNormal || reason == DiedUnknownId)
673+ (reason == DiedNormal || reason == DiedUnknownId))
623− liftIO $ putMVar gotNotification ()
674+ ] >>= liftIO . putMVar gotNotification
625 runProcess node2 $ do
676 runProcess node2 $ do
626 (sport, _) <- newChan :: Process (SendPort (), ReceivePort ())
677 (sport, _) <- newChan :: Process (SendPort (), ReceivePort ())
627 send pid sport
678 send pid sport
628 liftIO $ threadDelay 100000
679 liftIO $ threadDelay 100000
630− takeMVar gotNotification
681+ verifyClient "Expected PortMonitorNotification" gotNotification
632testRegistry :: TestTransport -> Assertion
683testRegistry :: TestTransport -> Assertion
633testRegistry TestTransport{..} = do
684testRegistry TestTransport{..} = do
@@ -639,20 +690,28 @@ testRegistry TestTransport{..} = do
640 runProcess node $ do
691 runProcess node $ do
641 register "ping" pingServer
692 register "ping" pingServer
642− Just pid <- whereis "ping"
693+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
643− True <- return $ pingServer == pid
644 us <- getSelfPid
694 us <- getSelfPid
645 nsend "ping" (Pong us)
695 nsend "ping" (Pong us)
646− Ping pid' <- expect
696+ receiveWait [
647− True <- return $ pingServer == pid'
697+ matchIf (\(Ping pid') -> pingServer == pid') (const $ return ())
648− Left (ProcessRegistrationException "dead" Nothing) <- try $ register "dead" deadProcess
698+ ]
649− Left (ProcessRegistrationException "ping" (Just x)) <- try $ register "ping" deadProcess
699+ checkRegException "dead" Nothing deadProcess
650− True <- return $ x == pingServer
700+ checkRegException "ping" (Just pingServer) deadProcess
651− Left (ProcessRegistrationException "dead" Nothing) <- try $ unregister "dead"
701+ try (unregister "dead") >>= checkReg "dead" Nothing
652 liftIO $ putMVar done ()
702 liftIO $ putMVar done ()
654 takeMVar done
704 takeMVar done
707+ checkRegException name pid dead =
708+ try (register name dead) >>= checkReg name pid
710+ checkReg name pid res =
712+ Left (ProcessRegistrationException name pid) -> return ()
713+ _ -> die $ "Unexpected Registration" ++ show res
656testRegistryRemoteProcess :: TestTransport -> Assertion
715testRegistryRemoteProcess :: TestTransport -> Assertion
657testRegistryRemoteProcess TestTransport{..} = do
716testRegistryRemoteProcess TestTransport{..} = do
658 node1 <- newLocalNode testTransport initRemoteTable
717 node1 <- newLocalNode testTransport initRemoteTable
@@ -663,13 +722,13 @@ testRegistryRemoteProcess TestTransport{..} = do
664 runProcess node2 $ do
723 runProcess node2 $ do
665 register "ping" pingServer
724 register "ping" pingServer
666− Just pid <- whereis "ping"
725+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
667− True <- return $ pingServer == pid
668 us <- getSelfPid
726 us <- getSelfPid
669 nsend "ping" (Pong us)
727 nsend "ping" (Pong us)
670− Ping pid' <- expect
728+ receiveWait [
671− True <- return $ pingServer == pid'
729+ matchIf (\(Ping pid') -> pingServer == pid')
672− liftIO $ putMVar done ()
730+ (const $ liftIO $ putMVar done ())
674 takeMVar done
733 takeMVar done
@@ -690,12 +749,13 @@ testRemoteRegistry TestTransport{..} = do
690 "ping" == label' && pid == pingServer)
749 "ping" == label' && pid == pingServer)
691 (\(RegisterReply _ _ _) -> return ()) ]
750 (\(RegisterReply _ _ _) -> return ()) ]
693− Just pid <- whereisRemote nid1 "ping"
752+ pid <- verifyWhereIsRemote nid1 "ping"
694− True <- return $ pingServer == pid
753+ liftIO $ assertBool "Expected pindServer to match pid" $ pingServer == pid
695 us <- getSelfPid
754 us <- getSelfPid
696 nsendRemote nid1 "ping" (Pong us)
755 nsendRemote nid1 "ping" (Pong us)
697− Ping pid' <- expect
756+ receiveWait [
698− True <- return $ pingServer == pid'
757+ match (\(Ping pid') -> return $ pingServer == pid')
758+ ] >>= liftIO . assertBool "Expected Ping with ping server's ProcessId"
700 -- test that if process was not registered Nothing is returned
760 -- test that if process was not registered Nothing is returned
701 -- in owner field.
761 -- in owner field.
@@ -731,15 +791,15 @@ testRemoteRegistryRemoteProcess TestTransport{..} = do
731 receiveWait [
791 receiveWait [
732 matchIf (\(RegisterReply label' _ _) -> "ping" == label')
792 matchIf (\(RegisterReply label' _ _) -> "ping" == label')
733 (\(RegisterReply _ _ _) -> return ()) ]
793 (\(RegisterReply _ _ _) -> return ()) ]
734− Just pid <- whereisRemote nid1 "ping"
794+ pid <- verifyWhereIsRemote nid1 "ping"
735− True <- return $ pingServer == pid
795+ liftIO $ assertBool "Expected pingServer to match remote name" $ pingServer == pid
736 us <- getSelfPid
796 us <- getSelfPid
737 nsendRemote nid1 "ping" (Pong us)
797 nsendRemote nid1 "ping" (Pong us)
738− Ping pid' <- expect
798+ receiveWait [
739− True <- return $ pingServer == pid'
799+ match (\(Ping pid') -> return $ pingServer == pid')
740− liftIO $ putMVar done ()
800+ ] >>= liftIO . putMVar done
742− takeMVar done
802+ verifyClient "Expected Ping with ping server's ProcessId" done
744testSpawnLocal :: TestTransport -> Assertion
804testSpawnLocal :: TestTransport -> Assertion
745testSpawnLocal TestTransport{..} = do
805testSpawnLocal TestTransport{..} = do
@@ -753,15 +813,14 @@ testSpawnLocal TestTransport{..} = do
753 sport <- expect
813 sport <- expect
754 sendChan sport (1234 :: Int)
814 sendChan sport (1234 :: Int)
756− sport <- spawnChannelLocal $ \rport -> do
816+ sport <- spawnChannelLocal $
757− (1234 :: Int) <- receiveChan rport
817+ \rport -> (receiveChan rport :: Process Int) >>= send us
760 send pid sport
819 send pid sport
762− liftIO $ putMVar done ()
820+ expect >>= liftIO . putMVar done
764− takeMVar done
822+ res <- takeMVar done
823+ assertBool "Expected 1234 :: Int" $ res == (1234 :: Int)
766testSpawnAsyncStrictness :: TestTransport -> Assertion
825testSpawnAsyncStrictness :: TestTransport -> Assertion
767testSpawnAsyncStrictness TestTransport{..} = do
826testSpawnAsyncStrictness TestTransport{..} = do
@@ -790,8 +849,9 @@ testReconnect TestTransport{..} = do
790 liftIO $ putMVar processA us
849 liftIO $ putMVar processA us
791 msg1 <- expect
850 msg1 <- expect
792 msg2 <- expect
851 msg2 <- expect
793− True <- return $ msg1 == "message 1" && msg2 == "message 3"
853+ assertBool "messages did not match" $ msg1 == "message 1" && msg2 == "message 3"
794− liftIO $ putMVar sendTestOk ()
854+ putMVar sendTestOk ()
796 forkProcess node2 $ do
856 forkProcess node2 $ do
@@ -824,7 +884,7 @@ testReconnect TestTransport{..} = do
824 matchIf (\(RegisterReply label' _ _) -> "a" == label')
884 matchIf (\(RegisterReply label' _ _) -> "a" == label')
825 (\(RegisterReply _ _ _) -> return ()) ]
885 (\(RegisterReply _ _ _) -> return ()) ]
827− Just _ <- whereisRemote nid1 "a"
887+ _ <- whereisRemote nid1 "a"
830 -- Simulate network failure
890 -- Simulate network failure
@@ -843,9 +903,10 @@ testReconnect TestTransport{..} = do
843 (\(RegisterReply _ _ _) -> return ()) ]
903 (\(RegisterReply _ _ _) -> return ()) ]
846− Nothing <- whereisRemote nid1 "a" -- this will fail because the name is removed when the node is disconnected
906+ mPid <- whereisRemote nid1 "a" -- this will fail because the name is removed when the node is disconnected
907+ liftIO $ assertBool "Expected remote name to be lost" $ mPid == Nothing
847− Just _ <- whereisRemote nid1 "b" -- this will suceed because the value is set after thereconnect
908+ verifyWhereIsRemote nid1 "b" -- this will suceed because the value is set after thereconnect
848− Just _ <- whereisRemote nid1 "c"
909+ verifyWhereIsRemote nid1 "c"
850 liftIO $ putMVar registerTestOk ()
911 liftIO $ putMVar registerTestOk ()
@@ -886,13 +947,14 @@ testUSend usendPrim TestTransport{..} numMessages = do
886 isSorted _ = True
947 isSorted _ = True
887 -- The list can't be null since there are no failures after sending
948 -- The list can't be null since there are no failures after sending
888 -- the last message.
949 -- the last message.
889− True <- return $ isSorted msgs && not (null msgs)
951+ assertBool "Unexpected failure after sending last msg" $ isSorted msgs && not (null msgs)
890− liftIO $ putMVar usendTestOk ()
952+ putMVar usendTestOk ()
892 forkProcess node2 $ do
954 forkProcess node2 $ do
893 them <- liftIO $ readMVar processA
955 them <- liftIO $ readMVar processA
894 getSelfPid >>= send them
956 getSelfPid >>= send them
895− () <- expect
957+ expect :: Process ()
896 forM_ [1..numMessages] $ \i -> do
958 forM_ [1..numMessages] $ \i -> do
897 liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
959 liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
898 usendPrim them i
960 usendPrim them i
@@ -924,14 +986,17 @@ testMatchAny TestTransport{..} = do
924 runProcess localNode $ do
986 runProcess localNode $ do
925 pid <- getSelfPid
987 pid <- getSelfPid
926 send mathServer (Add pid 1 2)
988 send mathServer (Add pid 1 2)
927− 3 <- expect :: Process Double
989+ three <- expect :: Process Double
928 send mathServer (Divide pid 8 2)
990 send mathServer (Divide pid 8 2)
929− 4 <- expect :: Process Double
991+ four <- expect :: Process Double
930 send mathServer (Divide pid 8 0)
992 send mathServer (Divide pid 8 0)
931− DivByZero <- expect
993+ divByZ <- expect
932− liftIO $ putMVar clientDone ()
994+ liftIO $ putMVar clientDone (three, four, divByZ)
934− takeMVar clientDone
996+ res <- takeMVar clientDone
998+ (3, 4, DivByZero) -> return ()
999+ _ -> error "Unexpected result"
936-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
1001-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
937-- in between, however we block 'Divide' requests ....
1002-- in between, however we block 'Divide' requests ....
@@ -958,12 +1023,13 @@ testMatchAnyHandle TestTransport{..} = do
958 runProcess localNode $ do
1023 runProcess localNode $ do
959 pid <- getSelfPid
1024 pid <- getSelfPid
960 send mathServer (Add pid 1 2)
1025 send mathServer (Add pid 1 2)
961− 3 <- expect :: Process Double
1026+ three <- expect :: Process Double
962 send mathServer (Divide pid 8 2)
1027 send mathServer (Divide pid 8 2)
963− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
1028+ res <- (expectTimeout 100000) :: Process (Maybe Double)
964− liftIO $ putMVar clientDone ()
1029+ liftIO $ putMVar clientDone $ three == 3 && res == Nothing
1031+ verifyClient "Expected Nothing (i.e. timeout)" clientDone
967 where maybeForward :: ProcessId -> Message -> Process (Maybe ())
1033 where maybeForward :: ProcessId -> Message -> Process (Maybe ())
968 maybeForward s msg =
1034 maybeForward s msg =
969 handleMessage msg (\m@(Add _ _ _) -> send s m)
1035 handleMessage msg (\m@(Add _ _ _) -> send s m)
@@ -991,8 +1057,10 @@ testMatchAnyNoHandle TestTransport{..} = do
991 Just _ -> die "NONSENSE")
1057 Just _ -> die "NONSENSE")
993 -- we *must* have removed the message from our mailbox though!!!
1059 -- we *must* have removed the message from our mailbox though!!!
994− Nothing <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
1060+ res <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
1062+ assertBool "Expected timeout!" $ res == Nothing
995− liftIO $ putMVar serverDone ()
1063+ putMVar serverDone ()
996 putMVar addr server
1064 putMVar addr server
998 -- Client
1066 -- Client
@@ -1035,14 +1103,21 @@ testMatchAnyIf TestTransport{..} = do
1035 runProcess localNode $ do
1103 runProcess localNode $ do
1036 pid <- getSelfPid
1104 pid <- getSelfPid
1037 send server (pid, "foo")
1105 send server (pid, "foo")
1038− "foo" <- expect
1106+ foo <- expect
1039− send server (pid, "baz")
1107+ -- provoking what would be the wrong ordering is informative here...
1040− "baz" <- expect
1108+
1041 send server (pid, "bar")
1109 send server (pid, "bar")
1042− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
1110+ bar <- (expectTimeout 100000) :: Process (Maybe String) -- was Double o_O !?
1112+ send server (pid, "baz")
1043− liftIO $ putMVar clientDone ()
1115+ liftIO $ putMVar clientDone (foo, bar, baz)
1117+ res <- takeMVar clientDone
1118+ let res' = res == ("foo", Nothing, "baz")
1119+ assertBool "Expected timeout due to type mismatch" res'
1045− takeMVar clientDone
1046 where tryHandleMessage :: Message -> Process (Maybe ())
1121 where tryHandleMessage :: Message -> Process (Maybe ())
1047 tryHandleMessage msg =
1122 tryHandleMessage msg =
1048 handleMessage msg (\(pid :: ProcessId, (m :: String))
1123 handleMessage msg (\(pid :: ProcessId, (m :: String))
@@ -1075,12 +1150,13 @@ testMatchMessageWithUnwrap TestTransport{..} = do
1075 runProcess localNode $ do
1150 runProcess localNode $ do
1076 pid <- getSelfPid
1151 pid <- getSelfPid
1077 send server (pid, wrapMessage ("foo" :: String))
1152 send server (pid, wrapMessage ("foo" :: String))
1078− "foo" <- expect
1153+ foo <- expect
1079 send server (pid, wrapMessage ("baz" :: String))
1154 send server (pid, wrapMessage ("baz" :: String))
1080− "baz" <- expect
1155+ baz <- expect
1081− liftIO $ putMVar clientDone ()
1156+ liftIO $ putMVar clientDone (foo, baz)
1083− takeMVar clientDone
1158+ res <- takeMVar clientDone
1159+ assertBool "Unexpected unwrapped results" $ res == ("foo", "baz")
1085-- Test 'receiveChanTimeout'
1161-- Test 'receiveChanTimeout'
1086testReceiveChanTimeout :: TestTransport -> Assertion
1162testReceiveChanTimeout :: TestTransport -> Assertion
@@ -1098,18 +1174,19 @@ testReceiveChanTimeout TestTransport{..} = do
1099 -- Wait for a message with a delay. No message arrives, we should get
1175 -- Wait for a message with a delay. No message arrives, we should get
1100 -- Nothing after the delay.
1176 -- Nothing after the delay.
1101− Nothing <- receiveChanTimeout 100000 rp
1177+ receiveChanTimeout 100000 rp >>= maybe (return ()) (const $ die "Expected Timeout")
1103 -- Let the sender know that it can send a message.
1179 -- Let the sender know that it can send a message.
1104 liftIO $ putMVar mvSender ()
1180 liftIO $ putMVar mvSender ()
1106 -- Wait for a message with a delay again. Now a message arrives after
1182 -- Wait for a message with a delay again. Now a message arrives after
1107 -- 0.1 seconds
1183 -- 0.1 seconds
1108− Just True <- receiveChanTimeout 20000000 rp
1184+ res <- receiveChanTimeout 20000000 rp >>= maybe (die "Timeout") return
1185+ liftIO $ assertBool "Expected result to be 'True'" res
1110 -- Wait for a message with zero timeout: non-blocking check. No message is
1187 -- Wait for a message with zero timeout: non-blocking check. No message is
1111 -- available, we get Nothing
1188 -- available, we get Nothing
1112− Nothing <- receiveChanTimeout 0 rp
1189+ receiveChanTimeout 0 rp >>= maybe (return ()) (const $ die "Expected Timeout")
1114 -- Let the sender know that it can send a message.
1191 -- Let the sender know that it can send a message.
1115 liftIO $ putMVar mvSender ()
1192 liftIO $ putMVar mvSender ()
@@ -1119,7 +1196,7 @@ testReceiveChanTimeout TestTransport{..} = do
1119 liftIO $ threadDelay 100000
1196 liftIO $ threadDelay 100000
1120 mb <- receiveChanTimeout 0 rp
1197 mb <- receiveChanTimeout 0 rp
1121 case mb of
1198 case mb of
1122− Just b -> do False <- return b; return ()
1199+ Just b -> do liftIO $ assertBool "Unexpected Message" $ not b
1123 _ -> loop
1200 _ -> loop
1125 liftIO $ putMVar done ()
1202 liftIO $ putMVar done ()
@@ -1156,8 +1233,8 @@ testReceiveChanFeatures TestTransport{..} = do
1157 rp1 <- mergePortsBiased [even <$> rpInt, rpBool]
1234 rp1 <- mergePortsBiased [even <$> rpInt, rpBool]
1159− True <- receiveChan rp1
1236+ receiveChan rp1 >>= liftIO . assertBool "Expected True"
1160− False <- receiveChan rp1
1237+ receiveChan rp1 >>= liftIO . assertBool "Expected False" . not
1162 -- Test Applicative instance
1239 -- Test Applicative instance
@@ -1166,7 +1243,7 @@ testReceiveChanFeatures TestTransport{..} = do
1167 let rp2 = pure (+) <*> rpInt <*> rpInt
1244 let rp2 = pure (+) <*> rpInt <*> rpInt
1169− 7 <- receiveChan rp2
1246+ receiveChan rp2 >>= liftIO . assertBool "Expected 7" . (== 7)
1171 -- Test Alternative instance
1248 -- Test Alternative instance
@@ -1175,8 +1252,8 @@ testReceiveChanFeatures TestTransport{..} = do
1176 let rp3 = (even <$> rpInt) <|> rpBool
1253 let rp3 = (even <$> rpInt) <|> rpBool
1178− False <- receiveChan rp3
1255+ receiveChan rp3 >>= liftIO . assertBool "Expected False" . not
1179− True <- receiveChan rp3
1256+ receiveChan rp3 >>= liftIO . assertBool "Expected True"
1181 -- Test Monad instance
1258 -- Test Monad instance
@@ -1190,8 +1267,8 @@ testReceiveChanFeatures TestTransport{..} = do
1190 then rpInt
1267 then rpInt
1191 else return 7
1268 else return 7
1193− 5 <- receiveChan rp4
1270+ receiveChan rp4 >>= liftIO . assertBool "Expected 5" . (== 5)
1194− 7 <- receiveChan rp4
1271+ receiveChan rp4 >>= liftIO . assertBool "Expected 7" . (== 7)
1196 liftIO $ putMVar done ()
1273 liftIO $ putMVar done ()
@@ -1200,7 +1277,6 @@ testReceiveChanFeatures TestTransport{..} = do
1200testKillLocal :: TestTransport -> Assertion
1277testKillLocal :: TestTransport -> Assertion
1201testKillLocal TestTransport{..} = do
1278testKillLocal TestTransport{..} = do
1202 localNode <- newLocalNode testTransport initRemoteTable
1279 localNode <- newLocalNode testTransport initRemoteTable
1203− done <- newEmptyMVar
1205 pid <- forkProcess localNode $ do
1281 pid <- forkProcess localNode $ do
1206 liftIO $ threadDelay 1000000
1282 liftIO $ threadDelay 1000000
@@ -1209,17 +1285,18 @@ testKillLocal TestTransport{..} = do
1209 ref <- monitor pid
1285 ref <- monitor pid
1210 us <- getSelfPid
1286 us <- getSelfPid
1211 kill pid "TestKill"
1287 kill pid "TestKill"
1212− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
1288+ mn <- expect
1290+ ProcessMonitorNotification ref' pid' (DiedException ex) ->
1213− True <- return $ ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill"
1291+ case ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill" of
1214− liftIO $ putMVar done ()
1292+ True -> return ()
1215−
1293+ False -> die "Invalid ProcessMonitorNotification received"
1216− takeMVar done
1294+ _ -> die "Something went horribly wrong"
1218testKillRemote :: TestTransport -> Assertion
1296testKillRemote :: TestTransport -> Assertion
1219testKillRemote TestTransport{..} = do
1297testKillRemote TestTransport{..} = do
1220 node1 <- newLocalNode testTransport initRemoteTable
1298 node1 <- newLocalNode testTransport initRemoteTable
1221 node2 <- newLocalNode testTransport initRemoteTable
1299 node2 <- newLocalNode testTransport initRemoteTable
1222− done <- newEmptyMVar
1224 pid <- forkProcess node1 $ do
1301 pid <- forkProcess node1 $ do
1225 liftIO $ threadDelay 1000000
1302 liftIO $ threadDelay 1000000
@@ -1228,11 +1305,17 @@ testKillRemote TestTransport{..} = do
1228 ref <- monitor pid
1305 ref <- monitor pid
1229 us <- getSelfPid
1306 us <- getSelfPid
1230 kill pid "TestKill"
1307 kill pid "TestKill"
1231− ProcessMonitorNotification ref' pid' (DiedException reason) <- expect
1310+ ProcessMonitorNotification ref' pid' (DiedException reason) ->
1232− True <- return $ ref == ref' && pid == pid' && reason == "killed-by=" ++ show us ++ ",reason=TestKill"
1311+ case (ref == ref', pid == pid', reason == "killed-by=" ++ show us ++ ",reason=TestKill") of
1233− liftIO $ putMVar done ()
1312+ (True, True, True) -> return ()
1234−
1313+ (a, b, c) -> do
1235− takeMVar done
1314+ let a' = if a then "" else "Invalid ref"
1315+ let b' = if b then "" else "Invalid pid"
1316+ let c' = if c then "" else "Invalid message"
1317+ die $ unwords [a', b', c']
1318+ _ -> die "Received unexpected message"
1237testCatchesExit :: TestTransport -> Assertion
1320testCatchesExit :: TestTransport -> Assertion
1238testCatchesExit TestTransport{..} = do
1321testCatchesExit TestTransport{..} = do
@@ -1258,7 +1341,10 @@ testHandleMessageIf TestTransport{..} = do
1258 self <- getSelfPid
1341 self <- getSelfPid
1259 send self (5 :: Integer, 10 :: Integer)
1342 send self (5 :: Integer, 10 :: Integer)
1260 msg <- receiveWait [ matchMessage return ]
1343 msg <- receiveWait [ matchMessage return ]
1261− Nothing <- handleMessageIf msg (\() -> True) (\() -> die $ "whoops")
1344+ handleMessageIf msg
1346+ (\() -> die "whoops") >>= maybe (return ())
1347+ (const $ die "Expected Mismatch")
1262 handleMessageIf msg (\(x :: Integer, y :: Integer) -> x == 5 && y == 10)
1348 handleMessageIf msg (\(x :: Integer, y :: Integer) -> x == 5 && y == 10)
1263 (\input -> liftIO $ putMVar done input)
1349 (\input -> liftIO $ putMVar done input)
1264 return ()
1350 return ()
@@ -1303,8 +1389,11 @@ testDie TestTransport{..} = do
1303 (die ("foobar", 123 :: Int))
1389 (die ("foobar", 123 :: Int))
1304 `catchExit` \_from reason -> do
1390 `catchExit` \_from reason -> do
1305 -- TODO: should verify that 'from' has the right value
1391 -- TODO: should verify that 'from' has the right value
1306− True <- return $ reason == ("foobar", 123 :: Int)
1392+ let res = reason == ("foobar", 123 :: Int)
1307 liftIO $ putMVar done ()
1393 liftIO $ putMVar done ()
1396+ else die "Something went horribly wrong"
1309 takeMVar done
1398 takeMVar done
@@ -1318,8 +1407,11 @@ testPrettyExit TestTransport{..} = do
1318 `catch` \ex@(ProcessExitException from _) ->
1407 `catch` \ex@(ProcessExitException from _) ->
1319 let expected = "exit-from=" ++ (show from)
1408 let expected = "exit-from=" ++ (show from)
1321− True <- return $ (show ex) == expected
1410+ let res = (show ex) == expected
1322 liftIO $ putMVar done ()
1411 liftIO $ putMVar done ()
1414+ else die "Something went horribly wrong"
1324 takeMVar done
1416 takeMVar done
@@ -1335,17 +1427,26 @@ testExitLocal TestTransport{..} = do
1335 pid <- forkProcess localNode $ do
1427 pid <- forkProcess localNode $ do
1336 (liftIO (putMVar handlerSetUp ()) >> expect) `catchExit` \_from reason -> do
1428 (liftIO (putMVar handlerSetUp ()) >> expect) `catchExit` \_from reason -> do
1337 -- TODO: should verify that 'from' has the right value
1429 -- TODO: should verify that 'from' has the right value
1338− True <- return $ reason == "TestExit"
1430+ res <- return $ reason == "TestExit"
1339 liftIO $ putMVar supervisedDone ()
1431 liftIO $ putMVar supervisedDone ()
1434+ else die "Something went horribly wrong"
1341 runProcess localNode $ do
1436 runProcess localNode $ do
1342 liftIO $ takeMVar handlerSetUp
1437 liftIO $ takeMVar handlerSetUp
1343 ref <- monitor pid
1438 ref <- monitor pid
1344 exit pid "TestExit"
1439 exit pid "TestExit"
1345 -- This time the client catches the exception, so it dies normally
1440 -- This time the client catches the exception, so it dies normally
1346− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1443+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1347− True <- return $ ref == ref' && pid == pid'
1444+ let res = ref == ref' && pid == pid'
1348− liftIO $ putMVar supervisorDone ()
1445+ liftIO $ putMVar supervisorDone ()
1448+ else die "Something went horribly wrong"
1449+ _ -> die "Something went horribly wrong"
1350 takeMVar supervisedDone
1451 takeMVar supervisedDone
1351 takeMVar supervisorDone
1452 takeMVar supervisorDone
@@ -1361,19 +1462,90 @@ testExitRemote TestTransport{..} = do
1361 (receiveWait [] :: Process ()) -- block forever
1462 (receiveWait [] :: Process ()) -- block forever
1362 `catchExit` \_from reason -> do
1463 `catchExit` \_from reason -> do
1363 -- TODO: should verify that 'from' has the right value
1464 -- TODO: should verify that 'from' has the right value
1364− True <- return $ reason == "TestExit"
1465+ res <- return $ reason == "TestExit"
1365 liftIO $ putMVar supervisedDone ()
1466 liftIO $ putMVar supervisedDone ()
1469+ else die "Something went horribly wrong"
1367 runProcess node2 $ do
1471 runProcess node2 $ do
1368 ref <- monitor pid
1472 ref <- monitor pid
1369 exit pid "TestExit"
1473 exit pid "TestExit"
1370− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1476+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1371− True <- return $ ref == ref' && pid == pid'
1477+ res' <- return $ ref == ref' && pid == pid'
1372− liftIO $ putMVar supervisorDone ()
1478+ liftIO $ putMVar supervisorDone ()
1481+ else die "Something went horribly wrong"
1482+ _ -> die "Something went horribly wrong"
1374 takeMVar supervisedDone
1484 takeMVar supervisedDone
1375 takeMVar supervisorDone
1485 takeMVar supervisorDone
1487+testRegistryMonitoring :: TestTransport -> Assertion
1488+testRegistryMonitoring TestTransport{..} = do
1489+ node1 <- newLocalNode testTransport initRemoteTable
1490+ node2 <- newLocalNode testTransport initRemoteTable
1491+ waitH <- newEmptyMVar
1493+ let nid = localNodeId node2
1494+ pid <- forkProcess node1 $ do
1495+ getSelfPid >>= runUntilRegistered nid
1496+ liftIO $ takeMVar waitH
1498+ runProcess node2 $ do
1499+ register regName pid
1500+ res <- whereis regName
1504+ assertBool "expected (Just pid)" $ res == (Just pid)
1506+ -- This delay isn't essential!
1507+ -- The test case passes perfectly fine without it (feel free to comment out
1508+ -- and see), however waiting a few seconds here, makes it much more likely
1509+ -- that in delayUntilMaybeUnregistered we will hit the match case right
1510+ -- away, and thus not be subjected to a 20 second delay. The value of 4
1511+ -- seconds appears to work optimally on osx and across several linux distros
1512+ -- running in virtual machines (which is essentially what we do in CI)
1513+ void $ receiveTimeout 4000000 [ matchAny return ]
1515+ -- This delay doesn't serve much purpose in the happy path, however if some
1516+ -- future patch breaks the cooperative behaviour of node controllers viz
1517+ -- remote process registration and notification taking place via ncEffectDied,
1518+ -- there would be the possibility of a race in the test case should we attempt
1519+ -- to evaluate `whereis regName` on node2 right away. In case the name is still
1520+ -- erroneously registered, observing the 20 second delay (or lack of), could at
1521+ -- least give a hint that something is wrong, and we give up our time slice
1522+ -- so that there's a higher change the registrations have been cleaned up
1524+ runProcess node2 $ delayUntilMaybeUnregistered nid pid
1526+ regHere <- newEmptyMVar
1527+ runProcess node2 $ whereis regName >>= liftIO . putMVar regHere
1528+ res <- takeMVar regHere
1529+ assertBool "expected Nothing, but process still registered" (res == Nothing)
1532+ runUntilRegistered nid us = do
1533+ whereisRemoteAsync nid regName
1535+ matchIf (\(WhereIsReply n (Just p)) -> n == regName && p == us)
1536+ (const $ return ())
1539+ delayUntilMaybeUnregistered nid p = do
1540+ whereisRemoteAsync nid regName
1541+ receiveTimeout 20000000 {- 20 sec delay -} [
1542+ matchIf (\(WhereIsReply n p) -> n == regName && p == Nothing)
1543+ (const $ return ())
1547+ regName = "testRegisterRemote"
1377testUnsafeSend :: TestTransport -> Assertion
1549testUnsafeSend :: TestTransport -> Assertion
1378testUnsafeSend TestTransport{..} = do
1550testUnsafeSend TestTransport{..} = do
1379 serverAddr <- newEmptyMVar
1551 serverAddr <- newEmptyMVar
@@ -1389,8 +1561,7 @@ testUnsafeSend TestTransport{..} = do
1389 void $ forkProcess localNode $ do
1561 void $ forkProcess localNode $ do
1390 serverPid <- liftIO $ takeMVar serverAddr
1562 serverPid <- liftIO $ takeMVar serverAddr
1391 getSelfPid >>= unsafeSend serverPid
1563 getSelfPid >>= unsafeSend serverPid
1393− liftIO $ putMVar clientDone ()
1564+ expect >>= liftIO . putMVar clientDone
1395 takeMVar clientDone
1566 takeMVar clientDone
@@ -1409,8 +1580,7 @@ testUnsafeUSend TestTransport{..} = do
1409 void $ forkProcess localNode $ do
1580 void $ forkProcess localNode $ do
1410 serverPid <- liftIO $ takeMVar serverAddr
1581 serverPid <- liftIO $ takeMVar serverAddr
1411 getSelfPid >>= unsafeUSend serverPid
1582 getSelfPid >>= unsafeUSend serverPid
1413− liftIO $ putMVar clientDone ()
1583+ expect >>= liftIO . putMVar clientDone
1415 takeMVar clientDone
1585 takeMVar clientDone
@@ -1421,8 +1591,7 @@ testUnsafeNSend TestTransport{..} = do
1421 localNode <- newLocalNode testTransport initRemoteTable
1591 localNode <- newLocalNode testTransport initRemoteTable
1423 pid <- forkProcess localNode $ do
1593 pid <- forkProcess localNode $ do
1425− liftIO $ putMVar clientDone ()
1594+ expect >>= liftIO . putMVar clientDone
1427 void $ runProcess localNode $ do
1596 void $ runProcess localNode $ do
1428 register "foobar" pid
1597 register "foobar" pid
@@ -1440,8 +1609,7 @@ testUnsafeNSendRemote TestTransport{..} = do
1440 _ <- forkProcess localNode1 $ do
1609 _ <- forkProcess localNode1 $ do
1441 getSelfPid >>= register "foobar"
1610 getSelfPid >>= register "foobar"
1442 liftIO $ putMVar clientDone ()
1611 liftIO $ putMVar clientDone ()
1444− liftIO $ putMVar clientDone ()
1612+ expect >>= liftIO . putMVar clientDone
1446 takeMVar clientDone
1614 takeMVar clientDone
1447 void $ runProcess localNode2 $ do
1615 void $ runProcess localNode2 $ do
@@ -1465,7 +1633,7 @@ testUnsafeSendChan TestTransport{..} = do
1465 serverPid <- liftIO $ takeMVar serverAddr
1633 serverPid <- liftIO $ takeMVar serverAddr
1466 (sp, rp) <- newChan
1634 (sp, rp) <- newChan
1467 unsafeSend serverPid sp
1635 unsafeSend serverPid sp
1468− () <- receiveChan rp
1636+ receiveChan rp :: Process ()
1469 liftIO $ putMVar clientDone ()
1637 liftIO $ putMVar clientDone ()
1471 takeMVar clientDone
1639 takeMVar clientDone
@@ -1479,8 +1647,8 @@ testCallLocal TestTransport{..} = do
1479 runProcess node $ do
1647 runProcess node $ do
1480 r <- (/=) <$> getSelfPid <*> callLocal getSelfPid
1648 r <- (/=) <$> getSelfPid <*> callLocal getSelfPid
1481 liftIO $ putMVar result r
1649 liftIO $ putMVar result r
1482− True <- takeMVar result
1651+ takeMVar result >>= assertBool "Expected 'True'"
1485 -- Testing that when callLocal is interrupted, the worker is interrupted.
1653 -- Testing that when callLocal is interrupted, the worker is interrupted.
1486 ibox <- newIORef False
1654 ibox <- newIORef False
@@ -1497,10 +1665,9 @@ testCallLocal TestTransport{..} = do
1497 (send keeper ())
1665 (send keeper ())
1498 caller <- expect
1666 caller <- expect
1499 exit caller "test"
1667 exit caller "test"
1500− () <- expect
1668+ expect :: Process ()
1502− True <- readIORef ibox
1670+ readIORef ibox >>= assertBool "Expected 'True'"
1505 -- Testing that when the worker raises an exception, the exception is propagated to the parent.
1672 -- Testing that when the worker raises an exception, the exception is propagated to the parent.
1506 ibox2 <- newIORef False
1673 ibox2 <- newIORef False
@@ -1509,8 +1676,8 @@ testCallLocal TestTransport{..} = do
1509 liftIO $ writeIORef ibox2 $ case r of
1676 liftIO $ writeIORef ibox2 $ case r of
1510 Left (ErrorCall "e") -> True
1677 Left (ErrorCall "e") -> True
1511 _ -> False
1678 _ -> False
1512− True <- readIORef ibox
1680+ readIORef ibox >>= assertBool "Expected 'True'"
1515 -- Test that caller waits for the worker in correct situation
1682 -- Test that caller waits for the worker in correct situation
1516 ibox3 <- newIORef False
1683 ibox3 <- newIORef False
@@ -1527,8 +1694,8 @@ testCallLocal TestTransport{..} = do
1527 liftIO $ putMVar result3 =<< readIORef ibox3
1694 liftIO $ putMVar result3 =<< readIORef ibox3
1528 worker <- expect
1695 worker <- expect
1529 send worker ()
1696 send worker ()
1530− True <- takeMVar result3
1698+ takeMVar result3 >>= assertBool "Expected 'True'"
1533 -- Test that caller waits for the worker in case when caller gets an exception
1700 -- Test that caller waits for the worker in case when caller gets an exception
1534 ibox4 <- newIORef False
1701 ibox4 <- newIORef False
@@ -1544,13 +1711,9 @@ testCallLocal TestTransport{..} = do
1544 `finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
1711 `finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
1545 caller <- expect
1712 caller <- expect
1546 exit caller "hi!"
1713 exit caller "hi!"
1547− True <- takeMVar result4
1549− -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
1715+ takeMVar result4 >>= assertBool "Expected 'True'"
1716+ -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
1555tests :: TestTransport -> IO [Test]
1718tests :: TestTransport -> IO [Test]
1556tests testtrans = return [
1719tests testtrans = return [
@@ -1584,6 +1747,7 @@ tests testtrans = return [
1584 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
1747 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
1585 , testCase "ExitLocal" (testExitLocal testtrans)
1748 , testCase "ExitLocal" (testExitLocal testtrans)
1586 , testCase "ExitRemote" (testExitRemote testtrans)
1749 , testCase "ExitRemote" (testExitRemote testtrans)
1750+ , testCase "RegistryMonitoring" (testRegistryMonitoring testtrans)
1587 , testCase "TextCallLocal" (testCallLocal testtrans)
1751 , testCase "TextCallLocal" (testCallLocal testtrans)
1588 -- Unsafe Primitives
1752 -- Unsafe Primitives
1589 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
1753 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
@@ -1636,17 +1800,3 @@ tests testtrans = return [
1636 , testCase "MonitorUnreachable" (testMonitorUnreachable testtrans True False)
1800 , testCase "MonitorUnreachable" (testMonitorUnreachable testtrans True False)
1640−syncBreakConnection :: (NT.EndPointAddress -> NT.EndPointAddress -> IO ()) -> LocalNode -> LocalNode -> IO ()
1641−syncBreakConnection breakConnection nid0 nid1 = do
1643− _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
1644− runProcess nid0 $ do
1645− them <- liftIO $ takeMVar m
1646− pinger <- spawnLocal $ forever $ send them ()
1647− _ <- monitorNode (localNodeId nid1)
1648− liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
1649− (nodeAddress $ localNodeId nid1)
1650− NodeMonitorNotification _ _ _ <- expect
1651− kill pinger "finished"