@@ -23,11 +23,11 @@ import Control.Distributed.Process.Management
23 , mxBroadcast
23 , mxBroadcast
26−import Control.Monad (void)
26+import Control.Monad (void, unless)
27import Control.Rematch (equalTo)
27import Control.Rematch (equalTo)
28import Data.Binary
28import Data.Binary
29import Data.List (find, sort)
29import Data.List (find, sort)
30−import Data.Maybe (isJust)
30+import Data.Maybe (isJust, isNothing)
31import Data.Typeable
31import Data.Typeable
32import GHC.Generics
32import GHC.Generics
33#if ! MIN_VERSION_base(4,6,0)
33#if ! MIN_VERSION_base(4,6,0)
@@ -141,6 +141,8 @@ testAgentMailboxHandling result = do
141testAgentEventHandling :: TestResult Bool -> Process ()
141testAgentEventHandling :: TestResult Bool -> Process ()
142testAgentEventHandling result = do
142testAgentEventHandling result = do
143 let initState = [] :: [MxEvent]
143 let initState = [] :: [MxEvent]
144 agentPid <- mxAgent (MxAgentId "lifecycle-listener-agent") initState [
146 agentPid <- mxAgent (MxAgentId "lifecycle-listener-agent") initState [
145 (mxSink $ \ev -> do
147 (mxSink $ \ev -> do
146 st <- mxGetLocal
148 st <- mxGetLocal
@@ -149,7 +151,7 @@ testAgentEventHandling result = do
149 (MxSpawned _) -> mxSetLocal (ev:st)
151 (MxSpawned _) -> mxSetLocal (ev:st)
150 (MxProcessDied _ _) -> mxSetLocal (ev:st)
152 (MxProcessDied _ _) -> mxSetLocal (ev:st)
151 _ -> return ()
153 _ -> return ()
152− act >> mxReady),
154+ act >> (liftMX $ sendChan rc ()) >> mxReady),
153 (mxSink $ \(ev, sp :: SendPort Bool) -> do
155 (mxSink $ \(ev, sp :: SendPort Bool) -> do
154 st <- mxGetLocal
156 st <- mxGetLocal
155 let found =
157 let found =
@@ -169,16 +171,26 @@ testAgentEventHandling result = do
174+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
172 _ <- monitor agentPid
177 _ <- monitor agentPid
173 (sp, rp) <- newChan
178 (sp, rp) <- newChan
174− pid <- spawnLocal $ sendChan sp ()
180+ pid <- spawnLocal $ expect >>= sendChan sp
175− () <- receiveChan rp
177 -- By waiting for a monitor notification, we have a
182 -- By waiting for a monitor notification, we have a
178− -- higher probably that the agent has seen
183+ -- higher probably that the agent has seen the spawn and died events
179 monitor pid
184 monitor pid
187+ () <- receiveChan rp
180 receiveWait [ match (\(ProcessMonitorNotification _ _ _) -> return ()) ]
189 receiveWait [ match (\(ProcessMonitorNotification _ _ _) -> return ()) ]
191+ -- TODO: yes, this is racy, but we're at the mercy of the scheduler here...
182 (replyTo, reply) <- newChan :: Process (SendPort Bool, ReceivePort Bool)
194 (replyTo, reply) <- newChan :: Process (SendPort Bool, ReceivePort Bool)
183 mxNotify (MxSpawned pid, replyTo)
195 mxNotify (MxSpawned pid, replyTo)
184 mxNotify (MxProcessDied pid DiedNormal, replyTo)
196 mxNotify (MxProcessDied pid DiedNormal, replyTo)
@@ -188,6 +200,12 @@ testAgentEventHandling result = do
189 stash result $ seenAlive && seenDead
201 stash result $ seenAlive && seenDead
190 kill agentPid "test-complete" >> awaitExit agentPid
202 kill agentPid "test-complete" >> awaitExit agentPid
204+ faff delay port = do
205+ res <- receiveChanTimeout delay port
206+ unless (isNothing res) $ do
192testMxRegEvents :: TestResult () -> Process ()
210testMxRegEvents :: TestResult () -> Process ()
193testMxRegEvents result = do
211testMxRegEvents result = do