Skip to content

Commit 1a0bfc0

Browse files
committed
Redo unique ports
1 parent 997e7d7 commit 1a0bfc0

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

test/Fencer/Server/Test.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,17 @@ withServer =
232232
withResource createServer destroyServer
233233

234234
-- | Get a unique port number that is not used by other tests. Needed since
235-
-- all tests run in parallel.
235+
-- all tests run in parallel and we can't run Fencer on the same port in
236+
-- parallel.
236237
getUniquePort :: IO Port
237-
getUniquePort = atomicModifyIORef' next (\port -> (succ port, port))
238-
where
239-
next :: IORef Port
240-
next = unsafePerformIO (newIORef defaultGRPCPort)
241-
{-# NOINLINE next #-}
238+
getUniquePort = atomicModifyIORef' nextUniquePortVar (\port -> (succ port, port))
242239

243-
{-# NOINLINE getUniquePort #-}
240+
-- | Top-level global variable used by 'getUniquePort'. For the explanation
241+
-- of @NOINLINE@, see
242+
-- <http://neilmitchell.blogspot.com/2014/10/hlint-now-spots-bad-unsafeperformio.html>.
243+
nextUniquePortVar :: IORef Port
244+
nextUniquePortVar = unsafePerformIO (newIORef defaultGRPCPort)
245+
{-# NOINLINE nextUniquePortVar #-}
244246

245247
----------------------------------------------------------------------------
246248
-- gRPC client

0 commit comments

Comments
 (0)