git.iko.soy/distributed-process
on master help sign in
Merge master
commit38b7a44bed631230aed431ef208a92440d41b915 authorTim Watson <watson.timothy@gmail.com> dateThu 15 Nov 2018, 23:53 (8 years ago) parentb352c30003e522
25 files changed+835−382
.travis.yml+12−13 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+23−10 distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+362−212 distributed-process-tests/src/Control/Distributed/Process/Tests/Closure.hs+83−44 distributed-process-tests/src/Control/Distributed/Process/Tests/Internal/Utils.hs+11−3 distributed-process-tests/src/Control/Distributed/Process/Tests/Mx.hs+190−38 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/runTCP.hs+2−2 distributed-process.cabal+2−2 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+4−1 stack-ghc-8.0.2.yaml+6−1 stack-ghc-8.2.2.yaml+4 stack-ghc-8.4.4.yaml+5−1 stack-nightly.yaml+26 stack.yaml+5−2
.travis.yml+12−13
@@ -5,19 +5,13 @@ sudo: false
55matrix:
66 include:
77 - env: ARGS="--stack-yaml stack-ghc-7.10.3.yaml"
8− addons: {apt: {packages: [libgmp-dev]}}
9−
10− - env: ARGS="--stack-yaml stack-ghc-8.0.2.yaml"
11− addons: {apt: {packages: [libgmp-dev]}}
12−
8+ addons: {apt: {packages: [libgmp-dev]}}
139 - env: ARGS="--stack-yaml stack-ghc-8.2.2.yaml"
14− addons: {apt: {packages: [libgmp-dev]}}
15−
10+ addons: {apt: {packages: [libgmp-dev]}}
1611 - env: ARGS="--stack-yaml stack-ghc-8.4.4.yaml"
17− addons: {apt: {packages: [libgmp-dev]}}
18−
19− - env: ARGS=
20− addons: {apt: {packages: [libgmp-dev]}}
12+ addons: {apt: {packages: [libgmp-dev]}}
13+ - env: ARGS="--stack-yaml stack-nightly.yaml --resolver nightly"
14+ addons: {apt: {packages: [libgmp-dev]}}
2115
2216cache:
2317 directories:
@@ -40,5 +34,10 @@ script:
4034- stack ${ARGS} test $ARG='--plain -t "!Flaky"' ${TEST_PACKAGE}TestCHInTCP
4135- stack ${ARGS} test $ARG='--plain -t "!SpawnReconnect"' ${TEST_PACKAGE}TestClosure
4236- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestStats
43−- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMx
44−- 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+23−10
@@ -34,7 +34,7 @@ library
3434 exceptions >= 0.5,
3535 HUnit >= 1.2 && < 1.7,
3636 network-transport >= 0.4.1.0 && < 0.6,
37− network >= 2.5 && < 2.7,
37+ network >= 2.5 && < 2.9,
3838 random >= 1.0 && < 1.2,
3939 rematch >= 0.1.2.1,
4040 setenv >= 0.1.1.3,
@@ -61,7 +61,7 @@ Test-Suite TestCHInMemory
6161 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.CH
6262 Build-Depends: base >= 4.4 && < 5,
6363 distributed-process-tests,
64− network >= 2.3 && < 2.7,
64+ network >= 2.3 && < 2.9,
6565 network-transport >= 0.4.1.0 && < 0.6,
6666 network-transport-inmemory >= 0.5,
6767 test-framework >= 0.6 && < 0.9
@@ -76,7 +76,7 @@ Test-Suite TestCHInTCP
7676 if flag(tcp)
7777 Build-Depends: base >= 4.4 && < 5,
7878 distributed-process-tests,
79− network >= 2.3 && < 2.7,
79+ network >= 2.3 && < 2.9,
8080 network-transport >= 0.4.1.0 && < 0.6,
8181 network-transport-tcp >= 0.5 && < 0.7,
8282 test-framework >= 0.6 && < 0.9
@@ -93,7 +93,7 @@ Test-Suite TestClosure
9393 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Closure
9494 Build-Depends: base >= 4.4 && < 5,
9595 distributed-process-tests,
96− network >= 2.3 && < 2.7,
96+ network >= 2.3 && < 2.9,
9797 network-transport >= 0.4.1.0 && < 0.6,
9898 network-transport-inmemory >= 0.5,
9999 test-framework >= 0.6 && < 0.9
@@ -107,7 +107,7 @@ Test-Suite TestStats
107107 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Stats
108108 Build-Depends: base >= 4.4 && < 5,
109109 distributed-process-tests,
110− network >= 2.3 && < 2.7,
110+ network >= 2.3 && < 2.9,
111111 network-transport >= 0.4.1.0 && < 0.6,
112112 network-transport-inmemory >= 0.5,
113113 test-framework >= 0.6 && < 0.9
@@ -115,14 +115,13 @@ Test-Suite TestStats
115115 ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
116116 HS-Source-Dirs: tests
117117
118−
119−Test-Suite TestMx
118+Test-Suite TestMxInMemory
120119 Type: exitcode-stdio-1.0
121120 Main-Is: runInMemory.hs
122121 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
123122 Build-Depends: base >= 4.4 && < 5,
124123 distributed-process-tests,
125− network >= 2.3 && < 2.7,
124+ network >= 2.3 && < 2.9,
126125 network-transport >= 0.4.1.0 && < 0.6,
127126 network-transport-inmemory >= 0.5,
128127 test-framework >= 0.6 && < 0.9
@@ -130,16 +129,30 @@ Test-Suite TestMx
130129 ghc-options: -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
131130 HS-Source-Dirs: tests
132131
133−Test-Suite TestTracing
132+Test-Suite TestTracingInMemory
134133 Type: exitcode-stdio-1.0
135134 Main-Is: runInMemory.hs
136135 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Tracing
137136 Build-Depends: base >= 4.4 && < 5,
138137 distributed-process-tests,
139− network >= 2.3 && < 2.7,
138+ network >= 2.3 && < 2.9,
140139 network-transport >= 0.4.1.0 && < 0.6,
141140 network-transport-inmemory >= 0.5,
142141 test-framework >= 0.6 && < 0.9
143142 Extensions: CPP
144143 ghc-options: -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
145144 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
158+ HS-Source-Dirs: tests
distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+362−212
@@ -42,9 +42,12 @@ import Control.Distributed.Process.Internal.Types
4242 , createUnencodedMessage
4343 )
4444import 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)
4548import Control.Distributed.Process.Serializable (Serializable)
4649
47−import Test.HUnit (Assertion, assertFailure)
50+import Test.HUnit (Assertion, assertBool, assertFailure)
4851import Test.Framework (Test, testGroup)
4952import Test.Framework.Providers.HUnit (testCase)
5053import Control.Rematch hiding (match)
@@ -80,12 +83,47 @@ ping = do
8083 send partner (Ping self)
8184 ping
8285
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+
8395-- | Quick and dirty synchronous version of whereisRemoteAsync
8496whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
8597whereisRemote nid string = do
8698 whereisRemoteAsync nid string
87− WhereIsReply _ mPid <- expect
88− 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 ()
89127
90128data Add = Add ProcessId Double Double deriving (Typeable)
91129data Divide = Divide ProcessId Double Double deriving (Typeable)
@@ -160,12 +198,18 @@ monitorTestProcess theirAddr mOrL un reason monitorSetup done =
160198 unmonitor ref
161199 liftIO $ putMVar done ()
162200 (False, ref) -> do
163− ProcessMonitorNotification ref' pid reason' <- expect
164− True <- return $ Just ref' == ref && pid == theirAddr && mOrL && reason == reason'
165− 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+ ]
166209 )
167210 (\(ProcessLinkException pid reason') -> do
168− 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')
169213 liftIO $ putMVar done ()
170214 )
171215
@@ -196,8 +240,10 @@ testPing TestTransport{..} = do
196240 pid <- getSelfPid
197241 replicateM_ numPings $ do
198242 send pingServer (Pong pid)
199− Ping _ <- expect
200− return ()
243+ p <- expect
244+ case p of
245+ Ping _ -> return ()
246+ _ -> die "Unexpected message"
201247
202248 putMVar clientDone ()
203249
@@ -284,7 +330,7 @@ testMonitorLocalDeadProcess TestTransport{..} mOrL un = do
284330 runProcess localNode $ do
285331 monitor theirAddr
286332 -- wait for the process to die
287− ProcessMonitorNotification _ _ _ <- expect
333+ expect :: Process ProcessMonitorNotification
288334 monitorTestProcess theirAddr mOrL un DiedUnknownId Nothing done
289335
290336 takeMVar done
@@ -358,14 +404,17 @@ testMath TestTransport{..} = do
358404 runProcess localNode $ do
359405 pid <- getSelfPid
360406 send mathServer (Add pid 1 2)
361− 3 <- expect :: Process Double
407+ three <- expect :: Process Double
362408 send mathServer (Divide pid 8 2)
363− 4 <- expect :: Process Double
409+ four <- expect :: Process Double
364410 send mathServer (Divide pid 8 0)
365− DivByZero <- expect
366− liftIO $ putMVar clientDone ()
411+ divByZ <- expect
412+ liftIO $ putMVar clientDone (three, four, divByZ)
367413
368− takeMVar clientDone
414+ res <- takeMVar clientDone
415+ case res of
416+ (3, 4, DivByZero) -> return ()
417+ _ -> error $ "Something went horribly wrong"
369418
370419-- | Send first message (i.e. connect) to an already terminated process
371420-- (without monitoring); then send another message to a second process on
@@ -393,11 +442,9 @@ testSendToTerminated TestTransport{..} = do
393442 pid <- getSelfPid
394443 send server1 "Hi"
395444 send server2 (Pong pid)
396− Ping pid' <- expect
397− True <- return $ pid' == server2
398− liftIO $ putMVar clientDone ()
445+ expectPing clientDone
399446
400− takeMVar clientDone
447+ verifyClient "Expected Ping from server" clientDone
401448
402449-- | Test (non-zero) timeout
403450testTimeout :: TestTransport -> Assertion
@@ -406,10 +453,10 @@ testTimeout TestTransport{..} = do
406453 done <- newEmptyMVar
407454
408455 runProcess localNode $ do
409− Nothing <- receiveTimeout 1000000 [match (\(Add _ _ _) -> return ())]
410− liftIO $ putMVar done ()
456+ res <- receiveTimeout 1000000 [match (\Add{} -> return ())]
457+ liftIO $ putMVar done $ res == Nothing
411458
412− takeMVar done
459+ verifyClient "Expected receiveTimeout to timeout..." done
413460
414461-- | Test zero timeout
415462testTimeout0 :: TestTransport -> Assertion
@@ -437,10 +484,9 @@ testTimeout0 TestTransport{..} = do
437484 -- is not interested in, and then a single message that it wants
438485 replicateM_ 10000 $ send server "Irrelevant message"
439486 send server (Pong pid)
440− Ping _ <- expect
441− liftIO $ putMVar clientDone ()
487+ expectPing clientDone
442488
443− takeMVar clientDone
489+ verifyClient "Expected Ping from server" clientDone
444490
445491-- | Test typed channels
446492testTypedChannels :: TestTransport -> Assertion
@@ -463,10 +509,10 @@ testTypedChannels TestTransport{..} = do
463509 runProcess localNode $ do
464510 (clientSendPort, rport) <- newChan
465511 sendChan serverSendPort (clientSendPort, 5)
466− False <- receiveChan rport
467− liftIO $ putMVar clientDone ()
512+ ch <- receiveChan rport
513+ liftIO $ putMVar clientDone $ ch == False
468514
469− takeMVar clientDone
515+ verifyClient "Expected channel to send 'False'" clientDone
470516
471517-- | Test merging receive ports
472518testMergeChannels :: TestTransport -> Assertion
@@ -489,9 +535,8 @@ testMergeChannels TestTransport{..} = do
489535 rs <- mapM charChannel "abc"
490536 m <- mergePorts biased rs
491537 xs <- replicateM 9 $ receiveChan m
492− True <- return $ xs == expected
493− liftIO $ putMVar done ()
494− takeMVar done
538+ liftIO $ putMVar done $ xs == expected
539+ verifyClient "Expected single layer merge to match expected ordering" done
495540
496541 -- Two layers of merging
497542 testNested :: LocalNode -> Bool -> Bool -> String -> IO ()
@@ -502,9 +547,8 @@ testMergeChannels TestTransport{..} = do
502547 ms <- mapM (mergePorts biasedInner) rss
503548 m <- mergePorts biasedOuter ms
504549 xs <- replicateM (9 * 3) $ receiveChan m
505− True <- return $ xs == expected
506− liftIO $ putMVar done ()
507− takeMVar done
550+ liftIO $ putMVar done $ xs == expected
551+ verifyClient "Expected nested channels to match expeted ordering" done
508552
509553 -- Test that if no messages are (immediately) available, the scheduler makes no difference
510554 testBlocked :: LocalNode -> Bool -> IO ()
@@ -513,43 +557,45 @@ testMergeChannels TestTransport{..} = do
513557 done <- newEmptyMVar
514558
515559 forkProcess localNode $ do
516− [sa, sb, sc] <- liftIO $ mapM readMVar vs
517− mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
518− [ -- a, b, c
519− (sa, 'a')
520− , (sb, 'b')
521− , (sc, 'c')
522− -- a, c, b
523− , (sa, 'a')
524− , (sc, 'c')
525− , (sb, 'b')
526− -- b, a, c
527− , (sb, 'b')
528− , (sa, 'a')
529− , (sc, 'c')
530− -- b, c, a
531− , (sb, 'b')
532− , (sc, 'c')
533− , (sa, 'a')
534− -- c, a, b
535− , (sc, 'c')
536− , (sa, 'a')
537− , (sb, 'b')
538− -- c, b, a
539− , (sc, 'c')
540− , (sb, 'b')
541− , (sa, 'a')
542− ]
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"
543590
544591 forkProcess localNode $ do
545592 (ss, rs) <- unzip <$> replicateM 3 newChan
546593 liftIO $ mapM_ (uncurry putMVar) $ zip vs ss
547594 m <- mergePorts biased rs
548595 xs <- replicateM (6 * 3) $ receiveChan m
549− True <- return $ xs == "abcacbbacbcacabcba"
550− liftIO $ putMVar done ()
596+ liftIO $ putMVar done $ xs == "abcacbbacbcacabcba"
551597
552− takeMVar done
598+ verifyClient "Expected merged ports to match expected ordering" done
553599
554600 mergePorts :: Serializable a => Bool -> [ReceivePort a] -> Process (ReceivePort a)
555601 mergePorts True = mergePortsBiased
@@ -567,8 +613,9 @@ testTerminate TestTransport{..} = do
567613 localNode <- newLocalNode testTransport initRemoteTable
568614 runProcess localNode $ do
569615 e <- try terminate :: Process (Either ProcessTerminationException ())
570− True <- return $ either show show e == show ProcessTerminationException
571− return ()
616+ if either show show e == show ProcessTerminationException
617+ then return ()
618+ else die "Unexpected result from terminate"
572619
573620testMonitorNode :: TestTransport -> Assertion
574621testMonitorNode TestTransport{..} = do
@@ -579,11 +626,12 @@ testMonitorNode TestTransport{..} = do
579626
580627 runProcess node2 $ do
581628 ref <- monitorNode (localNodeId node1)
582− NodeMonitorNotification ref' nid DiedDisconnect <- expect
583− True <- return $ ref == ref' && nid == localNodeId node1
584− liftIO $ putMVar done ()
629+ receiveWait [
630+ match (\(NodeMonitorNotification ref' nid DiedDisconnect) ->
631+ return $ ref == ref' && nid == localNodeId node1)
632+ ] >>= liftIO . putMVar done
585633
586− takeMVar done
634+ verifyClient "Expected NodeMonitorNotification with matching ref & nodeId" done
587635
588636testMonitorLiveNode :: TestTransport -> Assertion
589637testMonitorLiveNode TestTransport{..} = do
@@ -598,15 +646,16 @@ testMonitorLiveNode TestTransport{..} = do
598646 liftIO $ putMVar ready ()
599647 liftIO $ takeMVar readyr
600648 send p ()
601− NodeMonitorNotification ref' nid _ <- expect
602− True <- return $ ref == ref' && nid == localNodeId node1
603− liftIO $ putMVar done ()
649+ receiveWait [
650+ match (\(NodeMonitorNotification ref' nid _) ->
651+ (return $ ref == ref' && nid == localNodeId node1))
652+ ] >>= liftIO . putMVar done
604653
605654 takeMVar ready
606655 closeLocalNode node1
607656 putMVar readyr ()
608657
609− takeMVar done
658+ verifyClient "Expected NodeMonitorNotification for LIVE node" done
610659
611660testMonitorChannel :: TestTransport -> Assertion
612661testMonitorChannel TestTransport{..} = do
@@ -616,18 +665,20 @@ testMonitorChannel TestTransport{..} = do
616665 pid <- forkProcess node1 $ do
617666 sport <- expect :: Process (SendPort ())
618667 ref <- monitorPort sport
619− PortMonitorNotification ref' port' reason <- expect
620− -- reason might be DiedUnknownId if the receive port is GCed before the
621− -- monitor is established (TODO: not sure that this is reasonable)
622− return $ ref' == ref && port' == sendPortId sport && (reason == DiedNormal || reason == DiedUnknownId)
623− 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
624675
625676 runProcess node2 $ do
626677 (sport, _) <- newChan :: Process (SendPort (), ReceivePort ())
627678 send pid sport
628679 liftIO $ threadDelay 100000
629680
630− takeMVar gotNotification
681+ verifyClient "Expected PortMonitorNotification" gotNotification
631682
632683testRegistry :: TestTransport -> Assertion
633684testRegistry TestTransport{..} = do
@@ -639,20 +690,28 @@ testRegistry TestTransport{..} = do
639690
640691 runProcess node $ do
641692 register "ping" pingServer
642− Just pid <- whereis "ping"
643− True <- return $ pingServer == pid
693+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
644694 us <- getSelfPid
645695 nsend "ping" (Pong us)
646− Ping pid' <- expect
647− True <- return $ pingServer == pid'
648− Left (ProcessRegistrationException "dead" Nothing) <- try $ register "dead" deadProcess
649− Left (ProcessRegistrationException "ping" (Just x)) <- try $ register "ping" deadProcess
650− True <- return $ x == pingServer
651− 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
652702 liftIO $ putMVar done ()
653703
654704 takeMVar done
655705
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+
656715testRegistryRemoteProcess :: TestTransport -> Assertion
657716testRegistryRemoteProcess TestTransport{..} = do
658717 node1 <- newLocalNode testTransport initRemoteTable
@@ -663,13 +722,13 @@ testRegistryRemoteProcess TestTransport{..} = do
663722
664723 runProcess node2 $ do
665724 register "ping" pingServer
666− Just pid <- whereis "ping"
667− True <- return $ pingServer == pid
725+ whereis "ping" >>= liftIO . assertBool "Unexpected ping" . (== Just pingServer)
668726 us <- getSelfPid
669727 nsend "ping" (Pong us)
670− Ping pid' <- expect
671− True <- return $ pingServer == pid'
672− liftIO $ putMVar done ()
728+ receiveWait [
729+ matchIf (\(Ping pid') -> pingServer == pid')
730+ (const $ liftIO $ putMVar done ())
731+ ]
673732
674733 takeMVar done
675734
@@ -690,12 +749,13 @@ testRemoteRegistry TestTransport{..} = do
690749 "ping" == label' && pid == pingServer)
691750 (\(RegisterReply _ _ _) -> return ()) ]
692751
693− Just pid <- whereisRemote nid1 "ping"
694− True <- return $ pingServer == pid
752+ pid <- verifyWhereIsRemote nid1 "ping"
753+ liftIO $ assertBool "Expected pindServer to match pid" $ pingServer == pid
695754 us <- getSelfPid
696755 nsendRemote nid1 "ping" (Pong us)
697− Ping pid' <- expect
698− True <- return $ pingServer == pid'
756+ receiveWait [
757+ match (\(Ping pid') -> return $ pingServer == pid')
758+ ] >>= liftIO . assertBool "Expected Ping with ping server's ProcessId"
699759
700760 -- test that if process was not registered Nothing is returned
701761 -- in owner field.
@@ -731,15 +791,15 @@ testRemoteRegistryRemoteProcess TestTransport{..} = do
731791 receiveWait [
732792 matchIf (\(RegisterReply label' _ _) -> "ping" == label')
733793 (\(RegisterReply _ _ _) -> return ()) ]
734− Just pid <- whereisRemote nid1 "ping"
735− True <- return $ pingServer == pid
794+ pid <- verifyWhereIsRemote nid1 "ping"
795+ liftIO $ assertBool "Expected pingServer to match remote name" $ pingServer == pid
736796 us <- getSelfPid
737797 nsendRemote nid1 "ping" (Pong us)
738− Ping pid' <- expect
739− True <- return $ pingServer == pid'
740− liftIO $ putMVar done ()
798+ receiveWait [
799+ match (\(Ping pid') -> return $ pingServer == pid')
800+ ] >>= liftIO . putMVar done
741801
742− takeMVar done
802+ verifyClient "Expected Ping with ping server's ProcessId" done
743803
744804testSpawnLocal :: TestTransport -> Assertion
745805testSpawnLocal TestTransport{..} = do
@@ -753,15 +813,14 @@ testSpawnLocal TestTransport{..} = do
753813 sport <- expect
754814 sendChan sport (1234 :: Int)
755815
756− sport <- spawnChannelLocal $ \rport -> do
757− (1234 :: Int) <- receiveChan rport
758− send us ()
816+ sport <- spawnChannelLocal $
817+ \rport -> (receiveChan rport :: Process Int) >>= send us
759818
760819 send pid sport
761− () <- expect
762− liftIO $ putMVar done ()
820+ expect >>= liftIO . putMVar done
763821
764− takeMVar done
822+ res <- takeMVar done
823+ assertBool "Expected 1234 :: Int" $ res == (1234 :: Int)
765824
766825testSpawnAsyncStrictness :: TestTransport -> Assertion
767826testSpawnAsyncStrictness TestTransport{..} = do
@@ -790,8 +849,9 @@ testReconnect TestTransport{..} = do
790849 liftIO $ putMVar processA us
791850 msg1 <- expect
792851 msg2 <- expect
793− True <- return $ msg1 == "message 1" && msg2 == "message 3"
794− liftIO $ putMVar sendTestOk ()
852+ liftIO $ do
853+ assertBool "messages did not match" $ msg1 == "message 1" && msg2 == "message 3"
854+ putMVar sendTestOk ()
795855
796856 forkProcess node2 $ do
797857 {-
@@ -824,7 +884,7 @@ testReconnect TestTransport{..} = do
824884 matchIf (\(RegisterReply label' _ _) -> "a" == label')
825885 (\(RegisterReply _ _ _) -> return ()) ]
826886
827− Just _ <- whereisRemote nid1 "a"
887+ _ <- whereisRemote nid1 "a"
828888
829889
830890 -- Simulate network failure
@@ -843,9 +903,10 @@ testReconnect TestTransport{..} = do
843903 (\(RegisterReply _ _ _) -> return ()) ]
844904
845905 -- Check
846− Nothing <- whereisRemote nid1 "a" -- this will fail because the name is removed when the node is disconnected
847− Just _ <- whereisRemote nid1 "b" -- this will suceed because the value is set after thereconnect
848− 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"
849910
850911 liftIO $ putMVar registerTestOk ()
851912
@@ -886,13 +947,14 @@ testUSend usendPrim TestTransport{..} numMessages = do
886947 isSorted _ = True
887948 -- The list can't be null since there are no failures after sending
888949 -- the last message.
889− True <- return $ isSorted msgs && not (null msgs)
890− liftIO $ putMVar usendTestOk ()
950+ liftIO $ do
951+ assertBool "Unexpected failure after sending last msg" $ isSorted msgs && not (null msgs)
952+ putMVar usendTestOk ()
891953
892954 forkProcess node2 $ do
893955 them <- liftIO $ readMVar processA
894956 getSelfPid >>= send them
895− () <- expect
957+ expect :: Process ()
896958 forM_ [1..numMessages] $ \i -> do
897959 liftIO $ testBreakConnection (nodeAddress nid1) (nodeAddress nid2)
898960 usendPrim them i
@@ -924,14 +986,17 @@ testMatchAny TestTransport{..} = do
924986 runProcess localNode $ do
925987 pid <- getSelfPid
926988 send mathServer (Add pid 1 2)
927− 3 <- expect :: Process Double
989+ three <- expect :: Process Double
928990 send mathServer (Divide pid 8 2)
929− 4 <- expect :: Process Double
991+ four <- expect :: Process Double
930992 send mathServer (Divide pid 8 0)
931− DivByZero <- expect
932− liftIO $ putMVar clientDone ()
993+ divByZ <- expect
994+ liftIO $ putMVar clientDone (three, four, divByZ)
933995
934− takeMVar clientDone
996+ res <- takeMVar clientDone
997+ case res of
998+ (3, 4, DivByZero) -> return ()
999+ _ -> error "Unexpected result"
9351000
9361001-- | Test 'matchAny'. This repeats the 'testMath' but with a proxy server
9371002-- in between, however we block 'Divide' requests ....
@@ -958,12 +1023,13 @@ testMatchAnyHandle TestTransport{..} = do
9581023 runProcess localNode $ do
9591024 pid <- getSelfPid
9601025 send mathServer (Add pid 1 2)
961− 3 <- expect :: Process Double
1026+ three <- expect :: Process Double
9621027 send mathServer (Divide pid 8 2)
963− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
964− liftIO $ putMVar clientDone ()
1028+ res <- (expectTimeout 100000) :: Process (Maybe Double)
1029+ liftIO $ putMVar clientDone $ three == 3 && res == Nothing
1030+
1031+ verifyClient "Expected Nothing (i.e. timeout)" clientDone
9651032
966− takeMVar clientDone
9671033 where maybeForward :: ProcessId -> Message -> Process (Maybe ())
9681034 maybeForward s msg =
9691035 handleMessage msg (\m@(Add _ _ _) -> send s m)
@@ -991,8 +1057,10 @@ testMatchAnyNoHandle TestTransport{..} = do
9911057 Just _ -> die "NONSENSE")
9921058 ]
9931059 -- we *must* have removed the message from our mailbox though!!!
994− Nothing <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
995− liftIO $ putMVar serverDone ()
1060+ res <- receiveTimeout 100000 [ match (\(Add _ _ _) -> return ()) ]
1061+ liftIO $ do
1062+ assertBool "Expected timeout!" $ res == Nothing
1063+ putMVar serverDone ()
9961064 putMVar addr server
9971065
9981066 -- Client
@@ -1035,14 +1103,21 @@ testMatchAnyIf TestTransport{..} = do
10351103 runProcess localNode $ do
10361104 pid <- getSelfPid
10371105 send server (pid, "foo")
1038− "foo" <- expect
1039− send server (pid, "baz")
1040− "baz" <- expect
1106+ foo <- expect
1107+ -- provoking what would be the wrong ordering is informative here...
1108+
10411109 send server (pid, "bar")
1042− Nothing <- (expectTimeout 100000) :: Process (Maybe Double)
1043− liftIO $ putMVar clientDone ()
1110+ bar <- (expectTimeout 100000) :: Process (Maybe String) -- was Double o_O !?
1111+
1112+ send server (pid, "baz")
1113+ baz <- expect
1114+
1115+ liftIO $ putMVar clientDone (foo, bar, baz)
1116+
1117+ res <- takeMVar clientDone
1118+ let res' = res == ("foo", Nothing, "baz")
1119+ assertBool "Expected timeout due to type mismatch" res'
10441120
1045− takeMVar clientDone
10461121 where tryHandleMessage :: Message -> Process (Maybe ())
10471122 tryHandleMessage msg =
10481123 handleMessage msg (\(pid :: ProcessId, (m :: String))
@@ -1075,12 +1150,13 @@ testMatchMessageWithUnwrap TestTransport{..} = do
10751150 runProcess localNode $ do
10761151 pid <- getSelfPid
10771152 send server (pid, wrapMessage ("foo" :: String))
1078− "foo" <- expect
1153+ foo <- expect
10791154 send server (pid, wrapMessage ("baz" :: String))
1080− "baz" <- expect
1081− liftIO $ putMVar clientDone ()
1155+ baz <- expect
1156+ liftIO $ putMVar clientDone (foo, baz)
10821157
1083− takeMVar clientDone
1158+ res <- takeMVar clientDone
1159+ assertBool "Unexpected unwrapped results" $ res == ("foo", "baz")
10841160
10851161-- Test 'receiveChanTimeout'
10861162testReceiveChanTimeout :: TestTransport -> Assertion
@@ -1098,18 +1174,19 @@ testReceiveChanTimeout TestTransport{..} = do
10981174
10991175 -- Wait for a message with a delay. No message arrives, we should get
11001176 -- Nothing after the delay.
1101− Nothing <- receiveChanTimeout 100000 rp
1177+ receiveChanTimeout 100000 rp >>= maybe (return ()) (const $ die "Expected Timeout")
11021178
11031179 -- Let the sender know that it can send a message.
11041180 liftIO $ putMVar mvSender ()
11051181
11061182 -- Wait for a message with a delay again. Now a message arrives after
11071183 -- 0.1 seconds
1108− Just True <- receiveChanTimeout 20000000 rp
1184+ res <- receiveChanTimeout 20000000 rp >>= maybe (die "Timeout") return
1185+ liftIO $ assertBool "Expected result to be 'True'" res
11091186
11101187 -- Wait for a message with zero timeout: non-blocking check. No message is
11111188 -- available, we get Nothing
1112− Nothing <- receiveChanTimeout 0 rp
1189+ receiveChanTimeout 0 rp >>= maybe (return ()) (const $ die "Expected Timeout")
11131190
11141191 -- Let the sender know that it can send a message.
11151192 liftIO $ putMVar mvSender ()
@@ -1119,7 +1196,7 @@ testReceiveChanTimeout TestTransport{..} = do
11191196 liftIO $ threadDelay 100000
11201197 mb <- receiveChanTimeout 0 rp
11211198 case mb of
1122− Just b -> do False <- return b; return ()
1199+ Just b -> do liftIO $ assertBool "Unexpected Message" $ not b
11231200 _ -> loop
11241201
11251202 liftIO $ putMVar done ()
@@ -1156,8 +1233,8 @@ testReceiveChanFeatures TestTransport{..} = do
11561233
11571234 rp1 <- mergePortsBiased [even <$> rpInt, rpBool]
11581235
1159− True <- receiveChan rp1
1160− False <- receiveChan rp1
1236+ receiveChan rp1 >>= liftIO . assertBool "Expected True"
1237+ receiveChan rp1 >>= liftIO . assertBool "Expected False" . not
11611238
11621239 -- Test Applicative instance
11631240
@@ -1166,7 +1243,7 @@ testReceiveChanFeatures TestTransport{..} = do
11661243
11671244 let rp2 = pure (+) <*> rpInt <*> rpInt
11681245
1169− 7 <- receiveChan rp2
1246+ receiveChan rp2 >>= liftIO . assertBool "Expected 7" . (== 7)
11701247
11711248 -- Test Alternative instance
11721249
@@ -1175,8 +1252,8 @@ testReceiveChanFeatures TestTransport{..} = do
11751252
11761253 let rp3 = (even <$> rpInt) <|> rpBool
11771254
1178− False <- receiveChan rp3
1179− True <- receiveChan rp3
1255+ receiveChan rp3 >>= liftIO . assertBool "Expected False" . not
1256+ receiveChan rp3 >>= liftIO . assertBool "Expected True"
11801257
11811258 -- Test Monad instance
11821259
@@ -1190,8 +1267,8 @@ testReceiveChanFeatures TestTransport{..} = do
11901267 then rpInt
11911268 else return 7
11921269
1193− 5 <- receiveChan rp4
1194− 7 <- receiveChan rp4
1270+ receiveChan rp4 >>= liftIO . assertBool "Expected 5" . (== 5)
1271+ receiveChan rp4 >>= liftIO . assertBool "Expected 7" . (== 7)
11951272
11961273 liftIO $ putMVar done ()
11971274
@@ -1200,7 +1277,6 @@ testReceiveChanFeatures TestTransport{..} = do
12001277testKillLocal :: TestTransport -> Assertion
12011278testKillLocal TestTransport{..} = do
12021279 localNode <- newLocalNode testTransport initRemoteTable
1203− done <- newEmptyMVar
12041280
12051281 pid <- forkProcess localNode $ do
12061282 liftIO $ threadDelay 1000000
@@ -1209,17 +1285,18 @@ testKillLocal TestTransport{..} = do
12091285 ref <- monitor pid
12101286 us <- getSelfPid
12111287 kill pid "TestKill"
1212− ProcessMonitorNotification ref' pid' (DiedException ex) <- expect
1213− True <- return $ ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill"
1214− liftIO $ putMVar done ()
1215−
1216− takeMVar done
1288+ mn <- expect
1289+ case mn of
1290+ ProcessMonitorNotification ref' pid' (DiedException ex) ->
1291+ case ref == ref' && pid == pid' && ex == "killed-by=" ++ show us ++ ",reason=TestKill" of
1292+ True -> return ()
1293+ False -> die "Invalid ProcessMonitorNotification received"
1294+ _ -> die "Something went horribly wrong"
12171295
12181296testKillRemote :: TestTransport -> Assertion
12191297testKillRemote TestTransport{..} = do
12201298 node1 <- newLocalNode testTransport initRemoteTable
12211299 node2 <- newLocalNode testTransport initRemoteTable
1222− done <- newEmptyMVar
12231300
12241301 pid <- forkProcess node1 $ do
12251302 liftIO $ threadDelay 1000000
@@ -1228,11 +1305,17 @@ testKillRemote TestTransport{..} = do
12281305 ref <- monitor pid
12291306 us <- getSelfPid
12301307 kill pid "TestKill"
1231− ProcessMonitorNotification ref' pid' (DiedException reason) <- expect
1232− True <- return $ ref == ref' && pid == pid' && reason == "killed-by=" ++ show us ++ ",reason=TestKill"
1233− liftIO $ putMVar done ()
1234−
1235− takeMVar done
1308+ mn <- expect
1309+ case mn of
1310+ ProcessMonitorNotification ref' pid' (DiedException reason) ->
1311+ case (ref == ref', pid == pid', reason == "killed-by=" ++ show us ++ ",reason=TestKill") of
1312+ (True, True, True) -> return ()
1313+ (a, b, c) -> do
1314+ let a' = if a then "" else "Invalid ref"
1315+ let b' = if b then "" else "Invalid pid"
1316+ let c' = if c then "" else "Invalid message"
1317+ die $ unwords [a', b', c']
1318+ _ -> die "Received unexpected message"
12361319
12371320testCatchesExit :: TestTransport -> Assertion
12381321testCatchesExit TestTransport{..} = do
@@ -1258,7 +1341,10 @@ testHandleMessageIf TestTransport{..} = do
12581341 self <- getSelfPid
12591342 send self (5 :: Integer, 10 :: Integer)
12601343 msg <- receiveWait [ matchMessage return ]
1261− Nothing <- handleMessageIf msg (\() -> True) (\() -> die $ "whoops")
1344+ handleMessageIf msg
1345+ (\() -> True)
1346+ (\() -> die "whoops") >>= maybe (return ())
1347+ (const $ die "Expected Mismatch")
12621348 handleMessageIf msg (\(x :: Integer, y :: Integer) -> x == 5 && y == 10)
12631349 (\input -> liftIO $ putMVar done input)
12641350 return ()
@@ -1303,8 +1389,11 @@ testDie TestTransport{..} = do
13031389 (die ("foobar", 123 :: Int))
13041390 `catchExit` \_from reason -> do
13051391 -- TODO: should verify that 'from' has the right value
1306− True <- return $ reason == ("foobar", 123 :: Int)
1392+ let res = reason == ("foobar", 123 :: Int)
13071393 liftIO $ putMVar done ()
1394+ if res
1395+ then return ()
1396+ else die "Something went horribly wrong"
13081397
13091398 takeMVar done
13101399
@@ -1318,8 +1407,11 @@ testPrettyExit TestTransport{..} = do
13181407 `catch` \ex@(ProcessExitException from _) ->
13191408 let expected = "exit-from=" ++ (show from)
13201409 in do
1321− True <- return $ (show ex) == expected
1410+ let res = (show ex) == expected
13221411 liftIO $ putMVar done ()
1412+ if res
1413+ then return ()
1414+ else die "Something went horribly wrong"
13231415
13241416 takeMVar done
13251417
@@ -1335,17 +1427,26 @@ testExitLocal TestTransport{..} = do
13351427 pid <- forkProcess localNode $ do
13361428 (liftIO (putMVar handlerSetUp ()) >> expect) `catchExit` \_from reason -> do
13371429 -- TODO: should verify that 'from' has the right value
1338− True <- return $ reason == "TestExit"
1430+ res <- return $ reason == "TestExit"
13391431 liftIO $ putMVar supervisedDone ()
1432+ if res
1433+ then return ()
1434+ else die "Something went horribly wrong"
13401435
13411436 runProcess localNode $ do
13421437 liftIO $ takeMVar handlerSetUp
13431438 ref <- monitor pid
13441439 exit pid "TestExit"
13451440 -- This time the client catches the exception, so it dies normally
1346− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1347− True <- return $ ref == ref' && pid == pid'
1348− liftIO $ putMVar supervisorDone ()
1441+ mn <- expect
1442+ case mn of
1443+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1444+ let res = ref == ref' && pid == pid'
1445+ liftIO $ putMVar supervisorDone ()
1446+ if res
1447+ then return ()
1448+ else die "Something went horribly wrong"
1449+ _ -> die "Something went horribly wrong"
13491450
13501451 takeMVar supervisedDone
13511452 takeMVar supervisorDone
@@ -1361,19 +1462,90 @@ testExitRemote TestTransport{..} = do
13611462 (receiveWait [] :: Process ()) -- block forever
13621463 `catchExit` \_from reason -> do
13631464 -- TODO: should verify that 'from' has the right value
1364− True <- return $ reason == "TestExit"
1465+ res <- return $ reason == "TestExit"
13651466 liftIO $ putMVar supervisedDone ()
1467+ if res
1468+ then return ()
1469+ else die "Something went horribly wrong"
13661470
13671471 runProcess node2 $ do
13681472 ref <- monitor pid
13691473 exit pid "TestExit"
1370− ProcessMonitorNotification ref' pid' DiedNormal <- expect
1371− True <- return $ ref == ref' && pid == pid'
1372− liftIO $ putMVar supervisorDone ()
1474+ mn <- expect
1475+ case mn of
1476+ ProcessMonitorNotification ref' pid' DiedNormal -> do
1477+ res' <- return $ ref == ref' && pid == pid'
1478+ liftIO $ putMVar supervisorDone ()
1479+ if res'
1480+ then return ()
1481+ else die "Something went horribly wrong"
1482+ _ -> die "Something went horribly wrong"
13731483
13741484 takeMVar supervisedDone
13751485 takeMVar supervisorDone
13761486
1487+testRegistryMonitoring :: TestTransport -> Assertion
1488+testRegistryMonitoring TestTransport{..} = do
1489+ node1 <- newLocalNode testTransport initRemoteTable
1490+ node2 <- newLocalNode testTransport initRemoteTable
1491+ waitH <- newEmptyMVar
1492+
1493+ let nid = localNodeId node2
1494+ pid <- forkProcess node1 $ do
1495+ getSelfPid >>= runUntilRegistered nid
1496+ liftIO $ takeMVar waitH
1497+
1498+ runProcess node2 $ do
1499+ register regName pid
1500+ res <- whereis regName
1501+ us <- getSelfPid
1502+ liftIO $ do
1503+ putMVar waitH ()
1504+ assertBool "expected (Just pid)" $ res == (Just pid)
1505+
1506+ -- This delay isn't essential!
1507+ -- The test case passes perfectly fine without it (feel free to comment out
1508+ -- and see), however waiting a few seconds here, makes it much more likely
1509+ -- that in delayUntilMaybeUnregistered we will hit the match case right
1510+ -- away, and thus not be subjected to a 20 second delay. The value of 4
1511+ -- seconds appears to work optimally on osx and across several linux distros
1512+ -- running in virtual machines (which is essentially what we do in CI)
1513+ void $ receiveTimeout 4000000 [ matchAny return ]
1514+
1515+ -- This delay doesn't serve much purpose in the happy path, however if some
1516+ -- future patch breaks the cooperative behaviour of node controllers viz
1517+ -- remote process registration and notification taking place via ncEffectDied,
1518+ -- there would be the possibility of a race in the test case should we attempt
1519+ -- to evaluate `whereis regName` on node2 right away. In case the name is still
1520+ -- erroneously registered, observing the 20 second delay (or lack of), could at
1521+ -- least give a hint that something is wrong, and we give up our time slice
1522+ -- so that there's a higher change the registrations have been cleaned up
1523+ -- in either case.
1524+ runProcess node2 $ delayUntilMaybeUnregistered nid pid
1525+
1526+ regHere <- newEmptyMVar
1527+ runProcess node2 $ whereis regName >>= liftIO . putMVar regHere
1528+ res <- takeMVar regHere
1529+ assertBool "expected Nothing, but process still registered" (res == Nothing)
1530+
1531+ where
1532+ runUntilRegistered nid us = do
1533+ whereisRemoteAsync nid regName
1534+ receiveWait [
1535+ matchIf (\(WhereIsReply n (Just p)) -> n == regName && p == us)
1536+ (const $ return ())
1537+ ]
1538+
1539+ delayUntilMaybeUnregistered nid p = do
1540+ whereisRemoteAsync nid regName
1541+ receiveTimeout 20000000 {- 20 sec delay -} [
1542+ matchIf (\(WhereIsReply n p) -> n == regName && p == Nothing)
1543+ (const $ return ())
1544+ ]
1545+ return ()
1546+
1547+ regName = "testRegisterRemote"
1548+
13771549testUnsafeSend :: TestTransport -> Assertion
13781550testUnsafeSend TestTransport{..} = do
13791551 serverAddr <- newEmptyMVar
@@ -1389,8 +1561,7 @@ testUnsafeSend TestTransport{..} = do
13891561 void $ forkProcess localNode $ do
13901562 serverPid <- liftIO $ takeMVar serverAddr
13911563 getSelfPid >>= unsafeSend serverPid
1392− () <- expect
1393− liftIO $ putMVar clientDone ()
1564+ expect >>= liftIO . putMVar clientDone
13941565
13951566 takeMVar clientDone
13961567
@@ -1409,8 +1580,7 @@ testUnsafeUSend TestTransport{..} = do
14091580 void $ forkProcess localNode $ do
14101581 serverPid <- liftIO $ takeMVar serverAddr
14111582 getSelfPid >>= unsafeUSend serverPid
1412− () <- expect
1413− liftIO $ putMVar clientDone ()
1583+ expect >>= liftIO . putMVar clientDone
14141584
14151585 takeMVar clientDone
14161586
@@ -1421,8 +1591,7 @@ testUnsafeNSend TestTransport{..} = do
14211591 localNode <- newLocalNode testTransport initRemoteTable
14221592
14231593 pid <- forkProcess localNode $ do
1424− () <- expect
1425− liftIO $ putMVar clientDone ()
1594+ expect >>= liftIO . putMVar clientDone
14261595
14271596 void $ runProcess localNode $ do
14281597 register "foobar" pid
@@ -1440,8 +1609,7 @@ testUnsafeNSendRemote TestTransport{..} = do
14401609 _ <- forkProcess localNode1 $ do
14411610 getSelfPid >>= register "foobar"
14421611 liftIO $ putMVar clientDone ()
1443− () <- expect
1444− liftIO $ putMVar clientDone ()
1612+ expect >>= liftIO . putMVar clientDone
14451613
14461614 takeMVar clientDone
14471615 void $ runProcess localNode2 $ do
@@ -1465,7 +1633,7 @@ testUnsafeSendChan TestTransport{..} = do
14651633 serverPid <- liftIO $ takeMVar serverAddr
14661634 (sp, rp) <- newChan
14671635 unsafeSend serverPid sp
1468− () <- receiveChan rp
1636+ receiveChan rp :: Process ()
14691637 liftIO $ putMVar clientDone ()
14701638
14711639 takeMVar clientDone
@@ -1479,8 +1647,8 @@ testCallLocal TestTransport{..} = do
14791647 runProcess node $ do
14801648 r <- (/=) <$> getSelfPid <*> callLocal getSelfPid
14811649 liftIO $ putMVar result r
1482− True <- takeMVar result
1483− return ()
1650+
1651+ takeMVar result >>= assertBool "Expected 'True'"
14841652
14851653 -- Testing that when callLocal is interrupted, the worker is interrupted.
14861654 ibox <- newIORef False
@@ -1497,10 +1665,9 @@ testCallLocal TestTransport{..} = do
14971665 (send keeper ())
14981666 caller <- expect
14991667 exit caller "test"
1500− () <- expect
1501− return ()
1502− True <- readIORef ibox
1503− return ()
1668+ expect :: Process ()
1669+
1670+ readIORef ibox >>= assertBool "Expected 'True'"
15041671
15051672 -- Testing that when the worker raises an exception, the exception is propagated to the parent.
15061673 ibox2 <- newIORef False
@@ -1509,8 +1676,8 @@ testCallLocal TestTransport{..} = do
15091676 liftIO $ writeIORef ibox2 $ case r of
15101677 Left (ErrorCall "e") -> True
15111678 _ -> False
1512− True <- readIORef ibox
1513− return ()
1679+
1680+ readIORef ibox >>= assertBool "Expected 'True'"
15141681
15151682 -- Test that caller waits for the worker in correct situation
15161683 ibox3 <- newIORef False
@@ -1527,8 +1694,8 @@ testCallLocal TestTransport{..} = do
15271694 liftIO $ putMVar result3 =<< readIORef ibox3
15281695 worker <- expect
15291696 send worker ()
1530− True <- takeMVar result3
1531− return ()
1697+
1698+ takeMVar result3 >>= assertBool "Expected 'True'"
15321699
15331700 -- Test that caller waits for the worker in case when caller gets an exception
15341701 ibox4 <- newIORef False
@@ -1544,13 +1711,9 @@ testCallLocal TestTransport{..} = do
15441711 `finally` (liftIO $ putMVar result4 =<< readIORef ibox4)
15451712 caller <- expect
15461713 exit caller "hi!"
1547− True <- takeMVar result4
1548− return ()
1549− -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
1550−
1551−
1552−
15531714
1715+ takeMVar result4 >>= assertBool "Expected 'True'"
1716+ -- XXX: Testing that when mask_ $ callLocal p runs p in masked state.
15541717
15551718tests :: TestTransport -> IO [Test]
15561719tests testtrans = return [
@@ -1584,6 +1747,7 @@ tests testtrans = return [
15841747 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
15851748 , testCase "ExitLocal" (testExitLocal testtrans)
15861749 , testCase "ExitRemote" (testExitRemote testtrans)
1750+ , testCase "RegistryMonitoring" (testRegistryMonitoring testtrans)
15871751 , testCase "TextCallLocal" (testCallLocal testtrans)
15881752 -- Unsafe Primitives
15891753 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
@@ -1636,17 +1800,3 @@ tests testtrans = return [
16361800 , testCase "MonitorUnreachable" (testMonitorUnreachable testtrans True False)
16371801 ]
16381802 ]
1639−
1640−syncBreakConnection :: (NT.EndPointAddress -> NT.EndPointAddress -> IO ()) -> LocalNode -> LocalNode -> IO ()
1641−syncBreakConnection breakConnection nid0 nid1 = do
1642− m <- newEmptyMVar
1643− _ <- forkProcess nid1 $ getSelfPid >>= liftIO . putMVar m
1644− runProcess nid0 $ do
1645− them <- liftIO $ takeMVar m
1646− pinger <- spawnLocal $ forever $ send them ()
1647− _ <- monitorNode (localNodeId nid1)
1648− liftIO $ breakConnection (nodeAddress $ localNodeId nid0)
1649− (nodeAddress $ localNodeId nid1)
1650− NodeMonitorNotification _ _ _ <- expect
1651− kill pinger "finished"
1652− return ()
distributed-process-tests/src/Control/Distributed/Process/Tests/Closure.hs+83−44
@@ -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
@@ -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+190−38
@@ -21,10 +21,11 @@ import Control.Distributed.Process.Management
2121 , mxNotify
2222 , mxBroadcast
2323 )
24−import Control.Monad (void)
24+import Control.Monad (void, unless)
25+import Control.Rematch (equalTo)
2526import Data.Binary
2627import Data.List (find, sort)
27−import Data.Maybe (isJust)
28+import Data.Maybe (isJust, isNothing)
2829import Data.Typeable
2930import GHC.Generics
3031#if ! MIN_VERSION_base(4,6,0)
@@ -42,6 +43,16 @@ data Publish = Publish
4243
4344instance Binary Publish where
4445
46+awaitExit :: ProcessId -> Process ()
47+awaitExit pid =
48+ withMonitorRef pid $ \ref -> do
49+ receiveWait
50+ [ matchIf (\(ProcessMonitorNotification r _ _) -> r == ref)
51+ (\_ -> return ())
52+ ]
53+ where
54+ withMonitorRef pid = bracket (monitor pid) unmonitor
55+
4556testAgentBroadcast :: TestResult () -> Process ()
4657testAgentBroadcast result = do
4758 (resultSP, resultRP) <- newChan :: Process (SendPort (), ReceivePort ())
@@ -59,13 +70,13 @@ testAgentBroadcast result = do
5970 -- and the consumer will see that and send the result to our typed channel.
6071 stash result =<< receiveChan resultRP
6172
62− kill publisher "finished"
63− kill consumer "finished"
73+ kill publisher "finished" >> awaitExit publisher
74+ kill consumer "finished" >> awaitExit consumer
6475
6576testAgentDualInput :: TestResult (Maybe Int) -> Process ()
6677testAgentDualInput result = do
6778 (sp, rp) <- newChan
68− _ <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
79+ s <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
6980 mxSink $ (\(i :: Int) -> do
7081 mxSetLocal . (+i) =<< mxGetLocal
7182 i' <- mxGetLocal
@@ -82,6 +93,7 @@ testAgentDualInput result = do
8293 mxNotify (5 :: Int)
8394
8495 stash result =<< receiveChanTimeout 10000000 rp
96+ awaitExit s
8597
8698testAgentPrioritisation :: TestResult [String] -> Process ()
8799testAgentPrioritisation result = do
@@ -93,8 +105,8 @@ testAgentPrioritisation result = do
93105
94106 let name = "prioritising-agent"
95107 (sp, rp) <- newChan
96− void $ mxAgent (MxAgentId name) ["first"] [
97− mxSink (\(s :: String) -> do
108+ s <- mxAgent (MxAgentId name) ["first"] [
109+ mxSink (\(s :: String) -> do
98110 mxUpdateLocal ((s:))
99111 st <- mxGetLocal
100112 case length st of
@@ -110,22 +122,25 @@ testAgentPrioritisation result = do
110122 nsend name "fifth"
111123
112124 stash result . sort =<< receiveChan rp
125+ awaitExit s
113126
114127testAgentMailboxHandling :: TestResult (Maybe ()) -> Process ()
115128testAgentMailboxHandling result = do
116129 (sp, rp) <- newChan
117− agent <- mxAgent (MxAgentId "listener-agent") () [
130+ agent <- mxAgent (MxAgentId "mailbox-agent") () [
118131 mxSink $ \() -> (liftMX $ sendChan sp ()) >> mxReady
119132 ]
120133
121− nsend "listener-agent" ()
134+ nsend "mailbox-agent" ()
122135
123136 stash result =<< receiveChanTimeout 1000000 rp
124− kill agent "finished"
137+ kill agent "finished" >> awaitExit agent
125138
126139testAgentEventHandling :: TestResult Bool -> Process ()
127140testAgentEventHandling result = do
128141 let initState = [] :: [MxEvent]
142+
143+ (rc, rs) <- newChan
129144 agentPid <- mxAgent (MxAgentId "lifecycle-listener-agent") initState [
130145 (mxSink $ \ev -> do
131146 st <- mxGetLocal
@@ -134,7 +149,7 @@ testAgentEventHandling result = do
134149 (MxSpawned _) -> mxSetLocal (ev:st)
135150 (MxProcessDied _ _) -> mxSetLocal (ev:st)
136151 _ -> return ()
137− act >> mxReady),
152+ act >> (liftMX $ sendChan rc ()) >> mxReady),
138153 (mxSink $ \(ev, sp :: SendPort Bool) -> do
139154 st <- mxGetLocal
140155 let found =
@@ -154,16 +169,26 @@ testAgentEventHandling result = do
154169 mxReady)
155170 ]
156171
172+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
173+ faff 2000000 rs
174+
157175 _ <- monitor agentPid
158176 (sp, rp) <- newChan
159− pid <- spawnLocal $ sendChan sp ()
160− () <- receiveChan rp
177+
178+ pid <- spawnLocal $ expect >>= sendChan sp
161179
162180 -- By waiting for a monitor notification, we have a
163− -- higher probably that the agent has seen
181+ -- higher probably that the agent has seen the spawn and died events
164182 monitor pid
183+
184+ send pid ()
185+ () <- receiveChan rp
186+
165187 receiveWait [ match (\(ProcessMonitorNotification _ _ _) -> return ()) ]
166188
189+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
190+ faff 2000000 rs
191+
167192 (replyTo, reply) <- newChan :: Process (SendPort Bool, ReceivePort Bool)
168193 mxNotify (MxSpawned pid, replyTo)
169194 mxNotify (MxProcessDied pid DiedNormal, replyTo)
@@ -172,32 +197,159 @@ testAgentEventHandling result = do
172197 seenDead <- receiveChan reply
173198
174199 stash result $ seenAlive && seenDead
200+ kill agentPid "test-complete" >> awaitExit agentPid
201+ where
202+ faff delay port = do
203+ res <- receiveChanTimeout delay port
204+ unless (isNothing res) $ do
205+ pause delay
206+ faff delay port
207+
208+testMxRegEvents :: TestResult () -> Process ()
209+testMxRegEvents result = do
210+ {- This test only deals with the local case, to ensure that we are being
211+ notified in the expected order - the remote cases related to the
212+ behaviour of the node controller are contained in the CH test suite. -}
213+ ensure (stash result ()) $ do
214+ let label = "testMxRegEvents"
215+ let agentLabel = "mxRegEvents-agent"
216+ let delay = 1000000
217+ (regChan, regSink) <- newChan
218+ (unRegChan, unRegSink) <- newChan
219+ agent <- mxAgent (MxAgentId agentLabel) () [
220+ mxSink $ \ev -> do
221+ case ev of
222+ MxRegistered pid label'
223+ | label' == label -> liftMX $ sendChan regChan (label', pid)
224+ MxUnRegistered pid label'
225+ | label' == label -> liftMX $ sendChan unRegChan (label', pid)
226+ _ -> return ()
227+ mxReady
228+ ]
229+
230+ p1 <- spawnLocal expect
231+ p2 <- spawnLocal expect
232+
233+ register label p1
234+ reg1 <- receiveChanTimeout delay regSink
235+ reg1 `shouldBe` equalTo (Just (label, p1))
236+
237+ unregister label
238+ unreg1 <- receiveChanTimeout delay unRegSink
239+ unreg1 `shouldBe` equalTo (Just (label, p1))
240+
241+ register label p2
242+ reg2 <- receiveChanTimeout delay regSink
243+ reg2 `shouldBe` equalTo (Just (label, p2))
244+
245+ reregister label p1
246+ unreg2 <- receiveChanTimeout delay unRegSink
247+ unreg2 `shouldBe` equalTo (Just (label, p2))
248+
249+ reg3 <- receiveChanTimeout delay regSink
250+ reg3 `shouldBe` equalTo (Just (label, p1))
251+
252+ mapM_ (flip kill $ "test-complete") [agent, p1, p2]
253+ awaitExit agent
254+
255+testMxRegMon :: LocalNode -> TestResult () -> Process ()
256+testMxRegMon remoteNode result = do
257+ ensure (stash result ()) $ do
258+ -- ensure that when a registered process dies, we get a notification that
259+ -- it has been unregistered as well as seeing the name get removed
260+ let label1 = "aaaaa"
261+ let label2 = "bbbbb"
262+ let isValid l = l == label1 || l == label2
263+ let agentLabel = "mxRegMon-agent"
264+ let delay = 1000000
265+ (regChan, regSink) <- newChan
266+ (unRegChan, unRegSink) <- newChan
267+ agent <- mxAgent (MxAgentId agentLabel) () [
268+ mxSink $ \ev -> do
269+ case ev of
270+ MxRegistered pid label
271+ | isValid label -> liftMX $ sendChan regChan (label, pid)
272+ MxUnRegistered pid label
273+ | isValid label -> liftMX $ sendChan unRegChan (label, pid)
274+ _ -> return ()
275+ mxReady
276+ ]
277+
278+ (sp, rp) <- newChan
279+ liftIO $ forkProcess remoteNode $ do
280+ getSelfPid >>= sendChan sp
281+ expect :: Process ()
282+
283+ p1 <- receiveChan rp
284+
285+ register label1 p1
286+ reg1 <- receiveChanTimeout delay regSink
287+ reg1 `shouldBe` equalTo (Just (label1, p1))
288+
289+ register label2 p1
290+ reg2 <- receiveChanTimeout delay regSink
291+ reg2 `shouldBe` equalTo (Just (label2, p1))
292+
293+ n1 <- whereis label1
294+ n1 `shouldBe` equalTo (Just p1)
295+
296+ n2 <- whereis label2
297+ n2 `shouldBe` equalTo (Just p1)
298+
299+ kill p1 "goodbye"
300+
301+ unreg1 <- receiveChanTimeout delay unRegSink
302+ unreg2 <- receiveChanTimeout delay unRegSink
303+
304+ let evts = [unreg1, unreg2]
305+ -- we can't rely on the order of the values in the node controller's
306+ -- map (it's either racy to do so, or no such guarantee exists for Data.Map),
307+ -- so we simply verify that we received the un-registration events we expect
308+ evts `shouldContain` (Just (label1, p1))
309+ evts `shouldContain` (Just (label2, p1))
310+
311+ kill agent "test-complete" >> awaitExit agent
312+
313+ensure :: Process () -> Process () -> Process ()
314+ensure = flip finally
175315
176316tests :: TestTransport -> IO [Test]
177317tests TestTransport{..} = do
178318 node1 <- newLocalNode testTransport initRemoteTable
319+ node2 <- newLocalNode testTransport initRemoteTable
179320 return [
180− testGroup "Mx Agents" [
181− testCase "Event Handling"
182− (delayedAssertion
183− "expected True, but events where not as expected"
184− node1 True testAgentEventHandling)
185− , testCase "Inter-Agent Broadcast"
186− (delayedAssertion
187− "expected (), but no broadcast was received"
188− node1 () testAgentBroadcast)
189− , testCase "Agent Mailbox Handling"
190− (delayedAssertion
191− "expected (Just ()), but no regular (mailbox) input was handled"
192− node1 (Just ()) testAgentMailboxHandling)
193− , testCase "Agent Dual Input Handling"
194− (delayedAssertion
195− "expected sum = 15, but the result was Nothing"
196− node1 (Just 15 :: Maybe Int) testAgentDualInput)
197− , testCase "Agent Input Prioritisation"
198− (delayedAssertion
199− "expected [first, second, third, fourth, fifth], but result diverged"
200− node1 (sort ["first", "second",
201− "third", "fourth",
202− "fifth"]) testAgentPrioritisation)
203− ]]
321+ testGroup "Mx Agents" [
322+ testCase "Event Handling"
323+ (delayedAssertion
324+ "expected True, but events where not as expected"
325+ node1 True testAgentEventHandling)
326+ , testCase "Inter-Agent Broadcast"
327+ (delayedAssertion
328+ "expected (), but no broadcast was received"
329+ node1 () testAgentBroadcast)
330+ , testCase "Agent Mailbox Handling"
331+ (delayedAssertion
332+ "expected (Just ()), but no regular (mailbox) input was handled"
333+ node1 (Just ()) testAgentMailboxHandling)
334+ , testCase "Agent Dual Input Handling"
335+ (delayedAssertion
336+ "expected sum = 15, but the result was Nothing"
337+ node1 (Just 15 :: Maybe Int) testAgentDualInput)
338+ , testCase "Agent Input Prioritisation"
339+ (delayedAssertion
340+ "expected [first, second, third, fourth, fifth], but result diverged"
341+ node1 (sort ["first", "second",
342+ "third", "fourth",
343+ "fifth"]) testAgentPrioritisation)
344+ ]
345+ , testGroup "Mx Events" [
346+ testCase "Name Registration Events"
347+ (delayedAssertion
348+ "expected registration events to map to the correct ProcessId"
349+ node1 () testMxRegEvents)
350+ , testCase "Post Death Name UnRegistration Events"
351+ (delayedAssertion
352+ "expected process deaths to result in unregistration events"
353+ node1 () (testMxRegMon node2))
354+ ]
355+ ]
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/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+2−2
@@ -45,7 +45,7 @@ Library
4545 binary >= 0.6.3 && < 0.10,
4646 hashable >= 1.2.0.5 && < 1.3,
4747 network-transport >= 0.4.1.0 && < 0.6,
48− stm >= 2.4 && < 2.5,
48+ stm >= 2.4 && < 2.6,
4949 transformers >= 0.2 && < 0.6,
5050 mtl >= 2.0 && < 2.4,
5151 data-accessor >= 0.2 && < 0.3,
@@ -55,7 +55,7 @@ Library
5555 rank1dynamic >= 0.1 && < 0.5,
5656 syb >= 0.3 && < 0.8,
5757 exceptions >= 0.5,
58− containers >= 0.5 && < 0.6,
58+ containers >= 0.5 && < 0.7,
5959 deepseq >= 1.3.0.1 && < 1.6
6060 Exposed-modules: Control.Distributed.Process,
6161 Control.Distributed.Process.Closure,
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
@@ -112,6 +113,7 @@ newtype MxAgent s a =
112113 } deriving ( Functor
113114 , Monad
114115 , MonadIO
116+ , MonadFix
115117 , ST.MonadState (MxAgentState s)
116118 , Typeable
117119 , 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+4−1
@@ -3,12 +3,15 @@ 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
1417- exceptions-0.8.2.1 # test dependency
stack-ghc-8.0.2.yaml+6−1
@@ -1,14 +1,19 @@
11resolver: 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
1419# - exceptions-0.8.2.1 # test dependency
stack-ghc-8.2.2.yaml+4
@@ -3,6 +3,10 @@ resolver: lts-11.22
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
stack-ghc-8.4.4.yaml+5−1
@@ -1,8 +1,12 @@
1−resolver: lts-12.17
1+resolver: lts-12.18
22
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
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+5−2
@@ -1,16 +1,19 @@
1−resolver: nightly-2017-08-20
1+resolver: lts-12.18 # Use GHC 8.4.4
22
33# TODO: we can enable nightly-2018-11-11 once PR #319 is merged
44
55packages:
66- '.'
77- distributed-process-tests/
8+- location:
9+ git: https://github.com/haskell-distributed/network-transport-tcp.git
10+ commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
11+ extra-dep: true
812
913extra-deps:
1014- rank1dynamic-0.4.0
1115- distributed-static-0.3.8
1216- network-transport-0.5.2
13−- network-transport-tcp-0.6.0
1417- network-transport-inmemory-0.5.2
1518- rematch-0.2.0.0
1619