Skip to content

Commit 003e522

Browse files
authored
Publish MxUnregistered when a registered name dies
2 parents bbb3a2e + a027f75 commit 003e522

File tree

12 files changed

+364
-63
lines changed

12 files changed

+364
-63
lines changed

.travis.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1616
cache:
@@ -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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import Control.Distributed.Process.Internal.Types
3737
, createUnencodedMessage
3838
)
3939
import 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)
4043
import Control.Distributed.Process.Serializable (Serializable)
4144

4245
import 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+
14791544
testUnsafeSend :: TestTransport -> Assertion
14801545
testUnsafeSend 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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
7879
import Control.Distributed.Process.Serializable()
7980

8081
import Control.Exception (AsyncException(ThreadKilled), SomeException)
81-
import Control.Monad (forever)
82+
import Control.Monad (forever, void)
8283
import Control.Monad.STM (atomically)
8384
import Control.Rematch hiding (match)
84-
import Control.Rematch.Run
85+
import Control.Rematch.Run
8586
import Data.Binary
8687
import Data.Typeable (Typeable)
8788

@@ -107,10 +108,18 @@ data TestProcessControl = Stop | Go | Report ProcessId
107108

108109
instance 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.
111116
noop :: Process ()
112117
noop = return ()
113118

119+
pause :: Int -> Process ()
120+
pause delay =
121+
void $ receiveTimeout delay [ match (\Private -> return ()) ]
122+
114123
synchronisedAssertion :: Eq a
115124
=> String
116125
-> LocalNode
@@ -229,4 +238,3 @@ tryForkProcess :: LocalNode -> Process () -> IO ProcessId
229238
tryForkProcess node p = do
230239
tid <- liftIO myThreadId
231240
forkProcess node $ catch p (\e -> liftIO $ throwTo tid (e::SomeException))
232-

0 commit comments

Comments
 (0)