@@ -37,9 +37,11 @@ import Control.Distributed.Process.Internal.Types
37 , createUnencodedMessage
37 , createUnencodedMessage
39import Control.Distributed.Process.Node
39import Control.Distributed.Process.Node
40+import Control.Distributed.Process.Debug
41+import Control.Distributed.Process.Management.Internal.Types
40import Control.Distributed.Process.Serializable (Serializable)
42import Control.Distributed.Process.Serializable (Serializable)
42−import Test.HUnit (Assertion, assertFailure)
44+import Test.HUnit (Assertion, assertFailure, assertBool)
43import Test.Framework (Test, testGroup)
45import Test.Framework (Test, testGroup)
44import Test.Framework.Providers.HUnit (testCase)
46import Test.Framework.Providers.HUnit (testCase)
45import Control.Rematch hiding (match)
47import Control.Rematch hiding (match)
@@ -1369,6 +1371,113 @@ testExitRemote TestTransport{..} = do
1369 takeMVar supervisedDone
1371 takeMVar supervisedDone
1370 takeMVar supervisorDone
1372 takeMVar supervisorDone
1374+testRegistryMonitoring :: TestTransport -> Assertion
1375+testRegistryMonitoring TestTransport{..} = do
1376+ localNode <- newLocalNode testTransport initRemoteTable
1377+ remoteNode <- newLocalNode testTransport initRemoteTable
1380+ -- Local process. Test if local process will be removed from
1381+ -- registry when it dies.
1382+ box <- newEmptyMVar
1383+ runProcess localNode $ do
1384+ pid <- spawnLocal $ do
1386+ register "test" pid
1387+ tpid <- whereis "test"
1388+ if tpid == Just pid
1389+ then do _ <- monitor pid
1391+ ProcessMonitorNotification{} <- expect
1392+ tpid1 <- whereis "test"
1393+ liftIO $ putMVar box (Nothing == tpid1)
1394+ else liftIO $ putMVar box False
1396+ takeMVar box >>= assertBool "expected local process to not be registered"
1399+ -- Remote process. Test if remote process entry is removed
1400+ -- from registry when process dies.
1401+ remote1 <- testRemote remoteNode
1402+ runProcess localNode $
1404+ w <- whereis "test" :: Process (Maybe ProcessId)
1405+ forM_ w (const waitpoll)
1406+ in do register "test" remote1
1412+ -- Many labels. Test if all labels associated with process
1413+ -- are removed from registry when it dies.
1414+ remote2 <- testRemote remoteNode
1415+ runProcess localNode $
1417+ w1 <- whereis "test-3" :: Process (Maybe ProcessId)
1418+ w2 <- whereis "test-4" :: Process (Maybe ProcessId)
1419+ forM_ (w1 <|> w2) (const waitpoll)
1420+ in do register "test-3" remote2
1421+ register "test-4" remote2
1426+{- XXX: waiting including patch for nsend for remote process
1427+ remote3 <- testRemote remoteNode
1428+ remote4 <- testRemote remoteNode
1429+ -- test many labels
1430+ runProcess localNode $ do
1431+ register "test-3" remote3
1432+ reregister "test-3" remote4
1434+ liftIO $ threadDelay 50000 -- XXX: racy
1437+ ProcessMonitorNotification{} <- expect
1441+ -- Test registerRemoteAsync properties. Add a local process to
1442+ -- remote registry and checks that it is removed
1443+ -- when the process dies.
1444+ remote5 <- testRemote remoteNode
1445+ runProcess localNode $ do
1446+ registerRemoteAsync (localNodeId remoteNode) "test" remote5
1448+ match (\(RegisterReply _ True _) -> return ())
1451+ whereisRemoteAsync (localNodeId remoteNode) "test"
1453+ match (\(WhereIsReply _ mr) -> forM_ mr (const waitpoll))
1457+ -- Add remote process to remote registry and checks if
1458+ -- entry is removed then process is dead.
1459+ remote6 <- testRemote localNode
1460+ runProcess localNode $ do
1461+ registerRemoteAsync (localNodeId remoteNode) "test" remote6
1463+ match (\(RegisterReply _ True _) -> return ())
1466+ whereisRemoteAsync (localNodeId remoteNode) "test"
1468+ match (\(WhereIsReply _ mr) -> forM_ mr (const waitpoll))
1472+ testRemote node = do
1473+ -- test many labels
1474+ pidBox <- newEmptyMVar
1475+ forkProcess node $ do
1477+ liftIO $ putMVar pidBox us
1478+ expect :: Process ()
1372testUnsafeSend :: TestTransport -> Assertion
1481testUnsafeSend :: TestTransport -> Assertion
1373testUnsafeSend TestTransport{..} = do
1482testUnsafeSend TestTransport{..} = do
1374 serverAddr <- newEmptyMVar
1483 serverAddr <- newEmptyMVar
@@ -1579,6 +1688,7 @@ tests testtrans = return [
1579 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
1688 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
1580 , testCase "ExitLocal" (testExitLocal testtrans)
1689 , testCase "ExitLocal" (testExitLocal testtrans)
1581 , testCase "ExitRemote" (testExitRemote testtrans)
1690 , testCase "ExitRemote" (testExitRemote testtrans)
1691+ , testCase "TestRegistryMonitor" (testRegistryMonitoring testtrans)
1582 , testCase "TextCallLocal" (testCallLocal testtrans)
1692 , testCase "TextCallLocal" (testCallLocal testtrans)
1583 -- Unsafe Primitives
1693 -- Unsafe Primitives
1584 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
1694 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)