@@ -15,7 +15,7 @@ import Control.Concurrent.MVar
1515 , takeMVar
1616 , readMVar
1717 )
18−import Control.Monad (replicateM_, replicateM)
18+import Control.Monad (replicateM_, replicateM, forever)
1919import Control.Exception (throwIO)
2020import Control.Applicative ((<$>), (<*>))
2121import qualified Network.Transport as NT (Transport, closeEndPoint)
@@ -660,6 +660,39 @@ testReconnect transport transportInternals = do
660660
661661 takeMVar registerTestOk
662662
663+-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
664+-- in between
665+testMatchAny :: NT.Transport -> IO ()
666+testMatchAny transport = do
667+ proxyAddr <- newEmptyMVar
668+ clientDone <- newEmptyMVar
669+
670+ -- Math server
671+ forkIO $ do
672+ localNode <- newLocalNode transport initRemoteTable
673+ mathServer <- forkProcess localNode math
674+ proxyServer <- forkProcess localNode $ forever $ do
675+ msg <- receiveWait [ matchAny return ]
676+ forward msg mathServer
677+ putMVar proxyAddr proxyServer
678+
679+ -- Client
680+ forkIO $ do
681+ localNode <- newLocalNode transport initRemoteTable
682+ mathServer <- readMVar proxyAddr
683+
684+ runProcess localNode $ do
685+ pid <- getSelfPid
686+ send mathServer (Add pid 1 2)
687+ 3 <- expect :: Process Double
688+ send mathServer (Divide pid 8 2)
689+ 4 <- expect :: Process Double
690+ send mathServer (Divide pid 8 0)
691+ DivByZero <- expect
692+ liftIO $ putMVar clientDone ()
693+
694+ takeMVar clientDone
695+
663696main :: IO ()
664697main = do
665698 Right (transport, transportInternals) <- createTransportExposeInternals "127.0.0.1" "8080" defaultTCPParameters
@@ -675,6 +708,7 @@ main = do
675708 , ("Registry", testRegistry transport)
676709 , ("RemoteRegistry", testRemoteRegistry transport)
677710 , ("SpawnLocal", testSpawnLocal transport)
711+ , ("MatchAny", testMatchAny transport)
678712 -- Monitoring processes
679713 --
680714 -- The "missing" combinations in the list below don't make much sense, as