1{-# LANGUAGE DeriveDataTypeable #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3module Control.Distributed.Process.Tests.Stats (tests) where
5import Control.Distributed.Process.Tests.Internal.Utils
6import Network.Transport.Test (TestTransport(..))
8import Control.Concurrent.MVar
14import Control.Distributed.Process
15import Control.Distributed.Process.Node
17import Data.Typeable ()
19#if ! MIN_VERSION_base(4,6,0)
20import Prelude hiding (catch)
27import Test.HUnit (Assertion)
28import Test.Framework.Providers.HUnit (testCase)
30testLocalDeadProcessInfo :: TestResult (Maybe ProcessInfo) -> Process ()
31testLocalDeadProcessInfo result = do
32 pid <- spawnLocal $ do "finish" <- expect; return ()
36 matchIf (\(ProcessMonitorNotification ref' pid' r) ->
37 ref' == mref && pid' == pid && r == DiedNormal)
40 getProcessInfo pid >>= stash result
42testLocalLiveProcessInfo :: TestResult Bool -> Process ()
43testLocalLiveProcessInfo result = do
46 register "foobar" self
48 mon <- liftIO $ newEmptyMVar
49 -- TODO: we can't get the mailbox's length
50 -- mapM (send self) ["hello", "there", "mr", "process"]
51 pid <- spawnLocal $ do
58 monRef <- liftIO $ takeMVar mon
60 mpInfo <- getProcessInfo self
62 Nothing -> stash result False
63 Just p -> verifyPInfo p pid monRef node
64 where verifyPInfo :: ProcessInfo
69 verifyPInfo pInfo pid mref node =
70 stash result $ infoNode pInfo == node &&
71 infoLinks pInfo == [pid] &&
72 infoMonitors pInfo == [(pid, mref)] &&
73-- infoMessageQueueLength pInfo == Just 4 &&
74 infoRegisteredNames pInfo == ["foobar"]
76testRemoteLiveProcessInfo :: TestTransport -> LocalNode -> Assertion
77testRemoteLiveProcessInfo TestTransport{..} node1 = do
78 serverAddr <- liftIO $ newEmptyMVar :: IO (MVar ProcessId)
79 liftIO $ launchRemote serverAddr
80 serverPid <- liftIO $ takeMVar serverAddr
81 withActiveRemote node1 $ \result -> do
84 -- our send op shouldn't overtake link or monitor requests AFAICT
85 -- so a little table tennis should get us synchronised properly
86 send serverPid (self, "ping")
88 pInfo <- getProcessInfo serverPid
89 stash result $ pInfo /= Nothing
91 launchRemote :: MVar ProcessId -> IO ()
92 launchRemote locMV = do
93 node2 <- liftIO $ newLocalNode testTransport initRemoteTable
94 _ <- liftIO $ forkProcess node2 $ do
96 liftIO $ putMVar locMV self
98 match (\(pid, "ping") -> send pid "pong")
104 withActiveRemote :: LocalNode
105 -> ((TestResult Bool -> Process ()) -> Assertion)
106 withActiveRemote n = do
107 a <- delayedAssertion "getProcessInfo remotePid failed" n True
110tests :: TestTransport -> IO [Test]
111tests testtrans@TestTransport{..} = do
112 node1 <- newLocalNode testTransport initRemoteTable
114 testGroup "Process Info" [
115 testCase "testLocalDeadProcessInfo"
117 "expected dead process-info to be ProcessInfoNone"
118 node1 (Nothing) testLocalDeadProcessInfo)
119 , testCase "testLocalLiveProcessInfo"
121 "expected process-info to be correctly populated"
122 node1 True testLocalLiveProcessInfo)
123 , testCase "testRemoveLiveProcessInfo"
124 (testRemoteLiveProcessInfo testtrans node1)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list