1{-# LANGUAGE TemplateHaskell #-}
2{-# OPTIONS_GHC -Wall #-}
4-- | XXX test doesn't work, because failure exceptions don't get propagated. The
5-- test always claims to succeed, even if it failed.
7module Control.Distributed.Process.Tests.Receive (tests) where
9import Network.Transport.Test (TestTransport(..))
11import Network.Transport (Transport)
12import Control.Distributed.Process
13import Control.Distributed.Process.Closure
14import Control.Distributed.Process.Node
18import Test.HUnit (Assertion, (@?=))
19import Test.Framework (Test, defaultMain)
20import Test.Framework.Providers.HUnit (testCase)
24-- 1. 2 matchChans, receive on each one
25-- 2. matchChan/matchIf, receive on each one
26-- 3. matchIf/matchChan, receive on each one
27-- 4. matchIf/matchChan/matchIf, receive on each one
29recTest1 :: ReceivePort ()
31 -> ReceivePort String -> ReceivePort String
33recTest1 wait sync r1 r2 = do
37 [ matchChan r1 $ \s -> return ("received1 " ++ s)
38 , matchChan r2 $ \s -> return ("received2 " ++ s)
42recTest2 :: ReceivePort ()
44 -> ReceivePort String -> ReceivePort String
46recTest2 wait sync r1 r2 = do
50 [ matchChan r1 $ \s -> return ("received1 " ++ s)
51 , matchIf (== "foo") $ \s -> return ("received2 " ++ s)
55recTest3 :: ReceivePort ()
57 -> ReceivePort String -> ReceivePort String
59recTest3 wait sync r1 r2 = do
63 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
64 , matchChan r1 $ \s -> return ("received2 " ++ s)
68recTest4 :: ReceivePort ()
70 -> ReceivePort String -> ReceivePort String
72recTest4 wait sync r1 r2 = do
76 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
77 , matchChan r1 $ \s -> return ("received2 " ++ s)
78 , matchIf (== "bar") $ \s -> return ("received3 " ++ s)
84 (waits,waitr) <- newChan
85 (syncs,syncr) <- newChan
88 r <- receiveChan syncr
89 liftIO $ print (r,expect, r == expect)
92 liftIO $ putStrLn "---- Test 1 ----"
95 p <- spawnLocal (recTest1 waitr syncs r1 r2)
97 sendChan s1 "a" >> go "received1 a"
98 sendChan s2 "b" >> go "received2 b"
99 sendChan s1 "a" >> sendChan s2 "b" >> go "received1 a"
104 liftIO $ putStrLn "\n---- Test 2 ----"
107 p <- spawnLocal (recTest2 waitr syncs r1 r2)
109 sendChan s1 "a" >> go "received1 a"
110 send p "foo" >> go "received2 foo"
111 sendChan s1 "a" >> send p "foo" >> go "received1 a"
112 sendChan s1 "a" >> send p "bar" >> go "received1 a"
117 liftIO $ putStrLn "\n---- Test 3 ----"
120 p <- spawnLocal (recTest3 waitr syncs r1 r2)
122 sendChan s1 "a" >> go "received2 a"
123 send p "foo" >> go "received1 foo"
124 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
125 sendChan s1 "a" >> send p "bar" >> go "received2 a"
130 liftIO $ putStrLn "\n---- Test 4 ----"
133 p <- spawnLocal (recTest4 waitr syncs r1 r2)
135 sendChan s1 "a" >> go "received2 a"
136 send p "foo" >> go "received1 foo"
137 send p "bar" >> go "received3 bar"
138 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
139 send p "bar" >> go "received2 a"
140 send p "foo" >> go "received1 foo" >> go "received3 bar"
146testReceive :: Transport -> RemoteTable -> Assertion
147testReceive transport rtable = do
148 node <- newLocalNode transport rtable
149 runProcess node $ master
151tests :: TestTransport -> IO [Test]
152tests TestTransport{..} = do
153 let rtable = initRemoteTable
155 [ testCase "testReceive" (testReceive testTransport rtable) ]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list