git.iko.soy/distributed-process
on master help sign in
merge master
commitd2b5d822ce5008c408997842787c14f41da71e56 authorTim Watson <watson.timothy@gmail.com> dateFri 16 Nov 2018, 09:52 (8 years ago) parent13a37461e43976
27 files changed+871−377
.travis.yml+11−6 benchmarks/Channels.hs+6−5 benchmarks/Latency.hs+7−5 benchmarks/ProcessRing.hs+2−2 benchmarks/Spawns.hs+6−5 benchmarks/Throughput.hs+6−5 distributed-process-tests/distributed-process-tests.cabal+26−12 distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+375−221 distributed-process-tests/src/Control/Distributed/Process/Tests/Closure.hs+84−45 distributed-process-tests/src/Control/Distributed/Process/Tests/Internal/Utils.hs+11−3 distributed-process-tests/src/Control/Distributed/Process/Tests/Mx.hs+167−20 distributed-process-tests/src/Control/Distributed/Process/Tests/Receive.hs+7−8 distributed-process-tests/src/Control/Distributed/Process/Tests/Stats.hs+11−7 distributed-process-tests/src/Control/Distributed/Process/Tests/Tracing.hs+23−11 distributed-process-tests/tests/runInMemory.hs−1 distributed-process-tests/tests/runTCP.hs+2−2 distributed-process.cabal+1−1 src/Control/Distributed/Process/Internal/Primitives.hs+6−2 src/Control/Distributed/Process/Management/Internal/Trace/Primitives.hs+8−2 src/Control/Distributed/Process/Management/Internal/Types.hs+2 src/Control/Distributed/Process/Node.hs+23−9 stack-ghc-7.10.3.yaml+5−1 stack-ghc-8.0.2.yaml+8−2 stack-ghc-8.2.2.yaml+21 stack-ghc-8.4.4.yaml+20 stack-nightly.yaml+26 stack.yaml+7−2
.travis.yml+11−6
@@ -6,11 +6,11 @@ matrix:
66 include:
77 - env: ARGS="--stack-yaml stack-ghc-7.10.3.yaml"
88 addons: {apt: {packages: [libgmp-dev]}}
9−
10− - env: ARGS="--stack-yaml stack-ghc-8.0.2.yaml"
9+ - env: ARGS="--stack-yaml stack-ghc-8.2.2.yaml"
1110 addons: {apt: {packages: [libgmp-dev]}}
12−
13− - env: ARGS=
11+ - env: ARGS="--stack-yaml stack-ghc-8.4.4.yaml"
12+ addons: {apt: {packages: [libgmp-dev]}}
13+ - env: ARGS="--stack-yaml stack-nightly.yaml --resolver nightly"
1414 addons: {apt: {packages: [libgmp-dev]}}
1515
1616cache:
@@ -34,5 +34,10 @@ script:
3434- stack ${ARGS} test $ARG='--plain -t "!Flaky"' ${TEST_PACKAGE}TestCHInTCP
3535- stack ${ARGS} test $ARG='--plain -t "!SpawnReconnect"' ${TEST_PACKAGE}TestClosure
3636- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestStats
37−- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMx
38−- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestTracing
37+- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMxInMemory
38+- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMxInTCP
39+- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestTracingInMemory
40+
41+notifications:
42+ slack:
43+ secure: LbqbNjK1KiHNiQo/i/Za4vkMD9l9mhmN+PWYFBQkNvGFWffSRayRKFrTqt4znV2p7h4dY1XZFoC7T5RemBVQLq2ppZAUWxkITeu1OUlnmVLDfJLeVYGTR/fn90nP6Y5ITE7T3A07nKmWaRbKpIgFBAOjzgqaM0csscDx3z0WW18=
benchmarks/Channels.hs+6−5
@@ -4,7 +4,7 @@ import Control.Monad
44import Control.Applicative
55import Control.Distributed.Process
66import Control.Distributed.Process.Node
7−import Network.Transport.TCP (createTransport, defaultTCPParameters)
7+import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
88import Data.Binary (encode, decode)
99import qualified Data.ByteString.Lazy as BSL
1010
@@ -36,7 +36,8 @@ initialProcess "CLIENT" = do
3636main :: IO ()
3737main = do
3838 [role, host, port] <- getArgs
39− Right transport <- createTransport
40− host port (\sn -> (host, port)) defaultTCPParameters
41− node <- newLocalNode transport initRemoteTable
42− runProcess node $ initialProcess role
39+ trans <- createTransport (defaultTCPAddr host port) defaultTCPParameters
40+ case trans of
41+ Right transport -> do node <- newLocalNode transport initRemoteTable
42+ runProcess node $ initialProcess role
43+ Left other -> error $ show other
benchmarks/Latency.hs+7−5
@@ -3,7 +3,7 @@ import Control.Monad
33import Control.Applicative
44import Control.Distributed.Process
55import Control.Distributed.Process.Node
6−import Network.Transport.TCP (createTransport, defaultTCPParameters)
6+import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
77import Data.Binary (encode, decode)
88import qualified Data.ByteString.Lazy as BSL
99
@@ -31,7 +31,9 @@ initialProcess "CLIENT" = do
3131main :: IO ()
3232main = do
3333 [role, host, port] <- getArgs
34− Right transport <- createTransport
35− host port (\sn -> (host, sn)) defaultTCPParameters
36− node <- newLocalNode transport initRemoteTable
37− runProcess node $ initialProcess role
34+ trans <- createTransport
35+ (defaultTCPAddr host port) defaultTCPParameters
36+ case trans of
37+ Right transport -> do node <- newLocalNode transport initRemoteTable
38+ runProcess node $ initialProcess role
39+ Left other -> error $ show other
benchmarks/ProcessRing.hs+2−2
@@ -12,7 +12,7 @@ import Control.Monad
1212import Control.Distributed.Process hiding (catch)
1313import Control.Distributed.Process.Node
1414import Control.Exception (catch, SomeException)
15−import Network.Transport.TCP (createTransport, defaultTCPParameters)
15+import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
1616import System.Environment
1717import System.Console.GetOpt
1818
@@ -111,7 +111,7 @@ main = do
111111 (opt, _) <- parseArgv argv
112112 putStrLn $ "options: " ++ (show opt)
113113 Right transport <- createTransport
114− "127.0.0.1" "8090" (\sn -> ("127.0.0.1", sn)) defaultTCPParameters
114+ (defaultTCPAddr "127.0.0.1" "8090" ) defaultTCPParameters
115115 node <- newLocalNode transport initRemoteTable
116116 catch (void $ runProcess node $ initialProcess opt)
117117 (\(e :: SomeException) -> putStrLn $ "ERROR: " ++ (show e))
benchmarks/Spawns.hs+6−5
@@ -7,7 +7,7 @@ import Control.Monad
77import Control.Applicative
88import Control.Distributed.Process
99import Control.Distributed.Process.Node
10−import Network.Transport.TCP (createTransport, defaultTCPParameters)
10+import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
1111import Data.Binary (encode, decode)
1212import qualified Data.ByteString.Lazy as BSL
1313
@@ -42,7 +42,8 @@ initialProcess "CLIENT" = do
4242main :: IO ()
4343main = do
4444 [role, host, port] <- getArgs
45− Right transport <- createTransport
46− host port (\sn -> (host, sn)) defaultTCPParameters
47− node <- newLocalNode transport initRemoteTable
48− runProcess node $ initialProcess role
45+ trans <- createTransport (defaultTCPAddr host port) defaultTCPParameters
46+ case trans of
47+ Right transport -> do node <- newLocalNode transport initRemoteTable
48+ runProcess node $ initialProcess role
49+ Left other -> error $ show other
benchmarks/Throughput.hs+6−5
@@ -6,7 +6,7 @@ import Control.Monad
66import Control.Applicative
77import Control.Distributed.Process
88import Control.Distributed.Process.Node
9−import Network.Transport.TCP (createTransport, defaultTCPParameters)
9+import Network.Transport.TCP (createTransport, defaultTCPParameters, defaultTCPAddr)
1010import Data.Binary
1111import qualified Data.ByteString.Lazy as BSL
1212import Data.Typeable
@@ -67,7 +67,8 @@ initialProcess "CLIENT" = do
6767main :: IO ()
6868main = do
6969 [role, host, port] <- getArgs
70− Right transport <- createTransport
71− host port (\sn -> (host, sn)) defaultTCPParameters
72− node <- newLocalNode transport initRemoteTable
73− runProcess node $ initialProcess role
70+ trans <- createTransport (defaultTCPAddr host port) defaultTCPParameters
71+ case trans of
72+ Right transport -> do node <- newLocalNode transport initRemoteTable
73+ runProcess node $ initialProcess role
74+ Left other -> error $ show other
distributed-process-tests/distributed-process-tests.cabal+26−12
@@ -31,9 +31,10 @@ library
3131 bytestring >= 0.9 && < 0.12,
3232 distributed-process >= 0.6.0 && < 0.8,
3333 distributed-static,
34+ exceptions >= 0.5,
3435 HUnit >= 1.2 && < 1.7,
3536 network-transport >= 0.4.1.0 && < 0.6,
36− network >= 2.5 && < 2.7,
37+ network >= 2.5 && < 2.9,
3738 random >= 1.0 && < 1.2,
3839 rematch >= 0.1.2.1,
3940 setenv >= 0.1.1.3,
@@ -60,7 +61,7 @@ Test-Suite TestCHInMemory
6061 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.CH
6162 Build-Depends: base >= 4.4 && < 5,
6263 distributed-process-tests,
63− network >= 2.3 && < 2.7,
64+ network >= 2.3 && < 2.9,
6465 network-transport >= 0.4.1.0 && < 0.6,
6566 network-transport-inmemory >= 0.5,
6667 test-framework >= 0.6 && < 0.9
@@ -75,7 +76,7 @@ Test-Suite TestCHInTCP
7576 if flag(tcp)
7677 Build-Depends: base >= 4.4 && < 5,
7778 distributed-process-tests,
78− network >= 2.3 && < 2.7,
79+ network >= 2.3 && < 2.9,
7980 network-transport >= 0.4.1.0 && < 0.6,
8081 network-transport-tcp >= 0.5 && < 0.7,
8182 test-framework >= 0.6 && < 0.9
@@ -92,7 +93,7 @@ Test-Suite TestClosure
9293 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Closure
9394 Build-Depends: base >= 4.4 && < 5,
9495 distributed-process-tests,
95− network >= 2.3 && < 2.7,
96+ network >= 2.3 && < 2.9,
9697 network-transport >= 0.4.1.0 && < 0.6,
9798 network-transport-inmemory >= 0.5,
9899 test-framework >= 0.6 && < 0.9
@@ -106,7 +107,7 @@ Test-Suite TestStats
106107 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Stats
107108 Build-Depends: base >= 4.4 && < 5,
108109 distributed-process-tests,
109− network >= 2.3 && < 2.7,
110+ network >= 2.3 && < 2.9,
110111 network-transport >= 0.4.1.0 && < 0.6,
111112 network-transport-inmemory >= 0.5,
112113 test-framework >= 0.6 && < 0.9
@@ -114,31 +115,44 @@ Test-Suite TestStats
114115 ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
115116 HS-Source-Dirs: tests
116117
117−
118−Test-Suite TestMx
118+Test-Suite TestMxInMemory
119119 Type: exitcode-stdio-1.0
120120 Main-Is: runInMemory.hs
121121 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
122122 Build-Depends: base >= 4.4 && < 5,
123123 distributed-process-tests,
124− network >= 2.3 && < 2.7,
124+ network >= 2.3 && < 2.9,
125125 network-transport >= 0.4.1.0 && < 0.6,
126126 network-transport-inmemory >= 0.5,
127127 test-framework >= 0.6 && < 0.9
128128 Extensions: CPP
129− ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
129+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
130130 HS-Source-Dirs: tests
131131
132−Test-Suite TestTracing
132+Test-Suite TestTracingInMemory
133133 Type: exitcode-stdio-1.0
134134 Main-Is: runInMemory.hs
135135 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Tracing
136136 Build-Depends: base >= 4.4 && < 5,
137137 distributed-process-tests,
138− network >= 2.3 && < 2.7,
138+ network >= 2.3 && < 2.9,
139139 network-transport >= 0.4.1.0 && < 0.6,
140140 network-transport-inmemory >= 0.5,
141141 test-framework >= 0.6 && < 0.9
142142 Extensions: CPP
143− ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
143+ ghc-options: -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
144+ HS-Source-Dirs: tests
145+
146+Test-Suite TestMxInTCP
147+ Type: exitcode-stdio-1.0
148+ Main-Is: runInMemory.hs
149+ CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
150+ Build-Depends: base >= 4.4 && < 5,
151+ distributed-process-tests,
152+ network >= 2.3 && < 2.9,
153+ network-transport >= 0.4.1.0 && < 0.6,
154+ network-transport-inmemory >= 0.5,
155+ test-framework >= 0.6 && < 0.9
156+ Extensions: CPP
157+ ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
144158 HS-Source-Dirs: tests
distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+375−221
@@ -25,21 +25,29 @@ import Control.Concurrent.MVar
2525 )
2626import Control.Monad (replicateM_, replicateM, forever, void, unless, join)
2727import Control.Exception (SomeException, throwIO, ErrorCall(..))
28−import qualified Control.Exception as Ex (catch)
29−import Control.Applicative ((<$>), (<*>), pure, (<|>))
28+import Control.Monad.Catch (try, catch, finally, mask, onException)
29+import Control.Applicative ((<|>))
3030import qualified Network.Transport as NT (closeEndPoint, EndPointAddress)
31−import Control.Distributed.Process
31+import Control.Distributed.Process hiding
32+ ( try
33+ , catch
34+ , finally
35+ , mask
36+ , onException
37+ )
3238import Control.Distributed.Process.Internal.Types
33− ( NodeId(nodeAddress)
34− , LocalNode(localEndPoint)
39+ ( LocalNode(localEndPoint)
3540 , ProcessExitException(..)
3641 , nullProcessId
3742 , createUnencodedMessage
3843 )
3944import Control.Distributed.Process.Node
45+import Control.Distributed.Process.Debug
46+import Control.Distributed.Process.Management.Internal.Types
47+import Control.Distributed.Process.Tests.Internal.Utils (shouldBe)
4048import Control.Distributed.Process.Serializable (Serializable)
4149
42−import Test.HUnit (Assertion, assertFailure)
50+import Test.HUnit (Assertion, assertBool, assertFailure)
4351import Test.Framework (Test, testGroup)
4452import Test.Framework.Providers.HUnit (testCase)
4553import Control.Rematch hiding (match)
@@ -65,7 +73,7 @@ expectThat a matcher = case res of
6573forkTry :: IO () -> IO ThreadId
6674forkTry p = do
6775 tid <- myThreadId
68− forkIO $ Ex.catch p (\e -> throwTo tid (e :: SomeException))
76+ forkIO $ catch p (\e -> throwTo tid (e :: SomeException))
6977
7078-- | The ping server from the paper
7179ping :: Process ()
@@ -75,12 +83,47 @@ ping = do
7583 send partner (Ping self)
7684 ping
7785
86+verifyClient :: String -> MVar Bool -> IO ()
87+verifyClient s b = takeMVar b >>= assertBool s
88+
89+expectPing :: MVar Bool -> Process ()
90+expectPing mv = expect >>= liftIO . putMVar mv . checkPing
91+ where
92+ checkPing (Ping _) = True
93+ checkPing _ = False
94+
7895-- | Quick and dirty synchronous version of whereisRemoteAsync
7996whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
8097whereisRemote nid string = do
8198 whereisRemoteAsync nid string
82− WhereIsReply _ mPid <- expect
83− return mPid
99+ receiveWait [
100+ match (\(WhereIsReply _ mPid) -> return mPid)
101+ ]
102+
103+verifyWhereIsRemote :: NodeId -> String -> Process ProcessId
104+verifyWhereIsRemote n s = whereisRemote n s >>= maybe (die "remote name not found") return
105+
106+waitForExit :: ProcessId -> Process DiedReason
107+waitForExit pid = monitor pid >>= waitForDown
108+
109+waitForDown :: MonitorRef -> Process DiedReason
110+waitForDown ref =
111+ receiveWait [ matchIf (\(ProcessMonitorNotification ref' _ _) -> ref == ref')
112+ (\(ProcessMonitorNotification _ _ dr) -> return dr) ]
113+
114+syncBreakConnection :: (NT.EndPointAddress -> NT.EndPointAddress -> IO ()) -> LocalNode -> LocalNode -> IO ()
115+syncBreakConnection breakConnection nid0 nid1 = do
116+ m <- newEmptyMVar
117+ _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
118+ runProcess nid0 $ do
119+ them <- liftIO $ takeMVar m
120+ pinger <- spawnLocal $ forever $ send them ()
121+ _ <- monitorNode (localNodeId nid1)
122+ liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
123+ (nodeAddress $ localNodeId nid1)
124+ NodeMonitorNotification _ _ _ <- expect
125+ kill pinger "finished"
126+ return ()
84127
85128data Add = Add ProcessId Double Double deriving (Typeable)
86129data Divide = Divide ProcessId Double Double deriving (Typeable)
@@ -155,12 +198,18 @@ monitorTestProcess theirAddr mOrL un reason monitorSetup done =
155198 unmonitor ref
156199 liftIO $ putMVar done ()
157200 (False, ref) -> do
158− ProcessMonitorNotification ref' pid reason' <- expect
159− True <- return $ Just ref' == ref && pid == theirAddr && mOrL && reason == reason'
160− liftIO $ putMVar done ()
201+ receiveWait [
202+ match (\(ProcessMonitorNotification ref' pid reason') -> do
203+ liftIO $ do
204+ assertBool "Bad Monitor Signal"
205+ (Just ref' == ref && pid == theirAddr &&
206+ mOrL && reason == reason')
207+ putMVar done ())
208+ ]
161209 )
162210 (\(ProcessLinkException pid reason') -> do
163− True <- return $ pid == theirAddr && not mOrL && not un && reason == reason'
211+ (liftIO $ assertBool "link exception unmatched" $
212+ pid == theirAddr && not mOrL && not un && reason == reason')
164213 liftIO $ putMVar done ()
165214 )
166215
@@ -191,8 +240,10 @@ testPing TestTransport{..} = do
191240 pid <- getSelfPid
192241 replicateM_ numPings $ do
193242 send pingServer (Pong pid)
194− Ping _ <- expect
195− return ()
243+ p <- expect
244+ case p of
245+ Ping _ -> return ()
246+ _ -> die "Unexpected message"
196247
197248 putMVar clientDone ()
198249
@@ -279,7 +330,7 @@ testMonitorLocalDeadProcess TestTransport{..} mOrL un = do
279330 runProcess localNode $ do
280331 monitor theirAddr
281332 -- wait for the process to die
282− ProcessMonitorNotification _ _ _ <- expect
333+ expect :: Process ProcessMonitorNotification
283334 monitorTestProcess theirAddr mOrL un DiedUnknownId Nothing done
284335
285336 takeMVar done
@@ -353,14 +404,17 @@ testMath TestTransport{..} = do
353404 runProcess localNode $ do
354405 pid <- getSelfPid
355406 send mathServer (Add pid 1 2)
356− 3 <- expect :: Process Double
407+ three <- expect :: Process Double
357408 send mathServer (Divide pid 8 2)
358− 4 <- expect :: Process Double
409+ four <- expect :: Process Double
359410 send mathServer (Divide pid 8 0)
360− DivByZero <- expect
361− liftIO $ putMVar clientDone ()
411+ divByZ <- expect
412+ liftIO $ putMVar clientDone (three, four, divByZ)
362413
363− takeMVar clientDone
414+ res <- takeMVar clientDone
415+ case res of
416+ (3, 4, DivByZero) -> return ()
417+ _ -> error $ "Something went horribly wrong"
364418
365419-- | Send first message (i.e. connect) to an already terminated process
366420-- (without monitoring); then send another message to a second process on
@@ -388,11 +442,9 @@ testSendToTerminated TestTransport{..} = do
388442 pid <- getSelfPid
389443 send server1 "Hi"
390444 send server2 (Pong pid)
391− Ping pid' <- expect
392− True <- return $ pid' == server2
393− liftIO $ putMVar clientDone ()
445+ expectPing clientDone
394446
395− takeMVar clientDone
447+ verifyClient "Expected Ping from server" clientDone
396448
397449-- | Test (non-zero) timeout
398450testTimeout :: TestTransport -> Assertion
@@ -401,10 +453,10 @@ testTimeout TestTransport{..} = do
401453 done <- newEmptyMVar
402454
403455 runProcess localNode $ do
404− Nothing <- receiveTimeout 1000000 [match (\(Add _ _ _) -> return ())]
405− liftIO $ putMVar done ()
456+ res <- receiveTimeout 1000000 [match (\Add{} -> return ())]
457+ liftIO $ putMVar done $ res == Nothing
406458
407− takeMVar done
459+ verifyClient "Expected receiveTimeout to timeout..." done
408460
409461-- | Test zero timeout
410462testTimeout0 :: TestTransport -> Assertion
@@ -432,10 +484,9 @@ testTimeout0 TestTransport{..} = do
432484 -- is not interested in, and then a single message that it wants
433485 replicateM_ 10000 $ send server "Irrelevant message"
434486 send server (Pong pid)
435− Ping _ <- expect
436− liftIO $ putMVar clientDone ()
487+ expectPing clientDone
437488
438− takeMVar clientDone
489+ verifyClient "Expected Ping from server" clientDone
439490
440491-- | Test typed channels
441492testTypedChannels :: TestTransport -> Assertion
@@ -458,10 +509,10 @@ testTypedChannels TestTransport{..} = do
458509 runProcess localNode $ do
459510 (clientSendPort, rport) <- newChan
460511 sendChan serverSendPort (clientSendPort, 5)
461− False <- receiveChan rport
462− liftIO $ putMVar clientDone ()
512+ ch <- receiveChan rport
513+ liftIO $ putMVar clientDone $ ch == False
463514
464− takeMVar clientDone
515+ verifyClient "Expected channel to send 'False'" clientDone
465516
466517-- | Test merging receive ports
467518testMergeChannels :: TestTransport -> Assertion
@@ -484,9 +535,8 @@ testMergeChannels TestTransport{..} = do
484535 rs <- mapM charChannel "abc"
485536 m <- mergePorts biased rs
486537 xs <- replicateM 9 $ receiveChan m
487− True <- return $ xs == expected
488− liftIO $ putMVar done ()
489− takeMVar done
538+ liftIO $ putMVar done $ xs == expected
539+ verifyClient "Expected single layer merge to match expected ordering" done
490540
491541 -- Two layers of merging
492542 testNested :: LocalNode -> Bool -> Bool -> String -> IO ()
@@ -497,9 +547,8 @@ testMergeChannels TestTransport{..} = do
497547 ms <- mapM (mergePorts biasedInner) rss
498548 m <- mergePorts biasedOuter ms
499549 xs <- replicateM (9 * 3) $ receiveChan m
500− True <- return $ xs == expected
501− liftIO $ putMVar done ()
502− takeMVar done
550+ liftIO $ putMVar done $ xs == expected
551+ verifyClient "Expected nested channels to match expeted ordering" done
503552
504553 -- Test that if no messages are (immediately) available, the scheduler makes no difference
505554 testBlocked :: LocalNode -> Bool -> IO ()
@@ -508,43 +557,45 @@ testMergeChannels TestTransport{..} = do
508557 done <- newEmptyMVar
509558
510559 forkProcess localNode $ do
511− [sa, sb, sc] <- liftIO $ mapM readMVar vs
512− mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
513− [ -- a, b, c
514− (sa, 'a')
515− , (sb, 'b')
516− , (sc, 'c')
517− -- a, c, b
518− , (sa, 'a')
519− , (sc, 'c')
520− , (sb, 'b')
521− -- b, a, c
522− , (sb, 'b')
523− , (sa, 'a')
524− , (sc, 'c')
525− -- b, c, a
526− , (sb, 'b')
527− , (sc, 'c')
528− , (sa, 'a')
529− -- c, a, b
530− , (sc, 'c')
531− , (sa, 'a')
532− , (sb, 'b')
533− -- c, b, a
534− , (sc, 'c')
535− , (sb, 'b')
536− , (sa, 'a')
537− ]
560+ ss <- liftIO $ mapM readMVar vs
561+ case ss of
562+ [sa, sb, sc] ->
563+ mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
564+ [ -- a, b, c
565+ (sa, 'a')
566+ , (sb, 'b')
567+ , (sc, 'c')
568+ -- a, c, b
569+ , (sa, 'a')
570+ , (sc, 'c')
571+ , (sb, 'b')
572+ -- b, a, c
573+ , (sb, 'b')
574+ , (sa, 'a')
575+ , (sc, 'c')
576+ -- b, c, a
577+ , (sb, 'b')
578+ , (sc, 'c')
579+ , (sa, 'a')
580+ -- c, a, b
581+ , (sc, 'c')
582+ , (sa, 'a')
583+ , (sb, 'b')
584+ -- c, b, a
585+ , (sc, 'c')
586+ , (sb, 'b')
587+ , (sa, 'a')
588+ ]
589+ _ -> die "Something went horribly wrong"
538590
539591 forkProcess localNode $ do
540592 (ss, rs) <- unzip <$> replicateM 3 newChan
541593 liftIO $ mapM_ (uncurry putMVar) $ zip vs ss
542594 m <- mergePorts biased rs
543595 xs <- replicateM (6 * 3) $ receiveChan m
544− True <- return $ xs == "abcacbbacbcacabcba"
545− liftIO $ putMVar done ()
596+ liftIO $ putMVar done $ xs == "abcacbbacbcacabcba"
546597
547− takeMVar done
598+ verifyClient "Expected merged ports to match expected ordering" done
548599
549600 mergePorts :: Serializable a => Bool -> [ReceivePort a] -> Process (ReceivePort a)
550601 mergePorts True = mergePortsBiased
@@ -562,8 +613,9 @@ testTerminate TestTransport{..} = do
562613 localNode <- newLocalNode testTransport initRemoteTable
563614 runProcess localNode $ do
564615 e <- try terminate :: Process (Either ProcessTerminationException ())
565− True <- return $ either show show e == show ProcessTerminationException
566− return ()
616+ if either show show e == show ProcessTerminationException
617+ then return ()
618+ else die "Unexpected result from terminate"
567619
568620testMonitorNode :: TestTransport -> Assertion
569621testMonitorNode TestTransport{..} = do
@@ -574,11 +626,12 @@ testMonitorNode TestTransport{..} = do
574626
575627 runProcess node2 $ do
576628 ref <- monitorNode (localNodeId node1)
577− NodeMonitorNotification ref' nid DiedDisconnect <- expect
578− True <- return $ ref == ref' && nid == localNodeId node1
579− liftIO $ putMVar done ()
629+ receiveWait [
630+ match (\(NodeMonitorNotification ref' nid DiedDisconnect) ->
631+ return $ ref == ref' && nid == localNodeId node1)
632+ ] >>= liftIO . putMVar done
580633
581− takeMVar done
634+ verifyClient "Expected NodeMonitorNotification with matching ref & nodeId" done
582635
583636testMonitorLiveNode :: TestTransport -> Assertion
584637testMonitorLiveNode TestTransport{..} = do
@@ -593,15 +646,16 @@ testMonitorLiveNode TestTransport{..} = do
593646 liftIO $ putMVar ready ()
594647 liftIO $ takeMVar readyr
595648 send p ()
596− NodeMonitorNotification ref' nid _ <- expect
597− True <- return $ ref == ref' && nid == localNodeId node1
598− liftIO $ putMVar done ()
649+ receiveWait [
650+ match (\(NodeMonitorNotification ref' nid _) ->
651+ (return $ ref == ref' && nid == localNodeId node1))
652+ ] >>= liftIO . putMVar done
599653
600654 takeMVar ready
601655 closeLocalNode node1
602656 putMVar readyr ()
603657
604− takeMVar done
658+ verifyClient "Expected NodeMonitorNotification for LIVE node" done
605659
606660testMonitorChannel :: TestTransport -> Assertion
607661testMonitorChannel TestTransport{..} = do
@@ -611,18 +665,20 @@ testMonitorChannel TestTransport{..} = do
611665 pid <- forkProcess node1 $ do
612666 sport <- expect :: Process (SendPort ())
613667 ref <- monitorPort sport
614− PortMonitorNotification ref' port' reason <- expect
615− -- reason might be DiedUnknownId if the receive port is GCed before the
616− -- monitor is established (TODO: not sure that this is reasonable)
617− return $ ref' == ref && port' == sendPortId sport && (reason == DiedNormal || reason == DiedUnknownId)
618− liftIO $ putMVar gotNotification ()
668+ receiveWait [
669+ -- reason might be DiedUnknownId if the receive port is GCed before the
670+ -- monitor is established (TODO: not sure that this is reasonable)
671+ match (\(PortMonitorNotification ref' port' reason) ->
672+ return $ ref' == ref && port' == sendPortId sport &&
673+ (reason == DiedNormal || reason == DiedUnknownId))
674+ ] >>= liftIO . putMVar gotNotification
619675
620676 runProcess node2 $ do
621677 (sport, _) <- newChan :: Process (SendPort (), ReceivePort ())
622678 send pid sport
623679 liftIO $ threadDelay 100000
624680
625− takeMVar gotNotification
681+ verifyClient "Expected PortMonitorNotification" gotNotification
626682
627683testRegistry :: TestTransport -> Assertion
628684testRegistry TestTransport{..} = do
@@ -634,20 +690,28 @@ testRegistry TestTransport{..} = do
634690
635691 runProcess node $ do
636692 register "ping" pingServer
637− Just pid <- whereis "ping"
638− True <- return $ pingServer == pid
693+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
639694 us <- getSelfPid
640695 nsend "ping" (Pong us)
641− Ping pid' <- expect
642− True <- return $ pingServer == pid'
643− Left (ProcessRegistrationException "dead" Nothing) <- try $ register "dead" deadProcess
644− Left (ProcessRegistrationException "ping" (Just x)) <- try $ register "ping" deadProcess
645− True <- return $ x == pingServer
646− Left (ProcessRegistrationException "dead" Nothing) <- try $ unregister "dead"
696+ receiveWait [
697+ matchIf (\(Ping pid') -> pingServer == pid') (const $ return ())
698+ ]
699+ checkRegException "dead" Nothing deadProcess
700+ checkRegException "ping" (Just pingServer) deadProcess
701+ try (unregister "dead") >>= checkReg "dead" Nothing
647702 liftIO $ putMVar done ()
648703
649704 takeMVar done
650705
706+ where
707+ checkRegException name pid dead =
708+ try (register name dead) >>= checkReg name pid
709+
710+ checkReg name pid res =
711+ case res of
712+ Left (ProcessRegistrationException name pid) -> return ()
713+ _ -> die $ "Unexpected Registration" ++ show res
714+
651715testRegistryRemoteProcess :: TestTransport -> Assertion
652716testRegistryRemoteProcess TestTransport{..} = do
653717 node1 <- newLocalNode testTransport initRemoteTable
@@ -658,13 +722,13 @@ testRegistryRemoteProcess TestTransport{..} = do
658722
659723 runProcess node2 $ do
660724 register "ping" pingServer
661− Just pid <- whereis "ping"
662− True <- return $ pingServer == pid
725+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
663726 us <- getSelfPid
664727 nsend "ping" (Pong us)
665− Ping pid' <- expect
666− True <- return $ pingServer == pid'
667− liftIO $ putMVar done ()
728+ receiveWait [
729+ matchIf (\(Ping pid') -> pingServer == pid')
730+ (const $ liftIO $ putMVar done ())
731+ ]
668732
669733 takeMVar done
670734
@@ -685,12 +749,13 @@ testRemoteRegistry TestTransport{..} = do
685749 "ping" == label' && pid == pingServer)
686750 (\(RegisterReply _ _ _) -> return ()) ]
687751
688− Just pid <- whereisRemote nid1 "ping"
689− True <- return $ pingServer == pid
752+ pid <- verifyWhereIsRemote nid1 "ping"
753+ liftIO $ assertBool "Expected pindServer to match pid" $ pingServer == pid
690754 us <- getSelfPid
691755 nsendRemote nid1 "ping" (Pong us)
692− Ping pid' <- expect
693− True <- return $ pingServer == pid'
756+ receiveWait [
757+ match (\(Ping pid') -> return $ pingServer == pid')
758+ ] >>= liftIO . assertBool "Expected Ping with ping server's ProcessId"
694759
695760 -- test that if process was not registered Nothing is returned
696761 -- in owner field.
@@ -700,8 +765,8 @@ testRemoteRegistry TestTransport{..} = do
700765 (\(RegisterReply _ _ _) -> return ()) ]
701766 registerRemoteAsync nid1 "ping" deadProcess
702767 receiveWait [
703− matchIf (\(RegisterReply label' False (Just pid)) ->
704− "ping" == label' && pid == pingServer)
768+ matchIf (\(RegisterReply label' False (Just pid'')) ->
769+ "ping" == label' && pid'' == pingServer)
705770 (\(RegisterReply _ _ _) -> return ()) ]
706771 unregisterRemoteAsync nid1 "dead"
707772 receiveWait [
@@ -726,15 +791,15 @@ testRemoteRegistryRemoteProcess TestTransport{..} = do
726791 receiveWait [
727792 matchIf (\(RegisterReply label' _ _) -> "ping" == label')
728793 (\(RegisterReply _ _ _) -> return ()) ]
729− Just pid <- whereisRemote nid1 "ping"
730− True <- return $ pingServer == pid
794+ pid <- verifyWhereIsRemote nid1 "ping"
795+ liftIO $ assertBool "Expected pingServer to match remote name" $ pingServer == pid
731796 us <- getSelfPid
732797 nsendRemote nid1 "ping" (Pong us)
733− Ping pid' <- expect
734− True <- return $ pingServer == pid'
735− liftIO $ putMVar done ()
798+ receiveWait [
799+ match (\(Ping pid') -> return $ pingServer == pid')
800+ ] >>= liftIO . putMVar done
736801
737− takeMVar done
802+ verifyClient "Expected Ping with ping server's ProcessId" done
738803
739804testSpawnLocal :: TestTransport -> Assertion
740805testSpawnLocal TestTransport{..} = do
@@ -748,15 +813,14 @@ testSpawnLocal TestTransport{..} = do
748813 sport <- expect
749814 sendChan sport (1234 :: Int)
750815
751− sport <- spawnChannelLocal $ \rport -> do
752− (1234 :: Int) <- receiveChan rport
753− send us ()
816+ sport <- spawnChannelLocal $
817+ \rport -> (receiveChan rport :: Process Int) >>= send us
754818
755819 send pid sport
756− () <- expect
757− liftIO $ putMVar done ()
820+ expect >>= liftIO . putMVar done
758821
759− takeMVar done
822+ res <- takeMVar done
823+ assertBool "Expected 1234 :: Int" $ res == (1234 :: Int)
760824
761825testSpawnAsyncStrictness :: TestTransport -> Assertion
762826testSpawnAsyncStrictness TestTransport{..} = do
@@ -785,8 +849,9 @@ testReconnect TestTransport{..} = do
785849 liftIO $ putMVar processA us
786850 msg1 <- expect
787851 msg2 <- expect
788− True <- return $ msg1 == "message 1" && msg2 == "message 3"
789− liftIO $ putMVar sendTestOk ()
852+ liftIO $ do
853+ assertBool "messages did not match" $ msg1 == "message 1" && msg2 == "message 3"
854+ putMVar sendTestOk ()
790855
791856 forkProcess node2 $ do
792857 {-
@@ -819,7 +884,7 @@ testReconnect TestTransport{..} = do
819884 matchIf (\(RegisterReply label' _ _) -> "a" == label')
820885 (\(RegisterReply _ _ _) -> return ()) ]
821886
822− Just _ <- whereisRemote nid1 "a"
887+ _ <- whereisRemote nid1 "a"
823888
824889
825890 -- Simulate network failure
@@ -838,9 +903,10 @@ testReconnect TestTransport{..} = do
838903 (\(RegisterReply _ _ _) -> return ()) ]
839904
840905 -- Check
841− Nothing <- whereisRemote nid1 "a" -- this will fail because the name is removed when the node is disconnected
842− Just _ <- whereisRemote nid1 "b" -- this will suceed because the value is set after thereconnect
843− Just _ <- whereisRemote nid1 "c"
906+ mPid <- whereisRemote nid1 "a" -- this will fail because the name is removed when the node is disconnected
907+ liftIO $ assertBool "Expected remote name to be lost" $ mPid == Nothing
908+ verifyWhereIsRemote nid1 "b" -- this will suceed because the value is set after thereconnect
909+ verifyWhereIsRemote nid1 "c"
844910
845911 liftIO $ putMVar registerTestOk ()
846912
@@ -881,19 +947,19 @@ testUSend usendPrim TestTransport{..} numMessages = do
881947 isSorted _ = True
882948 -- The list can't be null since there are no failures after sending
883949 -- the last message.
884− True <- return $ isSorted msgs && not (null msgs)
885− liftIO $ putMVar usendTestOk ()
950+ liftIO $ putMVar usendTestOk $ isSorted msgs && not (null msgs)
886951
887952 forkProcess node2 $ do
888953 them <- liftIO $ readMVar processA
889954 getSelfPid >>= send them
890− () <- expect
955+ expect :: Process ()
891956 forM_ [1..numMessages] $ \i -> do
892957 liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
893958 usendPrim them i
894959 liftIO (threadDelay 30000)
895960
896− takeMVar usendTestOk
961+ res <- takeMVar usendTestOk
962+ assertBool "Unexpected failure after sending last msg" res
897963
898964-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
899965-- in between
@@ -919,14 +985,17 @@ testMatchAny TestTransport{..} = do
919985 runProcess localNode $ do
920986 pid <- getSelfPid
921987 send mathServer (Add pid 1 2)
922− 3 <- expect :: Process Double
988+ three <- expect :: Process Double
923989 send mathServer (Divide pid 8 2)
924− 4 <- expect :: Process Double
990+ four <- expect :: Process Double
925991 send mathServer (Divide pid 8 0)
926− DivByZero <- expect
927− liftIO $ putMVar clientDone ()
992+ divByZ <- expect
993+ liftIO $ putMVar clientDone (three, four, divByZ)
928994
929− takeMVar clientDone
995+ res <- takeMVar clientDone
996+ case res of
997+ (3, 4, DivByZero) -> return ()
998+ _ -> error "Unexpected result"
930999
9311000-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
9321001-- in between, however we block 'Divide' requests ....
@@ -953,12 +1022,13 @@ testMatchAnyHandle TestTransport{..} = do
9531022 runProcess localNode $ do
9541023 pid <- getSelfPid
9551024 send mathServer (Add pid 1 2)
956− 3 <- expect :: Process Double
1025+ three <- expect :: Process Double
9571026 send mathServer (Divide pid 8 2)
958− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
959− liftIO $ putMVar clientDone ()
1027+ res <- (expectTimeout 100000) :: Process (Maybe Double)
1028+ liftIO $ putMVar clientDone $ three == 3 && res == Nothing
1029+
1030+ verifyClient "Expected Nothing (i.e. timeout)" clientDone
9601031
961− takeMVar clientDone
9621032 where maybeForward :: ProcessId -> Message -> Process (Maybe ())
9631033 maybeForward s msg =
9641034 handleMessage msg (\m@(Add _ _ _) -> send s m)
@@ -986,8 +1056,10 @@ testMatchAnyNoHandle TestTransport{..} = do
9861056 Just _ -> die "NONSENSE")
9871057 ]
9881058 -- we *must* have removed the message from our mailbox though!!!
989− Nothing <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
990− liftIO $ putMVar serverDone ()
1059+ res <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
1060+ liftIO $ do
1061+ assertBool "Expected timeout!" $ res == Nothing
1062+ putMVar serverDone ()
9911063 putMVar addr server
9921064
9931065 -- Client
@@ -1030,14 +1102,21 @@ testMatchAnyIf TestTransport{..} = do
10301102 runProcess localNode $ do
10311103 pid <- getSelfPid
10321104 send server (pid, "foo")
1033− "foo" <- expect
1034− send server (pid, "baz")
1035− "baz" <- expect
1105+ foo <- expect
1106+ -- provoking what would be the wrong ordering is informative here...
1107+
10361108 send server (pid, "bar")
1037− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
1038− liftIO $ putMVar clientDone ()
1109+ bar <- (expectTimeout 100000) :: Process (Maybe String) -- was Double o_O !?
1110+
1111+ send server (pid, "baz")
1112+ baz <- expect
1113+
1114+ liftIO $ putMVar clientDone (foo, bar, baz)
1115+
1116+ res <- takeMVar clientDone
1117+ let res' = res == ("foo", Nothing, "baz")
1118+ assertBool "Expected timeout due to type mismatch" res'
10391119
1040− takeMVar clientDone
10411120 where tryHandleMessage :: Message -> Process (Maybe ())
10421121 tryHandleMessage msg =
10431122 handleMessage msg (\(pid :: ProcessId, (m :: String))
@@ -1070,12 +1149,13 @@ testMatchMessageWithUnwrap TestTransport{..} = do
10701149 runProcess localNode $ do
10711150 pid <- getSelfPid
10721151 send server (pid, wrapMessage ("foo" :: String))
1073− "foo" <- expect
1152+ foo <- expect
10741153 send server (pid, wrapMessage ("baz" :: String))
1075− "baz" <- expect
1076− liftIO $ putMVar clientDone ()
1154+ baz <- expect
1155+ liftIO $ putMVar clientDone (foo, baz)
10771156
1078− takeMVar clientDone
1157+ res <- takeMVar clientDone
1158+ assertBool "Unexpected unwrapped results" $ res == ("foo", "baz")
10791159
10801160-- Test 'receiveChanTimeout'
10811161testReceiveChanTimeout :: TestTransport -> Assertion
@@ -1093,18 +1173,19 @@ testReceiveChanTimeout TestTransport{..} = do
10931173
10941174 -- Wait for a message with a delay. No message arrives, we should get
10951175 -- Nothing after the delay.
1096− Nothing <- receiveChanTimeout 100000 rp
1176+ receiveChanTimeout 100000 rp >>= maybe (return ()) (const $ die "Expected Timeout")
10971177
10981178 -- Let the sender know that it can send a message.
10991179 liftIO $ putMVar mvSender ()
11001180
11011181 -- Wait for a message with a delay again. Now a message arrives after
11021182 -- 0.1 seconds
1103− Just True <- receiveChanTimeout 20000000 rp
1183+ res <- receiveChanTimeout 20000000 rp >>= maybe (die "Timeout") return
1184+ liftIO $ assertBool "Expected result to be 'True'" res
11041185
11051186 -- Wait for a message with zero timeout: non-blocking check. No message is
11061187 -- available, we get Nothing
1107− Nothing <- receiveChanTimeout 0 rp
1188+ receiveChanTimeout 0 rp >>= maybe (return ()) (const $ die "Expected Timeout")
11081189
11091190 -- Let the sender know that it can send a message.
11101191 liftIO $ putMVar mvSender ()
@@ -1114,7 +1195,7 @@ testReceiveChanTimeout TestTransport{..} = do
11141195 liftIO $ threadDelay 100000
11151196 mb <- receiveChanTimeout 0 rp
11161197 case mb of
1117− Just b -> do False <- return b; return ()
1198+ Just b -> do liftIO $ assertBool "Unexpected Message" $ not b
11181199 _ -> loop
11191200
11201201 liftIO $ putMVar done ()
@@ -1151,8 +1232,8 @@ testReceiveChanFeatures TestTransport{..} = do
11511232
11521233 rp1 <- mergePortsBiased [even <$> rpInt, rpBool]
11531234
1154− True <- receiveChan rp1
1155− False <- receiveChan rp1
1235+ receiveChan rp1 >>= liftIO . assertBool "Expected True"
1236+ receiveChan rp1 >>= liftIO . assertBool "Expected False" . not
11561237
11571238 -- Test Applicative instance
11581239
@@ -1161,7 +1242,7 @@ testReceiveChanFeatures TestTransport{..} = do
11611242
11621243 let rp2 = pure (+) <*> rpInt <*> rpInt
11631244
1164− 7 <- receiveChan rp2
1245+ receiveChan rp2 >>= liftIO . assertBool "Expected 7" . (== 7)
11651246
11661247 -- Test Alternative instance
11671248
@@ -1170,8 +1251,8 @@ testReceiveChanFeatures TestTransport{..} = do
11701251
11711252 let rp3 = (even <$> rpInt) <|> rpBool
11721253
1173− False <- receiveChan rp3
1174− True <- receiveChan rp3
1254+ receiveChan rp3 >>= liftIO . assertBool "Expected False" . not
1255+ receiveChan rp3 >>= liftIO . assertBool "Expected True"
11751256
11761257 -- Test Monad instance
11771258
@@ -1185,8 +1266,8 @@ testReceiveChanFeatures TestTransport{..} = do
11851266 then rpInt
11861267 else return 7
11871268
1188− 5 <- receiveChan rp4
1189− 7 <- receiveChan rp4
1269+ receiveChan rp4 >>= liftIO . assertBool "Expected 5" . (== 5)
1270+ receiveChan rp4 >>= liftIO . assertBool "Expected 7" . (== 7)
11901271
11911272 liftIO $ putMVar done ()
11921273
@@ -1195,7 +1276,6 @@ testReceiveChanFeatures TestTransport{..} = do
11951276testKillLocal :: TestTransport -> Assertion
11961277testKillLocal TestTransport{..} = do
11971278 localNode <- newLocalNode testTransport initRemoteTable
1198− done <- newEmptyMVar
11991279
12001280 pid <- forkProcess localNode $ do
12011281 liftIO $ threadDelay 1000000
@@ -1204,17 +1284,18 @@ testKillLocal TestTransport{..} = do
12041284 ref <- monitor pid
12051285 us <- getSelfPid
12061286 kill pid "TestKill"
1207− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
1208− True <- return $ ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill"
1209− liftIO $ putMVar done ()
1210−
1211− takeMVar done
1287+ mn <- expect
1288+ case mn of
1289+ ProcessMonitorNotification ref' pid' (DiedException ex) ->
1290+ case ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill" of
1291+ True -> return ()
1292+ False -> die "Invalid ProcessMonitorNotification received"
1293+ _ -> die "Something went horribly wrong"
12121294
12131295testKillRemote :: TestTransport -> Assertion
12141296testKillRemote TestTransport{..} = do
12151297 node1 <- newLocalNode testTransport initRemoteTable
12161298 node2 <- newLocalNode testTransport initRemoteTable
1217− done <- newEmptyMVar
12181299
12191300 pid <- forkProcess node1 $ do
12201301 liftIO $ threadDelay 1000000
@@ -1223,11 +1304,17 @@ testKillRemote TestTransport{..} = do
12231304 ref <- monitor pid
12241305 us <- getSelfPid
12251306 kill pid "TestKill"
1226− ProcessMonitorNotification ref' pid' (DiedException reason) <- expect
1227− True <- return $ ref == ref' && pid == pid' && reason == "killed-by=" ++ show us ++ ",reason=TestKill"
1228− liftIO $ putMVar done ()
1229−
1230− takeMVar done
1307+ mn <- expect
1308+ case mn of
1309+ ProcessMonitorNotification ref' pid' (DiedException reason) ->
1310+ case (ref == ref', pid == pid', reason == "killed-by=" ++ show us ++ ",reason=TestKill") of
1311+ (True, True, True) -> return ()
1312+ (a, b, c) -> do
1313+ let a' = if a then "" else "Invalid ref"
1314+ let b' = if b then "" else "Invalid pid"
1315+ let c' = if c then "" else "Invalid message"
1316+ die $ unwords [a', b', c']
1317+ _ -> die "Received unexpected message"
12311318
12321319testCatchesExit :: TestTransport -> Assertion
12331320testCatchesExit TestTransport{..} = do
@@ -1253,7 +1340,10 @@ testHandleMessageIf TestTransport{..} = do
12531340 self <- getSelfPid
12541341 send self (5 :: Integer, 10 :: Integer)
12551342 msg <- receiveWait [ matchMessage return ]
1256− Nothing <- handleMessageIf msg (\() -> True) (\() -> die $ "whoops")
1343+ handleMessageIf msg
1344+ (\() -> True)
1345+ (\() -> die "whoops") >>= maybe (return ())
1346+ (const $ die "Expected Mismatch")
12571347 handleMessageIf msg (\(x :: Integer, y :: Integer) -> x == 5 && y == 10)
12581348 (\input -> liftIO $ putMVar done input)
12591349 return ()
@@ -1298,8 +1388,11 @@ testDie TestTransport{..} = do
12981388 (die ("foobar", 123 :: Int))
12991389 `catchExit` \_from reason -> do
13001390 -- TODO: should verify that 'from' has the right value
1301− True <- return $ reason == ("foobar", 123 :: Int)
1391+ let res = reason == ("foobar", 123 :: Int)
13021392 liftIO $ putMVar done ()
1393+ if res
1394+ then return ()
1395+ else die "Something went horribly wrong"
13031396
13041397 takeMVar done
13051398
@@ -1313,8 +1406,11 @@ testPrettyExit TestTransport{..} = do
13131406 `catch` \ex@(ProcessExitException from _) ->
13141407 let expected = "exit-from=" ++ (show from)
13151408 in do
1316− True <- return $ (show ex) == expected
1409+ let res = (show ex) == expected
13171410 liftIO $ putMVar done ()
1411+ if res
1412+ then return ()
1413+ else die "Something went horribly wrong"
13181414
13191415 takeMVar done
13201416
@@ -1330,17 +1426,26 @@ testExitLocal TestTransport{..} = do
13301426 pid <- forkProcess localNode $ do
13311427 (liftIO (putMVar handlerSetUp ()) >> expect) `catchExit` \_from reason -> do
13321428 -- TODO: should verify that 'from' has the right value
1333− True <- return $ reason == "TestExit"
1429+ res <- return $ reason == "TestExit"
13341430 liftIO $ putMVar supervisedDone ()
1431+ if res
1432+ then return ()
1433+ else die "Something went horribly wrong"
13351434
13361435 runProcess localNode $ do
13371436 liftIO $ takeMVar handlerSetUp
13381437 ref <- monitor pid
13391438 exit pid "TestExit"
13401439 -- This time the client catches the exception, so it dies normally
1341− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1342− True <- return $ ref == ref' && pid == pid'
1343− liftIO $ putMVar supervisorDone ()
1440+ mn <- expect
1441+ case mn of
1442+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1443+ let res = ref == ref' && pid == pid'
1444+ liftIO $ putMVar supervisorDone ()
1445+ if res
1446+ then return ()
1447+ else die "Something went horribly wrong"
1448+ _ -> die "Something went horribly wrong"
13441449
13451450 takeMVar supervisedDone
13461451 takeMVar supervisorDone
@@ -1356,19 +1461,90 @@ testExitRemote TestTransport{..} = do
13561461 (receiveWait [] :: Process ()) -- block forever
13571462 `catchExit` \_from reason -> do
13581463 -- TODO: should verify that 'from' has the right value
1359− True <- return $ reason == "TestExit"
1464+ res <- return $ reason == "TestExit"
13601465 liftIO $ putMVar supervisedDone ()
1466+ if res
1467+ then return ()
1468+ else die "Something went horribly wrong"
13611469
13621470 runProcess node2 $ do
13631471 ref <- monitor pid
13641472 exit pid "TestExit"
1365− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1366− True <- return $ ref == ref' && pid == pid'
1367− liftIO $ putMVar supervisorDone ()
1473+ mn <- expect
1474+ case mn of
1475+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1476+ res' <- return $ ref == ref' && pid == pid'
1477+ liftIO $ putMVar supervisorDone ()
1478+ if res'
1479+ then return ()
1480+ else die "Something went horribly wrong"
1481+ _ -> die "Something went horribly wrong"
13681482
13691483 takeMVar supervisedDone
13701484 takeMVar supervisorDone
13711485
1486+testRegistryMonitoring :: TestTransport -> Assertion
1487+testRegistryMonitoring TestTransport{..} = do
1488+ node1 <- newLocalNode testTransport initRemoteTable
1489+ node2 <- newLocalNode testTransport initRemoteTable
1490+ waitH <- newEmptyMVar
1491+
1492+ let nid = localNodeId node2
1493+ pid <- forkProcess node1 $ do
1494+ getSelfPid >>= runUntilRegistered nid
1495+ liftIO $ takeMVar waitH
1496+
1497+ runProcess node2 $ do
1498+ register regName pid
1499+ res <- whereis regName
1500+ us <- getSelfPid
1501+ liftIO $ do
1502+ putMVar waitH ()
1503+ assertBool "expected (Just pid)" $ res == (Just pid)
1504+
1505+ -- This delay isn't essential!
1506+ -- The test case passes perfectly fine without it (feel free to comment out
1507+ -- and see), however waiting a few seconds here, makes it much more likely
1508+ -- that in delayUntilMaybeUnregistered we will hit the match case right
1509+ -- away, and thus not be subjected to a 20 second delay. The value of 4
1510+ -- seconds appears to work optimally on osx and across several linux distros
1511+ -- running in virtual machines (which is essentially what we do in CI)
1512+ void $ receiveTimeout 4000000 [ matchAny return ]
1513+
1514+ -- This delay doesn't serve much purpose in the happy path, however if some
1515+ -- future patch breaks the cooperative behaviour of node controllers viz
1516+ -- remote process registration and notification taking place via ncEffectDied,
1517+ -- there would be the possibility of a race in the test case should we attempt
1518+ -- to evaluate `whereis regName` on node2 right away. In case the name is still
1519+ -- erroneously registered, observing the 20 second delay (or lack of), could at
1520+ -- least give a hint that something is wrong, and we give up our time slice
1521+ -- so that there's a higher change the registrations have been cleaned up
1522+ -- in either case.
1523+ runProcess node2 $ delayUntilMaybeUnregistered nid pid
1524+
1525+ regHere <- newEmptyMVar
1526+ runProcess node2 $ whereis regName >>= liftIO . putMVar regHere
1527+ res <- takeMVar regHere
1528+ assertBool "expected Nothing, but process still registered" (res == Nothing)
1529+
1530+ where
1531+ runUntilRegistered nid us = do
1532+ whereisRemoteAsync nid regName
1533+ receiveWait [
1534+ matchIf (\(WhereIsReply n (Just p)) -> n == regName && p == us)
1535+ (const $ return ())
1536+ ]
1537+
1538+ delayUntilMaybeUnregistered nid p = do
1539+ whereisRemoteAsync nid regName
1540+ receiveTimeout 20000000 {- 20 sec delay -} [
1541+ matchIf (\(WhereIsReply n p) -> n == regName && p == Nothing)
1542+ (const $ return ())
1543+ ]
1544+ return ()
1545+
1546+ regName = "testRegisterRemote"
1547+
13721548testUnsafeSend :: TestTransport -> Assertion
13731549testUnsafeSend TestTransport{..} = do
13741550 serverAddr <- newEmptyMVar
@@ -1384,8 +1560,7 @@ testUnsafeSend TestTransport{..} = do
13841560 void $ forkProcess localNode $ do
13851561 serverPid <- liftIO $ takeMVar serverAddr
13861562 getSelfPid >>= unsafeSend serverPid
1387− () <- expect
1388− liftIO $ putMVar clientDone ()
1563+ expect >>= liftIO . putMVar clientDone
13891564
13901565 takeMVar clientDone
13911566
@@ -1404,8 +1579,7 @@ testUnsafeUSend TestTransport{..} = do
14041579 void $ forkProcess localNode $ do
14051580 serverPid <- liftIO $ takeMVar serverAddr
14061581 getSelfPid >>= unsafeUSend serverPid
1407− () <- expect
1408− liftIO $ putMVar clientDone ()
1582+ expect >>= liftIO . putMVar clientDone
14091583
14101584 takeMVar clientDone
14111585
@@ -1416,8 +1590,7 @@ testUnsafeNSend TestTransport{..} = do
14161590 localNode <- newLocalNode testTransport initRemoteTable
14171591
14181592 pid <- forkProcess localNode $ do
1419− () <- expect
1420− liftIO $ putMVar clientDone ()
1593+ expect >>= liftIO . putMVar clientDone
14211594
14221595 void $ runProcess localNode $ do
14231596 register "foobar" pid
@@ -1435,8 +1608,7 @@ testUnsafeNSendRemote TestTransport{..} = do
14351608 _ <- forkProcess localNode1 $ do
14361609 getSelfPid >>= register "foobar"
14371610 liftIO $ putMVar clientDone ()
1438− () <- expect
1439− liftIO $ putMVar clientDone ()
1611+ expect >>= liftIO . putMVar clientDone
14401612
14411613 takeMVar clientDone
14421614 void $ runProcess localNode2 $ do
@@ -1460,7 +1632,7 @@ testUnsafeSendChan TestTransport{..} = do
14601632 serverPid <- liftIO $ takeMVar serverAddr
14611633 (sp, rp) <- newChan
14621634 unsafeSend serverPid sp
1463− () <- receiveChan rp
1635+ receiveChan rp :: Process ()
14641636 liftIO $ putMVar clientDone ()
14651637
14661638 takeMVar clientDone
@@ -1474,8 +1646,8 @@ testCallLocal TestTransport{..} = do
14741646 runProcess node $ do
14751647 r <- (/=) <$> getSelfPid <*> callLocal getSelfPid
14761648 liftIO $ putMVar result r
1477− True <- takeMVar result
1478− return ()
1649+
1650+ takeMVar result >>= assertBool "Expected 'True'"
14791651
14801652 -- Testing that when callLocal is interrupted, the worker is interrupted.
14811653 ibox <- newIORef False
@@ -1492,10 +1664,9 @@ testCallLocal TestTransport{..} = do
14921664 (send keeper ())
14931665 caller <- expect
14941666 exit caller "test"
1495− () <- expect
1496− return ()
1497− True <- readIORef ibox
1498− return ()
1667+ expect :: Process ()
1668+
1669+ readIORef ibox >>= assertBool "Expected 'True'"
14991670
15001671 -- Testing that when the worker raises an exception, the exception is propagated to the parent.
15011672 ibox2 <- newIORef False
@@ -1504,8 +1675,8 @@ testCallLocal TestTransport{..} = do
15041675 liftIO $ writeIORef ibox2 $ case r of
15051676 Left (ErrorCall "e") -> True
15061677 _ -> False
1507− True <- readIORef ibox
1508− return ()
1678+
1679+ readIORef ibox >>= assertBool "Expected 'True'"
15091680
15101681 -- Test that caller waits for the worker in correct situation
15111682 ibox3 <- newIORef False
@@ -1522,8 +1693,8 @@ testCallLocal TestTransport{..} = do
15221693 liftIO $ putMVar result3 =<< readIORef ibox3
15231694 worker <- expect
15241695 send worker ()
1525− True <- takeMVar result3
1526− return ()
1696+
1697+ takeMVar result3 >>= assertBool "Expected 'True'"
15271698
15281699 -- Test that caller waits for the worker in case when caller gets an exception
15291700 ibox4 <- newIORef False
@@ -1539,13 +1710,9 @@ testCallLocal TestTransport{..} = do
15391710 `finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
15401711 caller <- expect
15411712 exit caller "hi!"
1542− True <- takeMVar result4
1543− return ()
1544− -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
1545−
1546−
1547−
15481713
1714+ takeMVar result4 >>= assertBool "Expected 'True'"
1715+ -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
15491716
15501717tests :: TestTransport -> IO [Test]
15511718tests testtrans = return [
@@ -1579,6 +1746,7 @@ tests testtrans = return [
15791746 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
15801747 , testCase "ExitLocal" (testExitLocal testtrans)
15811748 , testCase "ExitRemote" (testExitRemote testtrans)
1749+ , testCase "RegistryMonitoring" (testRegistryMonitoring testtrans)
15821750 , testCase "TextCallLocal" (testCallLocal testtrans)
15831751 -- Unsafe Primitives
15841752 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
@@ -1631,17 +1799,3 @@ tests testtrans = return [
16311799 , testCase "MonitorUnreachable" (testMonitorUnreachable testtrans True False)
16321800 ]
16331801 ]
1634−
1635−syncBreakConnection :: (NT.EndPointAddress -> NT.EndPointAddress -> IO ()) -> LocalNode -> LocalNode -> IO ()
1636−syncBreakConnection breakConnection nid0 nid1 = do
1637− m <- newEmptyMVar
1638− _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
1639− runProcess nid0 $ do
1640− them <- liftIO $ takeMVar m
1641− pinger <- spawnLocal $ forever $ send them ()
1642− _ <- monitorNode (localNodeId nid1)
1643− liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
1644− (nodeAddress $ localNodeId nid1)
1645− NodeMonitorNotification _ _ _ <- expect
1646− kill pinger "finished"
1647− return ()
distributed-process-tests/src/Control/Distributed/Process/Tests/Closure.hs+84−45
@@ -169,8 +169,11 @@ testUnclosure TestTransport{..} rtable = do
169169 node <- newLocalNode testTransport rtable
170170 done <- newEmptyMVar
171171 forkProcess node $ do
172− 120 <- join . unClosure $ factorialClosure 5
172+ i <- join . unClosure $ factorialClosure 5
173173 liftIO $ putMVar done ()
174+ if i == 720
175+ then return ()
176+ else error "Something went horribly wrong"
174177 takeMVar done
175178
176179testBind :: TestTransport -> RemoteTable -> Assertion
@@ -180,8 +183,11 @@ testBind TestTransport{..} rtable = do
180183 runProcess node $ do
181184 us <- getSelfPid
182185 join . unClosure $ sendFac 6 us
183− (720 :: Int) <- expect
186+ (i :: Int) <- expect
184187 liftIO $ putMVar done ()
188+ if i == 720
189+ then return ()
190+ else error "Something went horribly wrong"
185191 takeMVar done
186192
187193testSendPureClosure :: TestTransport -> RemoteTable -> Assertion
@@ -194,7 +200,7 @@ testSendPureClosure TestTransport{..} rtable = do
194200 addr <- forkProcess node $ do
195201 cl <- expect
196202 fn <- unClosure cl :: Process (Int -> Int)
197− 13 <- return $ fn 6
203+ (_ :: Int) <- return $ fn 6
198204 liftIO $ putMVar serverDone ()
199205 putMVar serverAddr addr
200206
@@ -218,8 +224,11 @@ testSendIOClosure TestTransport{..} rtable = do
218224 liftIO $ do
219225 someMVar <- newEmptyMVar
220226 io someMVar
221− 5 <- readMVar someMVar
227+ i <- readMVar someMVar
222228 putMVar serverDone ()
229+ if i == 5
230+ then return ()
231+ else error "Something went horribly wrong"
223232 putMVar serverAddr addr
224233
225234 forkIO $ do
@@ -248,8 +257,10 @@ testSendProcClosure TestTransport{..} rtable = do
248257 runProcess node $ do
249258 pid <- getSelfPid
250259 send theirAddr (cpSend $(mkStatic 'sdictInt) pid)
251− 5 <- expect :: Process Int
252− liftIO $ putMVar clientDone ()
260+ i <- expect :: Process Int
261+ if i == 5
262+ then liftIO $ putMVar clientDone ()
263+ else error "Something went horribly wrong"
253264
254265 takeMVar clientDone
255266
@@ -269,8 +280,9 @@ testSpawn TestTransport{..} rtable = do
269280 pid <- getSelfPid
270281 pid' <- spawn nid (sendPidClosure pid)
271282 pid'' <- expect
272− True <- return $ pid' == pid''
273− liftIO $ putMVar clientDone ()
283+ if pid' == pid''
284+ then liftIO $ putMVar clientDone ()
285+ else error "Something went horribly wrong"
274286
275287 takeMVar clientDone
276288
@@ -294,8 +306,9 @@ testSpawnRace TestTransport{..} rtable = do
294306 spawnLocal $ spawn (localNodeId node2) (sendPidClosure pid) >>= send pid
295307 pid' <- expect :: Process ProcessId
296308 pid'' <- expect :: Process ProcessId
297− True <- return $ pid' == pid''
298− return ()
309+ if pid' == pid''
310+ then return ()
311+ else error "Something went horribly wrong"
299312
300313 where
301314
@@ -332,8 +345,10 @@ testCall TestTransport{..} rtable = do
332345 node <- newLocalNode testTransport rtable
333346 nid <- readMVar serverNodeAddr
334347 runProcess node $ do
335− (120 :: Int) <- call $(mkStatic 'sdictInt) nid (factorialClosure 5)
336− liftIO $ putMVar clientDone ()
348+ (a :: Int) <- call $(mkStatic 'sdictInt) nid (factorialClosure 5)
349+ if a == 120
350+ then liftIO $ putMVar clientDone ()
351+ else error "something went horribly wrong"
337352
338353 takeMVar clientDone
339354
@@ -350,8 +365,10 @@ testCallBind TestTransport{..} rtable = do
350365 node <- newLocalNode testTransport rtable
351366 nid <- readMVar serverNodeAddr
352367 runProcess node $ do
353− (120 :: Int) <- call $(mkStatic 'sdictInt) nid (factorial' 5)
354− liftIO $ putMVar clientDone ()
368+ (a :: Int) <- call $(mkStatic 'sdictInt) nid (factorial' 5)
369+ if a == 120
370+ then liftIO $ putMVar clientDone ()
371+ else error "Something went horribly wrong"
355372
356373 takeMVar clientDone
357374
@@ -362,9 +379,11 @@ testSeq TestTransport{..} rtable = do
362379 runProcess node $ do
363380 us <- getSelfPid
364381 join . unClosure $ sendFac 5 us `seqCP` sendFac 6 us
365− 120 :: Int <- expect
366− 720 :: Int <- expect
367− liftIO $ putMVar done ()
382+ a :: Int <- expect
383+ b :: Int <- expect
384+ if a == 120 && b == 720
385+ then liftIO $ putMVar done ()
386+ else error "Something went horribly wrong"
368387 takeMVar done
369388
370389-- Test 'spawnSupervised'
@@ -393,25 +412,33 @@ testSpawnSupervised TestTransport{..} rtable = do
393412 throw supervisorDeath
394413
395414 forkProcess node2 $ do
396− [super, child] <- liftIO $ mapM readMVar [superPid, childPid]
397− ref <- monitor child
398− self <- getSelfPid
399− let waitForMOrL = do
400− liftIO $ threadDelay 10000
401− mpinfo <- getProcessInfo child
402− case mpinfo of
403− Nothing -> waitForMOrL
404− Just pinfo ->
405− unless (isJust $ lookup self (infoMonitors pinfo)) waitForMOrL
406− waitForMOrL
407− liftIO $ putMVar linkUp ()
408− -- because monitor message was sent before message to process
409− -- we hope that it will be processed before
410− ProcessMonitorNotification ref' pid' (DiedException e) <- expect
411− True <- return $ ref' == ref
412− && pid' == child
413− && e == show (ProcessLinkException super (DiedException (show supervisorDeath)))
414− liftIO $ putMVar thirdProcessDone ()
415+ res <- liftIO $ mapM readMVar [superPid, childPid]
416+ case res of
417+ [super, child] -> do
418+ ref <- monitor child
419+ self <- getSelfPid
420+ let waitForMOrL = do
421+ liftIO $ threadDelay 10000
422+ mpinfo <- getProcessInfo child
423+ case mpinfo of
424+ Nothing -> waitForMOrL
425+ Just pinfo ->
426+ unless (isJust $ lookup self (infoMonitors pinfo)) waitForMOrL
427+ waitForMOrL
428+ liftIO $ putMVar linkUp ()
429+ -- because monitor message was sent before message to process
430+ -- we hope that it will be processed before
431+ res' <- expect
432+ case res' of
433+ (ProcessMonitorNotification ref' pid' (DiedException e)) ->
434+ if (ref' == ref && pid' == child &&
435+ e == show (ProcessLinkException super
436+ (DiedException (show supervisorDeath))))
437+ then liftIO $ putMVar thirdProcessDone ()
438+ else error "Something went horribly wrong"
439+ _ -> error "Something went horribly wrong"
440+
441+ _ -> die $ "Something went horribly wrong"
415442
416443 takeMVar thirdProcessDone
417444 where
@@ -426,8 +453,10 @@ testSpawnInvalid TestTransport{..} rtable = do
426453 (pid, ref) <- spawnMonitor (localNodeId node) (closure (staticLabel "ThisDoesNotExist") empty)
427454 ProcessMonitorNotification ref' pid' _reason <- expect
428455 -- Depending on the exact interleaving, reason might be NoProc or the exception thrown by the absence of the static closure
429− True <- return $ ref' == ref && pid == pid'
430− liftIO $ putMVar done ()
456+ res <- return $ ref' == ref && pid == pid'
457+ if res == True
458+ then liftIO $ putMVar done ()
459+ else error "Something went horribly wrong"
431460 takeMVar done
432461
433462testClosureExpect :: TestTransport -> RemoteTable -> Assertion
@@ -439,8 +468,10 @@ testClosureExpect TestTransport{..} rtable = do
439468 us <- getSelfPid
440469 them <- spawn nodeId $ cpExpect $(mkStatic 'sdictInt) `bindCP` cpSend $(mkStatic 'sdictInt) us
441470 send them (1234 :: Int)
442− (1234 :: Int) <- expect
443− liftIO $ putMVar done ()
471+ (res :: Int) <- expect
472+ if res == 1234
473+ then liftIO $ putMVar done ()
474+ else error "Something went horribly wrong"
444475 takeMVar done
445476
446477testSpawnChannel :: TestTransport -> RemoteTable -> Assertion
@@ -465,8 +496,10 @@ testTDict TestTransport{..} rtable = do
465496 done <- newEmptyMVar
466497 [node1, node2] <- replicateM 2 $ newLocalNode testTransport rtable
467498 forkProcess node1 $ do
468− True <- call $(functionTDict 'isPrime) (localNodeId node2) ($(mkClosure 'isPrime) (79 :: Integer))
469− liftIO $ putMVar done ()
499+ res <- call $(functionTDict 'isPrime) (localNodeId node2) ($(mkClosure 'isPrime) (79 :: Integer))
500+ if res == True
501+ then liftIO $ putMVar done ()
502+ else error "Something went horribly wrong..."
470503 takeMVar done
471504
472505testFib :: TestTransport -> RemoteTable -> Assertion
@@ -477,8 +510,11 @@ testFib TestTransport{..} rtable = do
477510 forkProcess (head nodes) $ do
478511 (sport, rport) <- newChan
479512 spawnLocal $ dfib (map localNodeId nodes, sport, 10)
480− 55 <- receiveChan rport :: Process Integer
513+ ff <- receiveChan rport :: Process Integer
481514 liftIO $ putMVar done ()
515+ if ff /= 55
516+ then die $ "Something went horribly wrong"
517+ else return ()
482518
483519 takeMVar done
484520
@@ -486,7 +522,7 @@ testSpawnReconnect :: TestTransport -> RemoteTable -> Assertion
486522testSpawnReconnect testtrans@TestTransport{..} rtable = do
487523 [node1, node2] <- replicateM 2 $ newLocalNode testTransport rtable
488524 let nid1 = localNodeId node1
489− nid2 = localNodeId node2
525+ -- nid2 = localNodeId node2
490526 done <- newEmptyMVar
491527 iv <- newMVar (0 :: Int)
492528
@@ -503,9 +539,12 @@ testSpawnReconnect testtrans@TestTransport{..} rtable = do
503539 liftIO $ threadDelay 100000
504540
505541 count <- liftIO $ takeMVar iv
506− True <- return $ count == 2 || count == 3 -- It depends on which message we get first in 'spawn'
542+ res <- return $ count == 2 || count == 3 -- It depends on which message we get first in 'spawn'
507543
508544 liftIO $ putMVar done ()
545+ if res /= True
546+ then error "Something went horribly wrong"
547+ else return ()
509548
510549 takeMVar done
511550
distributed-process-tests/src/Control/Distributed/Process/Tests/Internal/Utils.hs+11−3
@@ -20,6 +20,7 @@ module Control.Distributed.Process.Tests.Internal.Utils
2020 -- ping !
2121 , Ping(Ping)
2222 , ping
23+ , pause
2324 , shouldBe
2425 , shouldMatch
2526 , shouldContain
@@ -78,10 +79,10 @@ import Control.Distributed.Process.Node
7879import Control.Distributed.Process.Serializable()
7980
8081import Control.Exception (AsyncException(ThreadKilled), SomeException)
81−import Control.Monad (forever)
82+import Control.Monad (forever, void)
8283import Control.Monad.STM (atomically)
8384import Control.Rematch hiding (match)
84−import Control.Rematch.Run
85+import Control.Rematch.Run
8586import Data.Binary
8687import Data.Typeable (Typeable)
8788
@@ -107,10 +108,18 @@ data TestProcessControl = Stop | Go | Report ProcessId
107108
108109instance Binary TestProcessControl where
109110
111+data Private = Private
112+ deriving (Typeable, Generic)
113+instance Binary Private where
114+
110115-- | Does exactly what it says on the tin, doing so in the @Process@ monad.
111116noop :: Process ()
112117noop = return ()
113118
119+pause :: Int -> Process ()
120+pause delay =
121+ void $ receiveTimeout delay [ match (\Private -> return ()) ]
122+
114123synchronisedAssertion :: Eq a
115124 => String
116125 -> LocalNode
@@ -229,4 +238,3 @@ tryForkProcess :: LocalNode -> Process () -> IO ProcessId
229238tryForkProcess node p = do
230239 tid <- liftIO myThreadId
231240 forkProcess node $ catch p (\e -> liftIO $ throwTo tid (e::SomeException))
232−
distributed-process-tests/src/Control/Distributed/Process/Tests/Mx.hs+167−20
@@ -4,7 +4,6 @@ module Control.Distributed.Process.Tests.Mx (tests) where
44import Control.Distributed.Process.Tests.Internal.Utils
55import Network.Transport.Test (TestTransport(..))
66
7−import Control.Concurrent (threadDelay)
87import Control.Distributed.Process
98import Control.Distributed.Process.Node
109import qualified Control.Distributed.Process.UnsafePrimitives as Unsafe
@@ -27,12 +26,12 @@ import Control.Distributed.Process.Management
2726 , mxUpdateLocal
2827 , mxNotify
2928 , mxBroadcast
30− , mxGetId
3129 )
32−import Control.Monad (void)
30+import Control.Monad (void, unless)
31+import Control.Rematch (equalTo)
3332import Data.Binary
3433import Data.List (find, sort)
35−import Data.Maybe (isJust)
34+import Data.Maybe (isJust, isNothing)
3635import Data.Typeable
3736import GHC.Generics
3837#if ! MIN_VERSION_base(4,6,0)
@@ -50,6 +49,16 @@ data Publish = Publish
5049
5150instance Binary Publish where
5251
52+awaitExit :: ProcessId -> Process ()
53+awaitExit pid =
54+ withMonitorRef pid $ \ref -> do
55+ receiveWait
56+ [ matchIf (\(ProcessMonitorNotification r _ _) -> r == ref)
57+ (\_ -> return ())
58+ ]
59+ where
60+ withMonitorRef pid = bracket (monitor pid) unmonitor
61+
5362testAgentBroadcast :: TestResult () -> Process ()
5463testAgentBroadcast result = do
5564 (resultSP, resultRP) <- newChan :: Process (SendPort (), ReceivePort ())
@@ -67,13 +76,13 @@ testAgentBroadcast result = do
6776 -- and the consumer will see that and send the result to our typed channel.
6877 stash result =<< receiveChan resultRP
6978
70− kill publisher "finished"
71− kill consumer "finished"
79+ kill publisher "finished" >> awaitExit publisher
80+ kill consumer "finished" >> awaitExit consumer
7281
7382testAgentDualInput :: TestResult (Maybe Int) -> Process ()
7483testAgentDualInput result = do
7584 (sp, rp) <- newChan
76− _ <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
85+ s <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
7786 mxSink $ (\(i :: Int) -> do
7887 mxSetLocal . (+i) =<< mxGetLocal
7988 i' <- mxGetLocal
@@ -90,6 +99,7 @@ testAgentDualInput result = do
9099 mxNotify (5 :: Int)
91100
92101 stash result =<< receiveChanTimeout 10000000 rp
102+ awaitExit s
93103
94104testAgentPrioritisation :: TestResult [String] -> Process ()
95105testAgentPrioritisation result = do
@@ -101,8 +111,8 @@ testAgentPrioritisation result = do
101111
102112 let name = "prioritising-agent"
103113 (sp, rp) <- newChan
104− void $ mxAgent (MxAgentId name) ["first"] [
105− mxSink (\(s :: String) -> do
114+ s <- mxAgent (MxAgentId name) ["first"] [
115+ mxSink (\(s :: String) -> do
106116 mxUpdateLocal ((s:))
107117 st <- mxGetLocal
108118 case length st of
@@ -118,22 +128,25 @@ testAgentPrioritisation result = do
118128 nsend name "fifth"
119129
120130 stash result . sort =<< receiveChan rp
131+ awaitExit s
121132
122133testAgentMailboxHandling :: TestResult (Maybe ()) -> Process ()
123134testAgentMailboxHandling result = do
124135 (sp, rp) <- newChan
125− agent <- mxAgent (MxAgentId "listener-agent") () [
136+ agent <- mxAgent (MxAgentId "mailbox-agent") () [
126137 mxSink $ \() -> (liftMX $ sendChan sp ()) >> mxReady
127138 ]
128139
129− nsend "listener-agent" ()
140+ nsend "mailbox-agent" ()
130141
131142 stash result =<< receiveChanTimeout 1000000 rp
132− kill agent "finished"
143+ kill agent "finished" >> awaitExit agent
133144
134145testAgentEventHandling :: TestResult Bool -> Process ()
135146testAgentEventHandling result = do
136147 let initState = [] :: [MxEvent]
148+
149+ (rc, rs) <- newChan
137150 agentPid <- mxAgent (MxAgentId "lifecycle-listener-agent") initState [
138151 (mxSink $ \ev -> do
139152 st <- mxGetLocal
@@ -142,7 +155,7 @@ testAgentEventHandling result = do
142155 (MxSpawned _) -> mxSetLocal (ev:st)
143156 (MxProcessDied _ _) -> mxSetLocal (ev:st)
144157 _ -> return ()
145− act >> mxReady),
158+ act >> (liftMX $ sendChan rc ()) >> mxReady),
146159 (mxSink $ \(ev, sp :: SendPort Bool) -> do
147160 st <- mxGetLocal
148161 let found =
@@ -162,16 +175,26 @@ testAgentEventHandling result = do
162175 mxReady)
163176 ]
164177
178+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
179+ faff 2000000 rs
180+
165181 _ <- monitor agentPid
166182 (sp, rp) <- newChan
167− pid <- spawnLocal $ sendChan sp ()
168− () <- receiveChan rp
183+
184+ pid <- spawnLocal $ expect >>= sendChan sp
169185
170186 -- By waiting for a monitor notification, we have a
171− -- higher probably that the agent has seen
187+ -- higher probably that the agent has seen the spawn and died events
172188 monitor pid
189+
190+ send pid ()
191+ () <- receiveChan rp
192+
173193 receiveWait [ match (\(ProcessMonitorNotification _ _ _) -> return ()) ]
174194
195+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
196+ faff 2000000 rs
197+
175198 (replyTo, reply) <- newChan :: Process (SendPort Bool, ReceivePort Bool)
176199 mxNotify (MxSpawned pid, replyTo)
177200 mxNotify (MxProcessDied pid DiedNormal, replyTo)
@@ -180,6 +203,121 @@ testAgentEventHandling result = do
180203 seenDead <- receiveChan reply
181204
182205 stash result $ seenAlive && seenDead
206+ kill agentPid "test-complete" >> awaitExit agentPid
207+ where
208+ faff delay port = do
209+ res <- receiveChanTimeout delay port
210+ unless (isNothing res) $ do
211+ pause delay
212+ faff delay port
213+
214+testMxRegEvents :: TestResult () -> Process ()
215+testMxRegEvents result = do
216+ {- This test only deals with the local case, to ensure that we are being
217+ notified in the expected order - the remote cases related to the
218+ behaviour of the node controller are contained in the CH test suite. -}
219+ ensure (stash result ()) $ do
220+ let label = "testMxRegEvents"
221+ let agentLabel = "mxRegEvents-agent"
222+ let delay = 1000000
223+ (regChan, regSink) <- newChan
224+ (unRegChan, unRegSink) <- newChan
225+ agent <- mxAgent (MxAgentId agentLabel) () [
226+ mxSink $ \ev -> do
227+ case ev of
228+ MxRegistered pid label'
229+ | label' == label -> liftMX $ sendChan regChan (label', pid)
230+ MxUnRegistered pid label'
231+ | label' == label -> liftMX $ sendChan unRegChan (label', pid)
232+ _ -> return ()
233+ mxReady
234+ ]
235+
236+ p1 <- spawnLocal expect
237+ p2 <- spawnLocal expect
238+
239+ register label p1
240+ reg1 <- receiveChanTimeout delay regSink
241+ reg1 `shouldBe` equalTo (Just (label, p1))
242+
243+ unregister label
244+ unreg1 <- receiveChanTimeout delay unRegSink
245+ unreg1 `shouldBe` equalTo (Just (label, p1))
246+
247+ register label p2
248+ reg2 <- receiveChanTimeout delay regSink
249+ reg2 `shouldBe` equalTo (Just (label, p2))
250+
251+ reregister label p1
252+ unreg2 <- receiveChanTimeout delay unRegSink
253+ unreg2 `shouldBe` equalTo (Just (label, p2))
254+
255+ reg3 <- receiveChanTimeout delay regSink
256+ reg3 `shouldBe` equalTo (Just (label, p1))
257+
258+ mapM_ (flip kill $ "test-complete") [agent, p1, p2]
259+ awaitExit agent
260+
261+testMxRegMon :: LocalNode -> TestResult () -> Process ()
262+testMxRegMon remoteNode result = do
263+ ensure (stash result ()) $ do
264+ -- ensure that when a registered process dies, we get a notification that
265+ -- it has been unregistered as well as seeing the name get removed
266+ let label1 = "aaaaa"
267+ let label2 = "bbbbb"
268+ let isValid l = l == label1 || l == label2
269+ let agentLabel = "mxRegMon-agent"
270+ let delay = 1000000
271+ (regChan, regSink) <- newChan
272+ (unRegChan, unRegSink) <- newChan
273+ agent <- mxAgent (MxAgentId agentLabel) () [
274+ mxSink $ \ev -> do
275+ case ev of
276+ MxRegistered pid label
277+ | isValid label -> liftMX $ sendChan regChan (label, pid)
278+ MxUnRegistered pid label
279+ | isValid label -> liftMX $ sendChan unRegChan (label, pid)
280+ _ -> return ()
281+ mxReady
282+ ]
283+
284+ (sp, rp) <- newChan
285+ liftIO $ forkProcess remoteNode $ do
286+ getSelfPid >>= sendChan sp
287+ expect :: Process ()
288+
289+ p1 <- receiveChan rp
290+
291+ register label1 p1
292+ reg1 <- receiveChanTimeout delay regSink
293+ reg1 `shouldBe` equalTo (Just (label1, p1))
294+
295+ register label2 p1
296+ reg2 <- receiveChanTimeout delay regSink
297+ reg2 `shouldBe` equalTo (Just (label2, p1))
298+
299+ n1 <- whereis label1
300+ n1 `shouldBe` equalTo (Just p1)
301+
302+ n2 <- whereis label2
303+ n2 `shouldBe` equalTo (Just p1)
304+
305+ kill p1 "goodbye"
306+
307+ unreg1 <- receiveChanTimeout delay unRegSink
308+ unreg2 <- receiveChanTimeout delay unRegSink
309+
310+ let evts = [unreg1, unreg2]
311+ -- we can't rely on the order of the values in the node controller's
312+ -- map (it's either racy to do so, or no such guarantee exists for Data.Map),
313+ -- so we simply verify that we received the un-registration events we expect
314+ evts `shouldContain` (Just (label1, p1))
315+ evts `shouldContain` (Just (label2, p1))
316+
317+ kill agent "test-complete" >> awaitExit agent
318+
319+ensure :: Process () -> Process () -> Process ()
320+ensure = flip finally
183321
184322
185323testMxUnsafeSendEvents :: LocalNode -> Process ()
@@ -265,8 +403,17 @@ tests TestTransport{..} = do
265403 node1 (sort ["first", "second",
266404 "third", "fourth",
267405 "fifth"]) testAgentPrioritisation)
268− testGroup "Mx Events" [
269− testCase "Monitor Events"
270− (runProcess node1 (testMxUnsafeSendEvents node2))
271406 ]
272− ]]
407+ , testGroup "Mx Events" [
408+ testCase "Name Registration Events"
409+ (delayedAssertion
410+ "expected registration events to map to the correct ProcessId"
411+ node1 () testMxRegEvents)
412+ , testCase "Post Death Name UnRegistration Events"
413+ (delayedAssertion
414+ "expected process deaths to result in unregistration events"
415+ node1 () (testMxRegMon node2))
416+ , testCase "Monitor Events"
417+ (runProcess node1 (testMxUnsafeSendEvents node2))
418+ ]
419+ ]
distributed-process-tests/src/Control/Distributed/Process/Tests/Receive.hs+7−8
@@ -10,13 +10,12 @@ import Network.Transport.Test (TestTransport(..))
1010
1111import Network.Transport (Transport)
1212import Control.Distributed.Process
13−import Control.Distributed.Process.Closure
1413import Control.Distributed.Process.Node
1514
1615import Control.Monad
1716
1817import Test.HUnit (Assertion, (@?=))
19−import Test.Framework (Test, defaultMain)
18+import Test.Framework (Test)
2019import Test.Framework.Providers.HUnit (testCase)
2120
2221-- Tests:
@@ -43,7 +42,7 @@ recTest2 :: ReceivePort ()
4342 -> SendPort String
4443 -> ReceivePort String -> ReceivePort String
4544 -> Process ()
46−recTest2 wait sync r1 r2 = do
45+recTest2 wait sync r1 _ = do
4746 forever $ do
4847 receiveChan wait
4948 r <- receiveWait
@@ -56,7 +55,7 @@ recTest3 :: ReceivePort ()
5655 -> SendPort String
5756 -> ReceivePort String -> ReceivePort String
5857 -> Process ()
59−recTest3 wait sync r1 r2 = do
58+recTest3 wait sync r1 _ = do
6059 forever $ do
6160 receiveChan wait
6261 r <- receiveWait
@@ -69,7 +68,7 @@ recTest4 :: ReceivePort ()
6968 -> SendPort String
7069 -> ReceivePort String -> ReceivePort String
7170 -> Process ()
72−recTest4 wait sync r1 r2 = do
71+recTest4 wait sync r1 _ = do
7372 forever $ do
7473 receiveChan wait
7574 r <- receiveWait
@@ -83,11 +82,11 @@ master :: Process ()
8382master = do
8483 (waits,waitr) <- newChan
8584 (syncs,syncr) <- newChan
86− let go expect = do
85+ let go expected = do
8786 sendChan waits ()
8887 r <- receiveChan syncr
89− liftIO $ print (r,expect, r == expect)
90− liftIO $ r @?= expect
88+ liftIO $ print (r, expected, r == expected)
89+ liftIO $ r @?= expected
9190
9291 liftIO $ putStrLn "---- Test 1 ----"
9392 (s1,r1) <- newChan
distributed-process-tests/src/Control/Distributed/Process/Tests/Stats.hs+11−7
@@ -29,7 +29,7 @@ import Test.Framework.Providers.HUnit (testCase)
2929
3030testLocalDeadProcessInfo :: TestResult (Maybe ProcessInfo) -> Process ()
3131testLocalDeadProcessInfo result = do
32− pid <- spawnLocal $ do "finish" <- expect; return ()
32+ pid <- spawnLocal $ do (_ :: String) <- expect; return ()
3333 mref <- monitor pid
3434 send pid "finish"
3535 _ <- receiveWait [
@@ -52,8 +52,10 @@ testLocalLiveProcessInfo result = do
5252 link self
5353 mRef <- monitor self
5454 stash mon mRef
55− "die" <- expect
56− return ()
55+ res <- expect
56+ case res of
57+ "die" -> return ()
58+ _ -> die $ "unexpected message received: " ++ res
5759
5860 monRef <- liftIO $ takeMVar mon
5961
@@ -84,9 +86,9 @@ testRemoteLiveProcessInfo TestTransport{..} node1 = do
8486 -- our send op shouldn't overtake link or monitor requests AFAICT
8587 -- so a little table tennis should get us synchronised properly
8688 send serverPid (self, "ping")
87− "pong" <- expect
89+ pong <- expect
8890 pInfo <- getProcessInfo serverPid
89− stash result $ pInfo /= Nothing
91+ stash result $ pong == "pong" && pInfo /= Nothing
9092 where
9193 launchRemote :: MVar ProcessId -> IO ()
9294 launchRemote locMV = do
@@ -97,8 +99,10 @@ testRemoteLiveProcessInfo TestTransport{..} node1 = do
9799 _ <- receiveWait [
98100 match (\(pid, "ping") -> send pid "pong")
99101 ]
100− "stop" <- expect
101− return ()
102+ res <- expect
103+ case res of
104+ "stop" -> return ()
105+ _ -> die $ "unexpected message received: " ++ res
102106 return ()
103107
104108 withActiveRemote :: LocalNode
distributed-process-tests/src/Control/Distributed/Process/Tests/Tracing.hs+23−11
@@ -125,9 +125,11 @@ testTraceSending result = do
125125 (\ev ->
126126 case ev of
127127 (MxSent to from msg) -> do
128− (Just s) <- unwrapMessage msg :: Process (Maybe String)
129− stash res (to == pid && from == self && s == "hello there")
130− stash res (to == pid && from == self)
128+ mS <- unwrapMessage msg :: Process (Maybe String)
129+ case mS of
130+ (Just s) -> do stash res (to == pid && from == self && s == "hello there")
131+ stash res (to == pid && from == self)
132+ _ -> die "failed state invariant, message type unmatched..."
131133 _ ->
132134 return ()) $ do
133135 send pid "hello there"
@@ -246,12 +248,8 @@ testRemoteTraceRelay TestTransport{..} result =
246248 -- Here we set up that relay, and then wait for a signal
247249 -- that the tracer (on node1) has seen the expected
248250 -- MxSpawned message, at which point we're finished
249− (Just log') <- whereis "logger"
250− pid <- liftIO $ forkProcess node2 $ do
251− logRelay <- spawnLocal $ relay log'
252− reregister "logger" logRelay
253− getSelfNode >>= stash mvNid >> (expect :: Process ())
254251
252+ pid <- splinchLogger node2 mvNid
255253 nid <- liftIO $ takeMVar mvNid
256254 mref <- monitor pid
257255 observedPid <- liftIO $ newEmptyMVar
@@ -291,6 +289,17 @@ testRemoteTraceRelay TestTransport{..} result =
291289 -- and just to be polite...
292290 liftIO $ closeLocalNode node2
293291
292+ where
293+ splinchLogger n2 mv = do
294+ mLog <- whereis "logger"
295+ case mLog of
296+ Nothing -> die "no logger registered"
297+ Just log' -> do liftIO $ forkProcess n2 $ do
298+ logRelay <- spawnLocal $ relay log'
299+ reregister "logger" logRelay
300+ getSelfNode >>= stash mv >> (expect :: Process ())
301+
302+
294303-- | Sets the value of an environment variable while executing the given IO
295304-- computation and restores the preceeding value upon completion.
296305withEnv :: String -> String -> IO a -> IO a
@@ -319,9 +328,12 @@ testSystemLoggerMsg t action interestingMessage =
319328 -- Wait for the trace message.
320329 receiveWait [ matchIf interestingMessage' $ const $ return () ]
321330 -- Only one interesting message should arrive.
322− Nothing <- receiveTimeout 100000
323− [ matchIf interestingMessage' $ const $ return () ]
324− return ()
331+ expectedTimeout <- receiveTimeout
332+ 100000
333+ [ matchIf interestingMessage' $ const $ return () ]
334+ case expectedTimeout of
335+ Nothing -> return ()
336+ Just _ -> die "Unexpected message arrived..."
325337
326338
327339-- | Tests that one and only one trace message is produced when a message is
distributed-process-tests/tests/runInMemory.hs−1
@@ -8,7 +8,6 @@ import Network.Transport.Test (TestTransport(..))
88import Network.Transport.InMemory
99import Test.Framework (defaultMainWithArgs)
1010
11−import Control.Concurrent (threadDelay)
1211import System.Environment (getArgs)
1312
1413main :: IO ()
distributed-process-tests/tests/runTCP.hs+2−2
@@ -10,6 +10,7 @@ import Network.Transport.TCP
1010 ( createTransportExposeInternals
1111 , TransportInternals(socketBetween)
1212 , defaultTCPParameters
13+ , defaultTCPAddr
1314 , TCPParameters(..)
1415 )
1516import Test.Framework (defaultMainWithArgs)
@@ -24,8 +25,7 @@ main = do
2425 hSetBuffering stdout LineBuffering
2526 hSetBuffering stderr LineBuffering
2627 Right (transport, internals) <-
27− createTransportExposeInternals "127.0.0.1" "8080"
28− (\sn -> ("127.0.0.1", sn))
28+ createTransportExposeInternals (defaultTCPAddr "127.0.0.1" "8080")
2929 defaultTCPParameters { transportConnectTimeout = Just 3000000 }
3030 ts <- tests TestTransport
3131 { testTransport = transport
distributed-process.cabal+1−1
@@ -21,7 +21,7 @@ Description: This is an implementation of Cloud Haskell, as described in
2121
2222 You will probably also want to install a Cloud Haskell backend such
2323 as distributed-process-simplelocalnet.
24−Tested-With: GHC==7.6.3 GHC==7.8.4 GHC==7.10.3 GHC==8.0.1
24+Tested-With: GHC==7.10.3 GHC==8.0.2 GHC==8.2.2 GHC==8.4.4
2525Category: Control
2626extra-source-files: ChangeLog
2727
src/Control/Distributed/Process/Internal/Primitives.hs+6−2
@@ -76,6 +76,7 @@ module Control.Distributed.Process.Internal.Primitives
7676 , unlink
7777 , monitor
7878 , unmonitor
79+ , unmonitorAsync
7980 , withMonitor
8081 , withMonitor_
8182 -- * Logging
@@ -400,8 +401,11 @@ newtype Match b = Match { unMatch :: MatchOn Message (Process b) }
400401receiveWait :: [Match b] -> Process b
401402receiveWait ms = do
402403 queue <- processQueue <$> ask
403− Just proc <- liftIO $ dequeue queue Blocking (map unMatch ms)
404− proc
404+ mProc <- liftIO $ dequeue queue Blocking (map unMatch ms)
405+ case mProc of
406+ Just proc' -> proc'
407+ Nothing -> die $ "System Invariant Violation: CQueue.hs returned `Nothing` "
408+ ++ "in the absence of a timeout value."
405409
406410-- | Like 'receiveWait' but with a timeout.
407411--
src/Control/Distributed/Process/Management/Internal/Trace/Primitives.hs+8−2
@@ -33,6 +33,7 @@ import Control.Distributed.Process.Internal.Primitives
3333 ( whereis
3434 , newChan
3535 , receiveChan
36+ , die
3637 )
3738import Control.Distributed.Process.Management.Internal.Trace.Types
3839 ( TraceArg(..)
@@ -168,6 +169,11 @@ withRegisteredTracer act = do
168169 withLocalTracer $ \t -> liftIO $ Tracer.getCurrentTraceClient t sp
169170 currentTracer <- receiveChan rp
170171 case currentTracer of
171− Nothing -> do { (Just p') <- whereis "tracer.initial"; act p' }
172+ Nothing -> do mTP <- whereis "tracer.initial"
173+ -- NB: this should NOT ever happen, but forcing pattern matches
174+ -- is not considered cool in later versions of MonadFail
175+ case mTP of
176+ Just p' -> act p'
177+ Nothing -> die $ "System Invariant Violation: Tracer Process "
178+ ++ "Name Not Found (whereis tracer.initial)"
172179 (Just p) -> act p
173−
src/Control/Distributed/Process/Management/Internal/Types.hs+2
@@ -30,6 +30,7 @@ import qualified Control.Monad.State as ST
3030 ( MonadState
3131 , StateT
3232 )
33+import Control.Monad.Fix (MonadFix)
3334import Data.Binary
3435import Data.Typeable (Typeable)
3536import GHC.Generics
@@ -114,6 +115,7 @@ newtype MxAgent s a =
114115 } deriving ( Functor
115116 , Monad
116117 , MonadIO
118+ , MonadFix
117119 , ST.MonadState (MxAgentState s)
118120 , Typeable
119121 , Applicative
src/Control/Distributed/Process/Node.hs+23−9
@@ -28,9 +28,12 @@ import Data.Binary (decode)
2828import Data.Map (Map)
2929import qualified Data.Map as Map
3030 ( empty
31+ , delete
3132 , toList
3233 , fromList
33− , filter
34+ , insert
35+ , lookup
36+ , partition
3437 , partitionWithKey
3538 , elems
3639 , size
@@ -183,6 +186,9 @@ import Control.Distributed.Process.Internal.Types
183186import Control.Distributed.Process.Management.Internal.Agent
184187 ( mxAgentController
185188 )
189+import Control.Distributed.Process.Management.Internal.Types
190+ ( MxEvent(..)
191+ )
186192import qualified Control.Distributed.Process.Management.Internal.Trace.Remote as Trace
187193 ( remoteTable
188194 )
@@ -195,9 +201,6 @@ import Control.Distributed.Process.Management.Internal.Trace.Types
195201 , traceLogFmt
196202 , enableTrace
197203 )
198−import Control.Distributed.Process.Management.Internal.Types
199− ( MxEvent(..)
200− )
201204import Control.Distributed.Process.Serializable (Serializable)
202205import Control.Distributed.Process.Internal.Messaging
203206 ( sendBinary
@@ -210,6 +213,9 @@ import Control.Distributed.Process.Internal.Primitives
210213 , match
211214 , sendChan
212215 , unwrapMessage
216+ , monitor
217+ , unmonitorAsync
218+ , getSelfNode
213219 , SayMessage(..)
214220 )
215221import Control.Distributed.Process.Internal.Types (SendPort, Tracer(..))
@@ -903,7 +909,11 @@ ncEffectDied ident reason = do
903909
904910 modify' $ (links ^= unaffectedLinks') . (monitors ^= unaffectedMons')
905911
906− modify' $ registeredHere ^: Map.filter (\pid -> not $ ident `impliesDeathOf` ProcessIdentifier pid)
912+ -- we now consider all labels for this identifier unregistered
913+ let toDrop pid = not $ ident `impliesDeathOf` ProcessIdentifier pid
914+ (keepNames, dropNames) <- Map.partition toDrop <$> gets (^. registeredHere)
915+ mapM_ (\(p, l) -> liftIO $ trace node (MxUnRegistered l p)) (Map.toList dropNames)
916+ modify' $ registeredHere ^= keepNames
907917
908918 remaining <- fmap Map.toList (gets (^. registeredOnNodes)) >>=
909919 mapM (\(pid,nidlist) ->
@@ -955,7 +965,11 @@ ncEffectRegister from label atnode mPid reregistration = do
955965 do modify' $ registeredHereFor label ^= mPid
956966 updateRemote node currentVal mPid
957967 case mPid of
958− (Just p) -> liftIO $ trace node (MxRegistered p label)
968+ (Just p) -> do
969+ if reregistration
970+ then liftIO $ trace node (MxUnRegistered (fromJust currentVal) label)
971+ else return ()
972+ liftIO $ trace node (MxRegistered p label)
959973 Nothing -> liftIO $ trace node (MxUnRegistered (fromJust currentVal) label)
960974 newVal <- gets (^. registeredHereFor label)
961975 ncSendToProcess from $ unsafeCreateUnencodedMessage $
@@ -1070,7 +1084,7 @@ ncEffectGetInfo from pid =
10701084 case mProc of
10711085 Nothing -> dispatch (isLocal node (ProcessIdentifier from))
10721086 from (ProcessInfoNone DiedUnknownId)
1073− Just proc -> do
1087+ Just proc -> do
10741088 itsLinks <- Set.map fst . BiMultiMap.lookupBy1st them <$>
10751089 gets (^. links)
10761090 itsMons <- BiMultiMap.lookupBy1st them <$> gets (^. monitors)
@@ -1084,8 +1098,8 @@ ncEffectGetInfo from pid =
10841098 infoNode = (processNodeId pid)
10851099 , infoRegisteredNames = reg
10861100 , infoMessageQueueLength = size
1087− , infoMonitors = Set.toList itsMons
1088− , infoLinks = Set.toList itsLinks
1101+ , infoMonitors = Set.toList itsMons
1102+ , infoLinks = Set.toList itsLinks
10891103 }
10901104 where dispatch :: (Serializable a)
10911105 => Bool
stack-ghc-7.10.3.yaml+5−1
@@ -3,14 +3,18 @@ resolver: nightly-2016-03-08
33packages:
44- '.'
55- distributed-process-tests/
6+- location:
7+ git: https://github.com/haskell-distributed/network-transport-tcp.git
8+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
9+ extra-dep: true
610
711extra-deps:
812- rank1dynamic-0.4.0
913- distributed-static-0.3.8
1014- network-transport-0.5.2
11−- network-transport-tcp-0.6.0
1215- network-transport-inmemory-0.5.2
1316- rematch-0.2.0.0
17+- exceptions-0.8.2.1 # test dependency
1418
1519flags:
1620 distributed-process-tests:
stack-ghc-8.0.2.yaml+8−2
@@ -1,16 +1,22 @@
1−resolver: lts-9.0
1+resolver: lts-9.21
2+# added -location for network-transport-tcp-0.6.0
3+# since c7fd79 broke the client facing API for createTransport :/
24
35packages:
46- '.'
57- distributed-process-tests/
8+- location:
9+ git: https://github.com/haskell-distributed/network-transport-tcp.git
10+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
11+ extra-dep: true
612
713extra-deps:
814- rank1dynamic-0.4.0
915- distributed-static-0.3.8
1016- network-transport-0.5.2
11−- network-transport-tcp-0.6.0
1217- network-transport-inmemory-0.5.2
1318- rematch-0.2.0.0
19+# - exceptions-0.8.2.1 # test dependency
1420
1521flags:
1622 distributed-process-tests:
stack-ghc-8.2.2.yamlnew file+21
@@ -0,0 +1,21 @@
1+resolver: lts-11.22
2+
3+packages:
4+- '.'
5+- distributed-process-tests/
6+- location:
7+ git: https://github.com/haskell-distributed/network-transport-tcp.git
8+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
9+ extra-dep: true
10+
11+extra-deps:
12+- rank1dynamic-0.4.0
13+- distributed-static-0.3.8
14+- network-transport-0.5.2
15+- network-transport-inmemory-0.5.2
16+- rematch-0.2.0.0
17+# - exceptions-0.8.2.1 # test dependency
18+
19+flags:
20+ distributed-process-tests:
21+ tcp: true
stack-ghc-8.4.4.yamlnew file+20
@@ -0,0 +1,20 @@
1+resolver: lts-12.18
2+
3+packages:
4+- '.'
5+- distributed-process-tests/
6+- location:
7+ git: https://github.com/haskell-distributed/network-transport-tcp.git
8+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
9+ extra-dep: true
10+
11+extra-deps:
12+- rank1dynamic-0.4.0
13+- distributed-static-0.3.8
14+- network-transport-0.5.2
15+- network-transport-inmemory-0.5.2
16+- rematch-0.2.0.0
17+
18+flags:
19+ distributed-process-tests:
20+ tcp: true
stack-nightly.yamlnew file+26
@@ -0,0 +1,26 @@
1+resolver: nightly
2+
3+packages:
4+- '.'
5+- distributed-process-tests/
6+- location:
7+ git: https://github.com/haskell-distributed/distributed-static.git
8+ commit: c51e6aadd3a44c044e96a8e986c11d3a94b45b11
9+ extra-dep: true
10+- location:
11+ git: https://github.com/haskell-distributed/network-transport-tcp.git
12+ commit: d58250e2388b86a1865ac4139373cbdc106e72e1
13+ extra-dep: true
14+- location:
15+ git: https://github.com/haskell-distributed/network-transport-inmemory.git
16+ commit: 0ce97924f15a8c1570b2355151834305c9bd2a28
17+ extra-dep: true
18+
19+extra-deps:
20+- rank1dynamic-0.4.0
21+- network-transport-0.5.2
22+- rematch-0.2.0.0
23+
24+flags:
25+ distributed-process-tests:
26+ tcp: true
stack.yaml+7−2
@@ -1,14 +1,19 @@
1−resolver: nightly-2017-08-20
1+resolver: lts-12.18 # Use GHC 8.4.4
2+
3+# TODO: we can enable nightly-2018-11-11 once PR #319 is merged
24
35packages:
46- '.'
57- distributed-process-tests/
8+- location:
9+ git: https://github.com/haskell-distributed/network-transport-tcp.git
10+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
11+ extra-dep: true
612
713extra-deps:
814- rank1dynamic-0.4.0
915- distributed-static-0.3.8
1016- network-transport-0.5.2
11−- network-transport-tcp-0.6.0
1217- network-transport-inmemory-0.5.2
1318- rematch-0.2.0.0
1419