@@ -9,6 +9,7 @@ import Network.Transport.Test (TestTransport(..))
9
9
import Data.Binary (Binary (.. ))
10
10
import Data.Typeable (Typeable )
11
11
import Data.Foldable (forM_ )
12
+ import Data.Function (fix )
12
13
import Data.IORef
13
14
( readIORef
14
15
, writeIORef
@@ -410,16 +411,14 @@ testTimeout0 :: TestTransport -> Assertion
410
411
testTimeout0 TestTransport {.. } = do
411
412
serverAddr <- newEmptyMVar
412
413
clientDone <- newEmptyMVar
413
- messagesSent <- newEmptyMVar
414
414
415
415
forkIO $ do
416
416
localNode <- newLocalNode testTransport initRemoteTable
417
417
addr <- forkProcess localNode $ do
418
- liftIO $ readMVar messagesSent >> threadDelay 1000000
419
418
-- Variation on the venerable ping server which uses a zero timeout
420
- -- Since we wait for all messages to be sent before doing this receive,
421
- -- we should nevertheless find the right message immediately
422
- Just partner <- receiveTimeout 0 [match ( \ ( Pong partner) -> return partner)]
419
+ partner <- fix $ \ loop ->
420
+ receiveTimeout 0 [match ( \ ( Pong partner) -> return partner)]
421
+ >>= maybe (liftIO (threadDelay 100000 ) >> loop) return
423
422
self <- getSelfPid
424
423
send partner (Ping self)
425
424
putMVar serverAddr addr
@@ -433,7 +432,6 @@ testTimeout0 TestTransport{..} = do
433
432
-- is not interested in, and then a single message that it wants
434
433
replicateM_ 10000 $ send server " Irrelevant message"
435
434
send server (Pong pid)
436
- liftIO $ putMVar messagesSent ()
437
435
Ping _ <- expect
438
436
liftIO $ putMVar clientDone ()
439
437
0 commit comments