@@ -22,9 +22,12 @@ import Control.Distributed.Process.Node
22 , closeLocalNode
22 , closeLocalNode
23 , LocalNode)
23 , LocalNode)
24import Network.Transport.TCP
24import Network.Transport.TCP
25+import qualified Network.Transport as NT
25#if ! MIN_VERSION_base(4,6,0)
27#if ! MIN_VERSION_base(4,6,0)
26import Prelude hiding (catch, log)
28import Prelude hiding (catch, log)
28import Test.Framework
31import Test.Framework
30 , defaultMain
33 , defaultMain
@@ -33,39 +36,7 @@ import Test.Framework
33import Test.HUnit (Assertion)
36import Test.HUnit (Assertion)
34import Test.HUnit.Base (assertBool)
37import Test.HUnit.Base (assertBool)
35import Test.Framework.Providers.HUnit (testCase)
38import Test.Framework.Providers.HUnit (testCase)
37−-- these utilities have been cribbed from distributed-process-platform
38−-- we should really find a way to share them...
40−-- | A mutable cell containing a test result.
41−type TestResult a = MVar a
43−delayedAssertion :: (Eq a)
47− -> (TestResult a -> Process ())
50−delayedAssertion note localNode expected testProc lock = do
51− result <- newEmptyMVar
52− _ <- forkProcess localNode $ do
54− finally (testProc result)
56− assertComplete note result expected
57− where acquire lock' = liftIO $ takeMVar lock'
58− release lock' = liftIO $ putMVar lock' ()
60−assertComplete :: (Eq a) => String -> MVar a -> a -> IO ()
61−assertComplete msg mv a = do
63− assertBool msg (a == b)
65−stash :: TestResult a -> a -> Process ()
66−stash mvar x = liftIO $ putMVar mvar x
70testSpawnTracing :: TestResult Bool -> Process ()
41testSpawnTracing :: TestResult Bool -> Process ()
71testSpawnTracing result = do
42testSpawnTracing result = do
@@ -328,50 +299,43 @@ tests node1 = do
329 testGroup "Tracing" [
300 testGroup "Tracing" [
330 testCase "Spawn Tracing"
301 testCase "Spawn Tracing"
331− (delayedAssertion
302+ (synchronisedAssertion
332 "expected dead process-info to be ProcessInfoNone"
303 "expected dead process-info to be ProcessInfoNone"
333 node1 True testSpawnTracing lock)
304 node1 True testSpawnTracing lock)
334 , testCase "Recv Tracing (Explicit Pid)"
305 , testCase "Recv Tracing (Explicit Pid)"
335− (delayedAssertion
306+ (synchronisedAssertion
336 "expected a recv trace for the supplied pid"
307 "expected a recv trace for the supplied pid"
337 node1 True testTraceRecvExplicitPid lock)
308 node1 True testTraceRecvExplicitPid lock)
338 , testCase "Recv Tracing (Named Pid)"
309 , testCase "Recv Tracing (Named Pid)"
339− (delayedAssertion
310+ (synchronisedAssertion
340 "expected a recv trace for the process registered as 'foobar'"
311 "expected a recv trace for the process registered as 'foobar'"
341 node1 True testTraceRecvNamedPid lock)
312 node1 True testTraceRecvNamedPid lock)
342 , testCase "Trace Send(er)"
313 , testCase "Trace Send(er)"
343− (delayedAssertion
314+ (synchronisedAssertion
344 "expected a 'send' trace with the requisite fields set"
315 "expected a 'send' trace with the requisite fields set"
345 node1 True testTraceSending lock)
316 node1 True testTraceSending lock)
346 , testCase "Trace Registration"
317 , testCase "Trace Registration"
347− (delayedAssertion
318+ (synchronisedAssertion
348 "expected a 'registered' trace"
319 "expected a 'registered' trace"
349 node1 True testTraceRegistration lock)
320 node1 True testTraceRegistration lock)
350 , testCase "Trace Unregistration"
321 , testCase "Trace Unregistration"
351− (delayedAssertion
322+ (synchronisedAssertion
352 "expected an 'unregistered' trace"
323 "expected an 'unregistered' trace"
353 node1 True testTraceUnRegistration lock)
324 node1 True testTraceUnRegistration lock)
354 , testCase "Trace Layering"
325 , testCase "Trace Layering"
355− (delayedAssertion
326+ (synchronisedAssertion
356− "expected blah"
327+ "expected blah"
357− node1 () testTraceLayering lock)
328+ node1 () testTraceLayering lock)
358 , testCase "Remote Trace Relay"
329 , testCase "Remote Trace Relay"
359− (delayedAssertion
330+ (synchronisedAssertion
360− "expected blah"
331+ "expected blah"
361− node1 True testRemoteTraceRelay lock)
332+ node1 True testRemoteTraceRelay lock)
364−mkNode :: String -> IO LocalNode
335+timerTests :: NT.Transport -> IO [Test]
365−mkNode port = do
336+timerTests transport = do
366− Right (transport1, _) <- createTransportExposeInternals
337+ mkNode "8080" >>= tests >>= return
367− "127.0.0.1" port defaultTCPParameters
368− newLocalNode transport1 initRemoteTable
370main :: IO ()
339main :: IO ()
371−main = do
340+main = testMain $ timerTests
372− node1 <- mkNode "8081"
373− testData <- tests node1
374− defaultMain testData
375− closeLocalNode node1