@@ -757,6 +757,121 @@ testMatchAny transport = do
758 takeMVar clientDone
758 takeMVar clientDone
760+-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
761+-- in between, however we block 'Divide' requests ....
762+testMatchAnyHandle :: NT.Transport -> Assertion
763+testMatchAnyHandle transport = do
764+ proxyAddr <- newEmptyMVar
765+ clientDone <- newEmptyMVar
769+ localNode <- newLocalNode transport initRemoteTable
770+ mathServer <- forkProcess localNode math
771+ proxyServer <- forkProcess localNode $ forever $ do
773+ matchAny (maybeForward mathServer)
775+ putMVar proxyAddr proxyServer
779+ localNode <- newLocalNode transport initRemoteTable
780+ mathServer <- readMVar proxyAddr
782+ runProcess localNode $ do
784+ send mathServer (Add pid 1 2)
785+ 3 <- expect :: Process Double
786+ send mathServer (Divide pid 8 2)
787+ Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
788+ liftIO $ putMVar clientDone ()
791+ where maybeForward :: ProcessId -> AbstractMessage -> Process (Maybe ())
792+ maybeForward s msg =
793+ maybeHandleMessage msg (\m@(Add _ _ _) -> send s m)
795+testMatchAnyNoHandle :: NT.Transport -> Assertion
796+testMatchAnyNoHandle transport = do
797+ addr <- newEmptyMVar
798+ clientDone <- newEmptyMVar
799+ serverDone <- newEmptyMVar
803+ localNode <- newLocalNode transport initRemoteTable
804+ server <- forkProcess localNode $ forever $ do
807+ -- the condition has type `Add -> Bool`
808+ (\(Add _ _ _) -> True)
809+ -- the match `AbstractMessage -> Process ()` will succeed!
811+ -- `String -> Process ()` does *not* match the input types however
812+ r <- (maybeHandleMessage m (\(_ :: String) -> die "NONSENSE" ))
814+ Nothing -> return ()
815+ Just _ -> die "NONSENSE")
817+ -- we *must* have removed the message from our mailbox though!!!
818+ Nothing <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
819+ liftIO $ putMVar serverDone ()
824+ localNode <- newLocalNode transport initRemoteTable
825+ server <- readMVar addr
827+ runProcess localNode $ do
829+ send server (Add pid 1 2)
830+ -- we only care about the client having sent a message, so we're done
831+ liftIO $ putMVar clientDone ()
836+-- | Test 'matchAnyIf'. We provide an /echo/ server, but it ignores requests
837+-- unless the text body @/= "bar"@ - this case should time out rather than
838+-- removing the message from the process mailbox.
839+testMatchAnyIf :: NT.Transport -> Assertion
840+testMatchAnyIf transport = do
841+ echoAddr <- newEmptyMVar
842+ clientDone <- newEmptyMVar
846+ localNode <- newLocalNode transport initRemoteTable
847+ echoServer <- forkProcess localNode $ forever $ do
849+ matchAnyIf (\(_ :: ProcessId, (s :: String)) -> s /= "bar")
852+ putMVar echoAddr echoServer
856+ localNode <- newLocalNode transport initRemoteTable
857+ server <- readMVar echoAddr
859+ runProcess localNode $ do
861+ send server (pid, "foo")
863+ send server (pid, "baz")
865+ send server (pid, "bar")
866+ Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
867+ liftIO $ putMVar clientDone ()
870+ where handleMessage :: AbstractMessage -> Process (Maybe ())
872+ maybeHandleMessage msg (\(pid :: ProcessId, (m :: String))
873+ -> do { send pid m; return () })
760-- Test 'receiveChanTimeout'
875-- Test 'receiveChanTimeout'
761testReceiveChanTimeout :: NT.Transport -> Assertion
876testReceiveChanTimeout :: NT.Transport -> Assertion
762testReceiveChanTimeout transport = do
877testReceiveChanTimeout transport = do
@@ -987,6 +1102,9 @@ tests (transport, transportInternals) = [
987 , testCase "RemoteRegistry" (testRemoteRegistry transport)
1102 , testCase "RemoteRegistry" (testRemoteRegistry transport)
988 , testCase "SpawnLocal" (testSpawnLocal transport)
1103 , testCase "SpawnLocal" (testSpawnLocal transport)
989 , testCase "MatchAny" (testMatchAny transport)
1104 , testCase "MatchAny" (testMatchAny transport)
1105+ , testCase "MatchAnyHandle" (testMatchAnyHandle transport)
1106+ , testCase "MatchAnyNoHandle" (testMatchAnyNoHandle transport)
1107+ , testCase "MatchAnyIf" (testMatchAnyIf transport)
990 , testCase "ReceiveChanTimeout" (testReceiveChanTimeout transport)
1108 , testCase "ReceiveChanTimeout" (testReceiveChanTimeout transport)
991 , testCase "ReceiveChanFeatures" (testReceiveChanFeatures transport)
1109 , testCase "ReceiveChanFeatures" (testReceiveChanFeatures transport)
992 , testCase "KillLocal" (testKillLocal transport)
1110 , testCase "KillLocal" (testKillLocal transport)