Skip to content

Commit d48549c

Browse files
committed
Test if it's possible to send message to remote nodes in Registry
Ability to send to remote nodes stored in local Registry required for distributed-process-simplelocalnet and possibly other uses, we want to check this functionality explicitly, in order to not optimize it out.
1 parent be78954 commit d48549c

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
@@ -653,6 +653,26 @@ testRegistry TestTransport{..} = do
653653

654654
takeMVar done
655655

656+
testRegistryRemoteProcess :: TestTransport -> Assertion
657+
testRegistryRemoteProcess TestTransport{..} = do
658+
node1 <- newLocalNode testTransport initRemoteTable
659+
node2 <- newLocalNode testTransport initRemoteTable
660+
done <- newEmptyMVar
661+
662+
pingServer <- forkProcess node1 ping
663+
664+
runProcess node2 $ do
665+
register "ping" pingServer
666+
Just pid <- whereis "ping"
667+
True <- return $ pingServer == pid
668+
us <- getSelfPid
669+
nsend "ping" (Pong us)
670+
Ping pid' <- expect
671+
True <- return $ pingServer == pid'
672+
liftIO $ putMVar done ()
673+
674+
takeMVar done
675+
656676
testRemoteRegistry :: TestTransport -> Assertion
657677
testRemoteRegistry TestTransport{..} = do
658678
node1 <- newLocalNode testTransport initRemoteTable
@@ -697,6 +717,30 @@ testRemoteRegistry TestTransport{..} = do
697717

698718
takeMVar done
699719

720+
testRemoteRegistryRemoteProcess :: TestTransport -> Assertion
721+
testRemoteRegistryRemoteProcess TestTransport{..} = do
722+
node1 <- newLocalNode testTransport initRemoteTable
723+
node2 <- newLocalNode testTransport initRemoteTable
724+
done <- newEmptyMVar
725+
726+
pingServer <- forkProcess node2 ping
727+
728+
runProcess node2 $ do
729+
let nid1 = localNodeId node1
730+
registerRemoteAsync nid1 "ping" pingServer
731+
receiveWait [
732+
matchIf (\(RegisterReply label' _ _) -> "ping" == label')
733+
(\(RegisterReply _ _ _) -> return ()) ]
734+
Just pid <- whereisRemote nid1 "ping"
735+
True <- return $ pingServer == pid
736+
us <- getSelfPid
737+
nsendRemote nid1 "ping" (Pong us)
738+
Ping pid' <- expect
739+
True <- return $ pingServer == pid'
740+
liftIO $ putMVar done ()
741+
742+
takeMVar done
743+
700744
testSpawnLocal :: TestTransport -> Assertion
701745
testSpawnLocal TestTransport{..} = do
702746
node <- newLocalNode testTransport initRemoteTable
@@ -1368,7 +1412,9 @@ tests testtrans = return [
13681412
, testCase "MergeChannels" (testMergeChannels testtrans)
13691413
, testCase "Terminate" (testTerminate testtrans)
13701414
, testCase "Registry" (testRegistry testtrans)
1415+
, testCase "RegistryRemoteProcess" (testRegistryRemoteProcess testtrans)
13711416
, testCase "RemoteRegistry" (testRemoteRegistry testtrans)
1417+
, testCase "RemoteRegistryRemoteProcess" (testRemoteRegistryRemoteProcess testtrans)
13721418
, testCase "SpawnLocal" (testSpawnLocal testtrans)
13731419
, testCase "HandleMessageIf" (testHandleMessageIf testtrans)
13741420
, testCase "MatchAny" (testMatchAny testtrans)

0 commit comments

Comments
 (0)