1{-# LANGUAGE TemplateHaskell, DeriveDataTypeable #-}
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
21import Test.HUnit (Assertion, (@?=))
22import Test.Framework (Test, defaultMain)
23import Test.Framework.Providers.HUnit (testCase)
27-- 1. 2 matchChans, receive on each one
28-- 2. matchChan/matchIf, receive on each one
29-- 3. matchIf/matchChan, receive on each one
30-- 4. matchIf/matchChan/matchIf, receive on each one
32recTest1 :: ReceivePort ()
34 -> ReceivePort String -> ReceivePort String
36recTest1 wait sync r1 r2 = do
40 [ matchChan r1 $ \s -> return ("received1 " ++ s)
41 , matchChan r2 $ \s -> return ("received2 " ++ s)
45recTest2 :: ReceivePort ()
47 -> ReceivePort String -> ReceivePort String
49recTest2 wait sync r1 r2 = do
53 [ matchChan r1 $ \s -> return ("received1 " ++ s)
54 , matchIf (== "foo") $ \s -> return ("received2 " ++ s)
58recTest3 :: ReceivePort ()
60 -> ReceivePort String -> ReceivePort String
62recTest3 wait sync r1 r2 = do
66 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
67 , matchChan r1 $ \s -> return ("received2 " ++ s)
71recTest4 :: ReceivePort ()
73 -> ReceivePort String -> ReceivePort String
75recTest4 wait sync r1 r2 = do
79 [ matchIf (== "foo") $ \s -> return ("received1 " ++ s)
80 , matchChan r1 $ \s -> return ("received2 " ++ s)
81 , matchIf (== "bar") $ \s -> return ("received3 " ++ s)
87 (waits,waitr) <- newChan
88 (syncs,syncr) <- newChan
91 r <- receiveChan syncr
92 liftIO $ print (r,expect, r == expect)
95 liftIO $ putStrLn "---- Test 1 ----"
98 p <- spawnLocal (recTest1 waitr syncs r1 r2)
100 sendChan s1 "a" >> go "received1 a"
101 sendChan s2 "b" >> go "received2 b"
102 sendChan s1 "a" >> sendChan s2 "b" >> go "received1 a"
107 liftIO $ putStrLn "\n---- Test 2 ----"
110 p <- spawnLocal (recTest2 waitr syncs r1 r2)
112 sendChan s1 "a" >> go "received1 a"
113 send p "foo" >> go "received2 foo"
114 sendChan s1 "a" >> send p "foo" >> go "received1 a"
115 sendChan s1 "a" >> send p "bar" >> go "received1 a"
120 liftIO $ putStrLn "\n---- Test 3 ----"
123 p <- spawnLocal (recTest3 waitr syncs r1 r2)
125 sendChan s1 "a" >> go "received2 a"
126 send p "foo" >> go "received1 foo"
127 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
128 sendChan s1 "a" >> send p "bar" >> go "received2 a"
133 liftIO $ putStrLn "\n---- Test 4 ----"
136 p <- spawnLocal (recTest4 waitr syncs r1 r2)
138 sendChan s1 "a" >> go "received2 a"
139 send p "foo" >> go "received1 foo"
140 send p "bar" >> go "received3 bar"
141 sendChan s1 "a" >> send p "foo" >> go "received1 foo"
142 send p "bar" >> go "received2 a"
143 send p "foo" >> go "received1 foo" >> go "received3 bar"
149testReceive :: Transport -> RemoteTable -> Assertion
150testReceive transport rtable = do
151 node <- newLocalNode transport rtable
152 runProcess node $ master
154tests :: TestTransport -> IO [Test]
155tests TestTransport{..} = do
156 let rtable = initRemoteTable
158 [ 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