Skip to content

Commit a00f97f

Browse files
committed
Merge pull request #11 from qnikst/remote-registry
Test if it's possible to send message to remote nodes in Registry
2 parents 3f07148 + d48549c commit a00f97f

File tree

1 file changed

+46
-0
lines changed
  • src/Control/Distributed/Process/Tests

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ testRegistry TestTransport{..} = do
658658

659659
takeMVar done
660660

661+
testRegistryRemoteProcess :: TestTransport -> Assertion
662+
testRegistryRemoteProcess TestTransport{..} = do
663+
node1 <- newLocalNode testTransport initRemoteTable
664+
node2 <- newLocalNode testTransport initRemoteTable
665+
done <- newEmptyMVar
666+
667+
pingServer <- forkProcess node1 ping
668+
669+
runProcess node2 $ do
670+
register "ping" pingServer
671+
Just pid <- whereis "ping"
672+
True <- return $ pingServer == pid
673+
us <- getSelfPid
674+
nsend "ping" (Pong us)
675+
Ping pid' <- expect
676+
True <- return $ pingServer == pid'
677+
liftIO $ putMVar done ()
678+
679+
takeMVar done
680+
661681
testRemoteRegistry :: TestTransport -> Assertion
662682
testRemoteRegistry TestTransport{..} = do
663683
node1 <- newLocalNode testTransport initRemoteTable
@@ -702,6 +722,30 @@ testRemoteRegistry TestTransport{..} = do
702722

703723
takeMVar done
704724

725+
testRemoteRegistryRemoteProcess :: TestTransport -> Assertion
726+
testRemoteRegistryRemoteProcess TestTransport{..} = do
727+
node1 <- newLocalNode testTransport initRemoteTable
728+
node2 <- newLocalNode testTransport initRemoteTable
729+
done <- newEmptyMVar
730+
731+
pingServer <- forkProcess node2 ping
732+
733+
runProcess node2 $ do
734+
let nid1 = localNodeId node1
735+
registerRemoteAsync nid1 "ping" pingServer
736+
receiveWait [
737+
matchIf (\(RegisterReply label' _ _) -> "ping" == label')
738+
(\(RegisterReply _ _ _) -> return ()) ]
739+
Just pid <- whereisRemote nid1 "ping"
740+
True <- return $ pingServer == pid
741+
us <- getSelfPid
742+
nsendRemote nid1 "ping" (Pong us)
743+
Ping pid' <- expect
744+
True <- return $ pingServer == pid'
745+
liftIO $ putMVar done ()
746+
747+
takeMVar done
748+
705749
testSpawnLocal :: TestTransport -> Assertion
706750
testSpawnLocal TestTransport{..} = do
707751
node <- newLocalNode testTransport initRemoteTable
@@ -1468,7 +1512,9 @@ tests testtrans = return [
14681512
, testCase "MergeChannels" (testMergeChannels testtrans)
14691513
, testCase "Terminate" (testTerminate testtrans)
14701514
, testCase "Registry" (testRegistry testtrans)
1515+
, testCase "RegistryRemoteProcess" (testRegistryRemoteProcess testtrans)
14711516
, testCase "RemoteRegistry" (testRemoteRegistry testtrans)
1517+
, testCase "RemoteRegistryRemoteProcess" (testRemoteRegistryRemoteProcess testtrans)
14721518
, testCase "SpawnLocal" (testSpawnLocal testtrans)
14731519
, testCase "SpawnAsyncStrictness" (testSpawnAsyncStrictness testtrans)
14741520
, testCase "HandleMessageIf" (testHandleMessageIf testtrans)

0 commit comments

Comments
 (0)