Skip to content

Commit 729482c

Browse files
Merge pull request #607 from emilazy/push-oztlzsuvtxwz
Use `withSystemTempDirectory` consistently for Unix socket tests
2 parents 86f33ca + 16ec523 commit 729482c

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

tests/Network/SocketSpec.hs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ spec = do
158158
when isUnixDomainSocketAvailable $ do
159159
context "unix sockets" $ do
160160
it "basic unix sockets end-to-end" $ do
161-
let client sock = send sock testMsg
162-
server (sock, addr) = do
163-
recv sock 1024 `shouldReturn` testMsg
164-
addr `shouldBe` (SockAddrUnix "")
165-
test . setClientAction client $ unixWithUnlink unixAddr server
161+
withSystemTempDirectory "haskell-network" $ \path -> do
162+
let unixAddr = path ++ "/socket-file"
163+
let client sock = send sock testMsg
164+
server (sock, addr) = do
165+
recv sock 1024 `shouldReturn` testMsg
166+
addr `shouldBe` (SockAddrUnix "")
167+
test . setClientAction client $ unixWithUnlink unixAddr server
166168
#endif
167169

168170
#ifdef linux_HOST_OS
@@ -208,19 +210,21 @@ spec = do
208210
--
209211
describe "getPeerCredential" $ do
210212
it "can return something" $ do
211-
-- It would be useful to check that we did not get garbage
212-
-- back, but rather the actual uid of the test program. For
213-
-- that we'd need System.Posix.User, but that is not available
214-
-- under Windows. For now, accept the risk that we did not get
215-
-- the right answer.
216-
--
217-
let server (sock, _) = do
218-
(_, uid, _) <- getPeerCredential sock
219-
uid `shouldNotBe` Nothing
220-
client sock = do
221-
(_, uid, _) <- getPeerCredential sock
222-
uid `shouldNotBe` Nothing
223-
test . setClientAction client $ unixWithUnlink unixAddr server
213+
withSystemTempDirectory "haskell-network" $ \path -> do
214+
let unixAddr = path ++ "/socket-file"
215+
-- It would be useful to check that we did not get garbage
216+
-- back, but rather the actual uid of the test program. For
217+
-- that we'd need System.Posix.User, but that is not available
218+
-- under Windows. For now, accept the risk that we did not get
219+
-- the right answer.
220+
--
221+
let server (sock, _) = do
222+
(_, uid, _) <- getPeerCredential sock
223+
uid `shouldNotBe` Nothing
224+
client sock = do
225+
(_, uid, _) <- getPeerCredential sock
226+
uid `shouldNotBe` Nothing
227+
test . setClientAction client $ unixWithUnlink unixAddr server
224228
{- The below test fails on many *BSD systems, because the getsockopt()
225229
call that underlies getpeereid() does not have the same meaning for
226230
all address families, but the C-library was not checking that the

tests/Network/Test/Common.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Network.Test.Common
2121
-- * Common constants
2222
, serverAddr
2323
, serverAddr6
24-
, unixAddr
2524
, testMsg
2625
, lazyTestMsg
2726
) where
@@ -53,9 +52,6 @@ testMsg = "This is a test message."
5352
lazyTestMsg :: L.ByteString
5453
lazyTestMsg = L.fromStrict "This is a test message."
5554

56-
unixAddr :: String
57-
unixAddr = "/tmp/network-test"
58-
5955
-- | Establish a connection between client and server and then run
6056
-- 'clientAct' and 'serverAct', in different threads. Both actions
6157
-- get passed a connected 'Socket', used for communicating between

0 commit comments

Comments
 (0)