@@ -0,0 +1,88 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+module Main where
3+
4+import Prelude hiding (catch)
5+import qualified Network.Transport as NT
6+import Test.Framework
7+ ( Test
8+ , defaultMain
9+ , testGroup
10+ )
11+import Network.Transport.TCP
12+import Control.Distributed.Process
13+import Control.Distributed.Process.Node
14+ ( forkProcess
15+ , newLocalNode
16+ , initRemoteTable
17+ , closeLocalNode
18+ , LocalNode)
19+import Control.Concurrent.MVar
20+ ( MVar
21+ , newEmptyMVar
22+ , putMVar
23+ , takeMVar
24+ )
25+import Test.HUnit (Assertion)
26+import Test.HUnit.Base (assertBool)
27+import Test.Framework.Providers.HUnit (testCase)
28+
29+-- these utilities have been cribbed from distributed-process-platform
30+-- we should really find a way to share them...
31+
32+-- | A mutable cell containing a test result.
33+type TestResult a = MVar a
34+
35+delayedAssertion :: (Eq a) => String -> LocalNode -> a ->
36+ (TestResult a -> Process ()) -> Assertion
37+delayedAssertion note localNode expected testProc = do
38+ result <- newEmptyMVar
39+ _ <- forkProcess localNode $ testProc result
40+ assertComplete note result expected
41+
42+assertComplete :: (Eq a) => String -> MVar a -> a -> IO ()
43+assertComplete msg mv a = do
44+ b <- takeMVar mv
45+ assertBool msg (a == b)
46+
47+stash :: TestResult a -> a -> Process ()
48+stash mvar x = liftIO $ putMVar mvar x
49+
50+------
51+
52+testLocalDeadProcessInfo :: TestResult (Maybe ProcessInfo) -> Process ()
53+testLocalDeadProcessInfo result = do
54+ pid <- spawnLocal $ do "finish" <- expect; return ()
55+ mref <- monitor pid
56+ send pid "finish"
57+ _ <- receiveWait [
58+ matchIf (\(ProcessMonitorNotification ref' pid' r) ->
59+ ref' == mref && pid' == pid && r == DiedNormal)
60+ (\p -> return p)
61+ ]
62+ say "waiting for process info...."
63+ getProcessInfo pid >>= stash result
64+
65+tests :: LocalNode -> IO [Test]
66+tests node1 = do
67+ return [
68+ testGroup "Process Info" [
69+ testCase "testLocalDeadProcessInfo"
70+ (delayedAssertion
71+ "expected dead process-info to be ProcessInfoNone"
72+ node1 (Nothing) testLocalDeadProcessInfo)
73+ ] ]
74+
75+mkNode :: String -> IO LocalNode
76+mkNode port = do
77+ Right (transport1, _) <- createTransportExposeInternals
78+ "127.0.0.1" port defaultTCPParameters
79+ newLocalNode transport1 initRemoteTable
80+
81+main :: IO ()
82+main = do
83+ node1 <- mkNode "8081"
84+ testData <- tests node1
85+ defaultMain testData
86+ closeLocalNode node1
87+ return ()
88+