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.Node
17import Test.HUnit (Assertion, (@?=))
18import Test.Framework (Test)
19import Test.Framework.Providers.HUnit (testCase)
23-- 1. 2 matchChans, receive on each one
24-- 2. matchChan/matchIf, receive on each one
25-- 3. matchIf/matchChan, receive on each one
26-- 4. matchIf/matchChan/matchIf, receive on each one
28recTest1 :: ReceivePort ()
30 -> ReceivePort String -> ReceivePort String
32recTest1 wait sync r1 r2 = do
36 [ matchChan r1 $ \s -> return ("received1 " ++ s)
37 , matchChan r2 $ \s -> return ("received2 " ++ s)
41recTest2 :: ReceivePort ()
43 -> ReceivePort String -> ReceivePort String
45recTest2 wait sync r1 _ = do
49 [ matchChan r1 $ \s -> return ("received1 " ++ s)
50 , matchIf (== "foo") $ \s -> return ("received2 " ++ s)
54recTest3 :: ReceivePort ()
56 -> ReceivePort String -> ReceivePort String
58recTest3 wait sync r1 _ = do
62 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
63 , matchChan r1 $ \s -> return ("received2 " ++ s)
67recTest4 :: ReceivePort ()
69 -> ReceivePort String -> ReceivePort String
71recTest4 wait sync r1 _ = do
75 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
76 , matchChan r1 $ \s -> return ("received2 " ++ s)
77 , matchIf (== "bar") $ \s -> return ("received3 " ++ s)
83 (waits,waitr) <- newChan
84 (syncs,syncr) <- newChan
87 r <- receiveChan syncr
88 liftIO $ print (r, expected, r == expected)
89 liftIO $ r @?= expected
91 liftIO $ putStrLn "---- Test 1 ----"
94 p <- spawnLocal (recTest1 waitr syncs r1 r2)
96 sendChan s1 "a" >> go "received1 a"
97 sendChan s2 "b" >> go "received2 b"
98 sendChan s1 "a" >> sendChan s2 "b" >> go "received1 a"
103 liftIO $ putStrLn "\n---- Test 2 ----"
106 p <- spawnLocal (recTest2 waitr syncs r1 r2)
108 sendChan s1 "a" >> go "received1 a"
109 send p "foo" >> go "received2 foo"
110 sendChan s1 "a" >> send p "foo" >> go "received1 a"
111 sendChan s1 "a" >> send p "bar" >> go "received1 a"
116 liftIO $ putStrLn "\n---- Test 3 ----"
119 p <- spawnLocal (recTest3 waitr syncs r1 r2)
121 sendChan s1 "a" >> go "received2 a"
122 send p "foo" >> go "received1 foo"
123 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
124 sendChan s1 "a" >> send p "bar" >> go "received2 a"
129 liftIO $ putStrLn "\n---- Test 4 ----"
132 p <- spawnLocal (recTest4 waitr syncs r1 r2)
134 sendChan s1 "a" >> go "received2 a"
135 send p "foo" >> go "received1 foo"
136 send p "bar" >> go "received3 bar"
137 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
138 send p "bar" >> go "received2 a"
139 send p "foo" >> go "received1 foo" >> go "received3 bar"
145testReceive :: Transport -> RemoteTable -> Assertion
146testReceive transport rtable = do
147 node <- newLocalNode transport rtable
148 runProcess node $ master
150tests :: TestTransport -> IO [Test]
151tests TestTransport{..} = do
152 let rtable = initRemoteTable
154 [ 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