git.iko.soy/distributed-process
on master help sign in
Publish MxUnregistered when a registered name dies
commit003e522b986aa272256d1f5e935fba990acc54db authorTim Watson <watson.timothy@gmail.com> dateThu 15 Nov 2018, 23:32 (8 years ago) parentbbb3a2ea027f75
12 files changed+364−63
.travis.yml+11−6 distributed-process-tests/distributed-process-tests.cabal+16−3 distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+66 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 src/Control/Distributed/Process/Internal/Primitives.hs+1 src/Control/Distributed/Process/Management/Internal/Types.hs+2 src/Control/Distributed/Process/Node.hs+23−9 stack-ghc-8.2.2.yaml+20 stack-ghc-8.4.4.yaml+20 stack-nightly.yaml+3−3 stack.yaml+1−1
.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=
distributed-process-tests/distributed-process-tests.cabal+16−3
@@ -114,8 +114,7 @@ Test-Suite TestStats
114114 ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
115115 HS-Source-Dirs: tests
116116
117−
118−Test-Suite TestMx
117+Test-Suite TestMxInMemory
119118 Type: exitcode-stdio-1.0
120119 Main-Is: runInMemory.hs
121120 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
@@ -129,7 +128,7 @@ Test-Suite TestMx
129128 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
130129 HS-Source-Dirs: tests
131130
132−Test-Suite TestTracing
131+Test-Suite TestTracingInMemory
133132 Type: exitcode-stdio-1.0
134133 Main-Is: runInMemory.hs
135134 CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Tracing
@@ -142,3 +141,17 @@ Test-Suite TestTracing
142141 Extensions: CPP
143142 ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
144143 HS-Source-Dirs: tests
144+
145+Test-Suite TestMxInTCP
146+ Type: exitcode-stdio-1.0
147+ Main-Is: runInMemory.hs
148+ CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
149+ Build-Depends: base >= 4.4 && < 5,
150+ distributed-process-tests,
151+ network >= 2.3 && < 2.9,
152+ network-transport >= 0.4.1.0 && < 0.6,
153+ network-transport-inmemory >= 0.5,
154+ test-framework >= 0.6 && < 0.9
155+ Extensions: CPP
156+ ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
157+ HS-Source-Dirs: tests
distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+66
@@ -37,6 +37,9 @@ import Control.Distributed.Process.Internal.Types
3737 , createUnencodedMessage
3838 )
3939import Control.Distributed.Process.Node
40+import Control.Distributed.Process.Debug
41+import Control.Distributed.Process.Management.Internal.Types
42+import Control.Distributed.Process.Tests.Internal.Utils (shouldBe)
4043import Control.Distributed.Process.Serializable (Serializable)
4144
4245import Test.HUnit (Assertion, assertBool, assertFailure)
@@ -1476,6 +1479,68 @@ testExitRemote TestTransport{..} = do
14761479 takeMVar supervisedDone
14771480 takeMVar supervisorDone
14781481
1482+testRegistryMonitoring :: TestTransport -> Assertion
1483+testRegistryMonitoring TestTransport{..} = do
1484+ node1 <- newLocalNode testTransport initRemoteTable
1485+ node2 <- newLocalNode testTransport initRemoteTable
1486+ waitH <- newEmptyMVar
1487+
1488+ let nid = localNodeId node2
1489+ pid <- forkProcess node1 $ do
1490+ getSelfPid >>= runUntilRegistered nid
1491+ liftIO $ takeMVar waitH
1492+
1493+ runProcess node2 $ do
1494+ register regName pid
1495+ res <- whereis regName
1496+ us <- getSelfPid
1497+ liftIO $ do
1498+ putMVar waitH ()
1499+ assertBool "expected (Just pid)" $ res == (Just pid)
1500+
1501+ -- This delay isn't essential!
1502+ -- The test case passes perfectly fine without it (feel free to comment out
1503+ -- and see), however waiting a few seconds here, makes it much more likely
1504+ -- that in delayUntilMaybeUnregistered we will hit the match case right
1505+ -- away, and thus not be subjected to a 20 second delay. The value of 4
1506+ -- seconds appears to work optimally on osx and across several linux distros
1507+ -- running in virtual machines (which is essentially what we do in CI)
1508+ void $ receiveTimeout 4000000 [ matchAny return ]
1509+
1510+ -- This delay doesn't serve much purpose in the happy path, however if some
1511+ -- future patch breaks the cooperative behaviour of node controllers viz
1512+ -- remote process registration and notification taking place via ncEffectDied,
1513+ -- there would be the possibility of a race in the test case should we attempt
1514+ -- to evaluate `whereis regName` on node2 right away. In case the name is still
1515+ -- erroneously registered, observing the 20 second delay (or lack of), could at
1516+ -- least give a hint that something is wrong, and we give up our time slice
1517+ -- so that there's a higher change the registrations have been cleaned up
1518+ -- in either case.
1519+ runProcess node2 $ delayUntilMaybeUnregistered nid pid
1520+
1521+ regHere <- newEmptyMVar
1522+ runProcess node2 $ whereis regName >>= liftIO . putMVar regHere
1523+ res <- takeMVar regHere
1524+ assertBool "expected Nothing, but process still registered" (res == Nothing)
1525+
1526+ where
1527+ runUntilRegistered nid us = do
1528+ whereisRemoteAsync nid regName
1529+ receiveWait [
1530+ matchIf (\(WhereIsReply n (Just p)) -> n == regName && p == us)
1531+ (const $ return ())
1532+ ]
1533+
1534+ delayUntilMaybeUnregistered nid p = do
1535+ whereisRemoteAsync nid regName
1536+ receiveTimeout 20000000 {- 20 sec delay -} [
1537+ matchIf (\(WhereIsReply n p) -> n == regName && p == Nothing)
1538+ (const $ return ())
1539+ ]
1540+ return ()
1541+
1542+ regName = "testRegisterRemote"
1543+
14791544testUnsafeSend :: TestTransport -> Assertion
14801545testUnsafeSend TestTransport{..} = do
14811546 serverAddr <- newEmptyMVar
@@ -1677,6 +1742,7 @@ tests testtrans = return [
16771742 , testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
16781743 , testCase "ExitLocal" (testExitLocal testtrans)
16791744 , testCase "ExitRemote" (testExitRemote testtrans)
1745+ , testCase "RegistryMonitoring" (testRegistryMonitoring testtrans)
16801746 , testCase "TextCallLocal" (testCallLocal testtrans)
16811747 -- Unsafe Primitives
16821748 , testCase "TestUnsafeSend" (testUnsafeSend testtrans)
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
@@ -23,10 +23,11 @@ import Control.Distributed.Process.Management
2323 , mxBroadcast
2424 , mxGetId
2525 )
26−import Control.Monad (void)
26+import Control.Monad (void, unless)
27+import Control.Rematch (equalTo)
2728import Data.Binary
2829import Data.List (find, sort)
29−import Data.Maybe (isJust)
30+import Data.Maybe (isJust, isNothing)
3031import Data.Typeable
3132import GHC.Generics
3233#if ! MIN_VERSION_base(4,6,0)
@@ -44,6 +45,16 @@ data Publish = Publish
4445
4546instance Binary Publish where
4647
48+awaitExit :: ProcessId -> Process ()
49+awaitExit pid =
50+ withMonitorRef pid $ \ref -> do
51+ receiveWait
52+ [ matchIf (\(ProcessMonitorNotification r _ _) -> r == ref)
53+ (\_ -> return ())
54+ ]
55+ where
56+ withMonitorRef pid = bracket (monitor pid) unmonitor
57+
4758testAgentBroadcast :: TestResult () -> Process ()
4859testAgentBroadcast result = do
4960 (resultSP, resultRP) <- newChan :: Process (SendPort (), ReceivePort ())
@@ -61,13 +72,13 @@ testAgentBroadcast result = do
6172 -- and the consumer will see that and send the result to our typed channel.
6273 stash result =<< receiveChan resultRP
6374
64− kill publisher "finished"
65− kill consumer "finished"
75+ kill publisher "finished" >> awaitExit publisher
76+ kill consumer "finished" >> awaitExit consumer
6677
6778testAgentDualInput :: TestResult (Maybe Int) -> Process ()
6879testAgentDualInput result = do
6980 (sp, rp) <- newChan
70− _ <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
81+ s <- mxAgent (MxAgentId "sum-agent") (0 :: Int) [
7182 mxSink $ (\(i :: Int) -> do
7283 mxSetLocal . (+i) =<< mxGetLocal
7384 i' <- mxGetLocal
@@ -84,6 +95,7 @@ testAgentDualInput result = do
8495 mxNotify (5 :: Int)
8596
8697 stash result =<< receiveChanTimeout 10000000 rp
98+ awaitExit s
8799
88100testAgentPrioritisation :: TestResult [String] -> Process ()
89101testAgentPrioritisation result = do
@@ -95,8 +107,8 @@ testAgentPrioritisation result = do
95107
96108 let name = "prioritising-agent"
97109 (sp, rp) <- newChan
98− void $ mxAgent (MxAgentId name) ["first"] [
99− mxSink (\(s :: String) -> do
110+ s <- mxAgent (MxAgentId name) ["first"] [
111+ mxSink (\(s :: String) -> do
100112 mxUpdateLocal ((s:))
101113 st <- mxGetLocal
102114 case length st of
@@ -112,22 +124,25 @@ testAgentPrioritisation result = do
112124 nsend name "fifth"
113125
114126 stash result . sort =<< receiveChan rp
127+ awaitExit s
115128
116129testAgentMailboxHandling :: TestResult (Maybe ()) -> Process ()
117130testAgentMailboxHandling result = do
118131 (sp, rp) <- newChan
119− agent <- mxAgent (MxAgentId "listener-agent") () [
132+ agent <- mxAgent (MxAgentId "mailbox-agent") () [
120133 mxSink $ \() -> (liftMX $ sendChan sp ()) >> mxReady
121134 ]
122135
123− nsend "listener-agent" ()
136+ nsend "mailbox-agent" ()
124137
125138 stash result =<< receiveChanTimeout 1000000 rp
126− kill agent "finished"
139+ kill agent "finished" >> awaitExit agent
127140
128141testAgentEventHandling :: TestResult Bool -> Process ()
129142testAgentEventHandling result = do
130143 let initState = [] :: [MxEvent]
144+
145+ (rc, rs) <- newChan
131146 agentPid <- mxAgent (MxAgentId "lifecycle-listener-agent") initState [
132147 (mxSink $ \ev -> do
133148 st <- mxGetLocal
@@ -136,7 +151,7 @@ testAgentEventHandling result = do
136151 (MxSpawned _) -> mxSetLocal (ev:st)
137152 (MxProcessDied _ _) -> mxSetLocal (ev:st)
138153 _ -> return ()
139− act >> mxReady),
154+ act >> (liftMX $ sendChan rc ()) >> mxReady),
140155 (mxSink $ \(ev, sp :: SendPort Bool) -> do
141156 st <- mxGetLocal
142157 let found =
@@ -156,16 +171,26 @@ testAgentEventHandling result = do
156171 mxReady)
157172 ]
158173
174+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
175+ faff 2000000 rs
176+
159177 _ <- monitor agentPid
160178 (sp, rp) <- newChan
161− pid <- spawnLocal $ sendChan sp ()
162− () <- receiveChan rp
179+
180+ pid <- spawnLocal $ expect >>= sendChan sp
163181
164182 -- By waiting for a monitor notification, we have a
165− -- higher probably that the agent has seen
183+ -- higher probably that the agent has seen the spawn and died events
166184 monitor pid
185+
186+ send pid ()
187+ () <- receiveChan rp
188+
167189 receiveWait [ match (\(ProcessMonitorNotification _ _ _) -> return ()) ]
168190
191+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
192+ faff 2000000 rs
193+
169194 (replyTo, reply) <- newChan :: Process (SendPort Bool, ReceivePort Bool)
170195 mxNotify (MxSpawned pid, replyTo)
171196 mxNotify (MxProcessDied pid DiedNormal, replyTo)
@@ -174,32 +199,159 @@ testAgentEventHandling result = do
174199 seenDead <- receiveChan reply
175200
176201 stash result $ seenAlive && seenDead
202+ kill agentPid "test-complete" >> awaitExit agentPid
203+ where
204+ faff delay port = do
205+ res <- receiveChanTimeout delay port
206+ unless (isNothing res) $ do
207+ pause delay
208+ faff delay port
209+
210+testMxRegEvents :: TestResult () -> Process ()
211+testMxRegEvents result = do
212+ {- This test only deals with the local case, to ensure that we are being
213+ notified in the expected order - the remote cases related to the
214+ behaviour of the node controller are contained in the CH test suite. -}
215+ ensure (stash result ()) $ do
216+ let label = "testMxRegEvents"
217+ let agentLabel = "mxRegEvents-agent"
218+ let delay = 1000000
219+ (regChan, regSink) <- newChan
220+ (unRegChan, unRegSink) <- newChan
221+ agent <- mxAgent (MxAgentId agentLabel) () [
222+ mxSink $ \ev -> do
223+ case ev of
224+ MxRegistered pid label'
225+ | label' == label -> liftMX $ sendChan regChan (label', pid)
226+ MxUnRegistered pid label'
227+ | label' == label -> liftMX $ sendChan unRegChan (label', pid)
228+ _ -> return ()
229+ mxReady
230+ ]
231+
232+ p1 <- spawnLocal expect
233+ p2 <- spawnLocal expect
234+
235+ register label p1
236+ reg1 <- receiveChanTimeout delay regSink
237+ reg1 `shouldBe` equalTo (Just (label, p1))
238+
239+ unregister label
240+ unreg1 <- receiveChanTimeout delay unRegSink
241+ unreg1 `shouldBe` equalTo (Just (label, p1))
242+
243+ register label p2
244+ reg2 <- receiveChanTimeout delay regSink
245+ reg2 `shouldBe` equalTo (Just (label, p2))
246+
247+ reregister label p1
248+ unreg2 <- receiveChanTimeout delay unRegSink
249+ unreg2 `shouldBe` equalTo (Just (label, p2))
250+
251+ reg3 <- receiveChanTimeout delay regSink
252+ reg3 `shouldBe` equalTo (Just (label, p1))
253+
254+ mapM_ (flip kill $ "test-complete") [agent, p1, p2]
255+ awaitExit agent
256+
257+testMxRegMon :: LocalNode -> TestResult () -> Process ()
258+testMxRegMon remoteNode result = do
259+ ensure (stash result ()) $ do
260+ -- ensure that when a registered process dies, we get a notification that
261+ -- it has been unregistered as well as seeing the name get removed
262+ let label1 = "aaaaa"
263+ let label2 = "bbbbb"
264+ let isValid l = l == label1 || l == label2
265+ let agentLabel = "mxRegMon-agent"
266+ let delay = 1000000
267+ (regChan, regSink) <- newChan
268+ (unRegChan, unRegSink) <- newChan
269+ agent <- mxAgent (MxAgentId agentLabel) () [
270+ mxSink $ \ev -> do
271+ case ev of
272+ MxRegistered pid label
273+ | isValid label -> liftMX $ sendChan regChan (label, pid)
274+ MxUnRegistered pid label
275+ | isValid label -> liftMX $ sendChan unRegChan (label, pid)
276+ _ -> return ()
277+ mxReady
278+ ]
279+
280+ (sp, rp) <- newChan
281+ liftIO $ forkProcess remoteNode $ do
282+ getSelfPid >>= sendChan sp
283+ expect :: Process ()
284+
285+ p1 <- receiveChan rp
286+
287+ register label1 p1
288+ reg1 <- receiveChanTimeout delay regSink
289+ reg1 `shouldBe` equalTo (Just (label1, p1))
290+
291+ register label2 p1
292+ reg2 <- receiveChanTimeout delay regSink
293+ reg2 `shouldBe` equalTo (Just (label2, p1))
294+
295+ n1 <- whereis label1
296+ n1 `shouldBe` equalTo (Just p1)
297+
298+ n2 <- whereis label2
299+ n2 `shouldBe` equalTo (Just p1)
300+
301+ kill p1 "goodbye"
302+
303+ unreg1 <- receiveChanTimeout delay unRegSink
304+ unreg2 <- receiveChanTimeout delay unRegSink
305+
306+ let evts = [unreg1, unreg2]
307+ -- we can't rely on the order of the values in the node controller's
308+ -- map (it's either racy to do so, or no such guarantee exists for Data.Map),
309+ -- so we simply verify that we received the un-registration events we expect
310+ evts `shouldContain` (Just (label1, p1))
311+ evts `shouldContain` (Just (label2, p1))
312+
313+ kill agent "test-complete" >> awaitExit agent
314+
315+ensure :: Process () -> Process () -> Process ()
316+ensure = flip finally
177317
178318tests :: TestTransport -> IO [Test]
179319tests TestTransport{..} = do
180320 node1 <- newLocalNode testTransport initRemoteTable
321+ node2 <- newLocalNode testTransport initRemoteTable
181322 return [
182− testGroup "Mx Agents" [
183− testCase "Event Handling"
184− (delayedAssertion
185− "expected True, but events where not as expected"
186− node1 True testAgentEventHandling)
187− , testCase "Inter-Agent Broadcast"
188− (delayedAssertion
189− "expected (), but no broadcast was received"
190− node1 () testAgentBroadcast)
191− , testCase "Agent Mailbox Handling"
192− (delayedAssertion
193− "expected (Just ()), but no regular (mailbox) input was handled"
194− node1 (Just ()) testAgentMailboxHandling)
195− , testCase "Agent Dual Input Handling"
196− (delayedAssertion
197− "expected sum = 15, but the result was Nothing"
198− node1 (Just 15 :: Maybe Int) testAgentDualInput)
199− , testCase "Agent Input Prioritisation"
200− (delayedAssertion
201− "expected [first, second, third, fourth, fifth], but result diverged"
202− node1 (sort ["first", "second",
203− "third", "fourth",
204− "fifth"]) testAgentPrioritisation)
205− ]]
323+ testGroup "Mx Agents" [
324+ testCase "Event Handling"
325+ (delayedAssertion
326+ "expected True, but events where not as expected"
327+ node1 True testAgentEventHandling)
328+ , testCase "Inter-Agent Broadcast"
329+ (delayedAssertion
330+ "expected (), but no broadcast was received"
331+ node1 () testAgentBroadcast)
332+ , testCase "Agent Mailbox Handling"
333+ (delayedAssertion
334+ "expected (Just ()), but no regular (mailbox) input was handled"
335+ node1 (Just ()) testAgentMailboxHandling)
336+ , testCase "Agent Dual Input Handling"
337+ (delayedAssertion
338+ "expected sum = 15, but the result was Nothing"
339+ node1 (Just 15 :: Maybe Int) testAgentDualInput)
340+ , testCase "Agent Input Prioritisation"
341+ (delayedAssertion
342+ "expected [first, second, third, fourth, fifth], but result diverged"
343+ node1 (sort ["first", "second",
344+ "third", "fourth",
345+ "fifth"]) testAgentPrioritisation)
346+ ]
347+ , testGroup "Mx Events" [
348+ testCase "Name Registration Events"
349+ (delayedAssertion
350+ "expected registration events to map to the correct ProcessId"
351+ node1 () testMxRegEvents)
352+ , testCase "Post Death Name UnRegistration Events"
353+ (delayedAssertion
354+ "expected process deaths to result in unregistration events"
355+ node1 () (testMxRegMon node2))
356+ ]
357+ ]
src/Control/Distributed/Process/Internal/Primitives.hs+1
@@ -76,6 +76,7 @@ module Control.Distributed.Process.Internal.Primitives
7676 , unlink
7777 , monitor
7878 , unmonitor
79+ , unmonitorAsync
7980 , withMonitor
8081 , withMonitor_
8182 -- * Logging
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-8.2.2.yamlnew file+20
@@ -0,0 +1,20 @@
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+
18+flags:
19+ distributed-process-tests:
20+ 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.yaml+3−3
@@ -1,4 +1,4 @@
1−resolver: nightly-2018-11-10
1+resolver: nightly
22
33packages:
44- '.'
@@ -9,11 +9,11 @@ packages:
99 extra-dep: true
1010- location:
1111 git: https://github.com/haskell-distributed/network-transport-tcp.git
12− commit: d87d6f55697a94a1fbf211ff9c1bb769a1e129cd
12+ commit: d58250e2388b86a1865ac4139373cbdc106e72e1
1313 extra-dep: true
1414- location:
1515 git: https://github.com/haskell-distributed/network-transport-inmemory.git
16− commit: b7a10ffc07a77f4fe6affbf8abe535b11933a01a
16+ commit: 0ce97924f15a8c1570b2355151834305c9bd2a28
1717 extra-dep: true
1818
1919extra-deps:
stack.yaml+1−1
@@ -1,4 +1,4 @@
1−resolver: nightly-2017-08-20
1+resolver: lts-12.18 # Use GHC 8.4.4
22
33packages:
44- '.'