diff --git a/tests/Network/SocketSpec.hs b/tests/Network/SocketSpec.hs index b4491617..d056c9de 100644 --- a/tests/Network/SocketSpec.hs +++ b/tests/Network/SocketSpec.hs @@ -158,11 +158,13 @@ spec = do when isUnixDomainSocketAvailable $ do context "unix sockets" $ do it "basic unix sockets end-to-end" $ do - let client sock = send sock testMsg - server (sock, addr) = do - recv sock 1024 `shouldReturn` testMsg - addr `shouldBe` (SockAddrUnix "") - test . setClientAction client $ unixWithUnlink unixAddr server + withSystemTempDirectory "haskell-network" $ \path -> do + let unixAddr = path ++ "/socket-file" + let client sock = send sock testMsg + server (sock, addr) = do + recv sock 1024 `shouldReturn` testMsg + addr `shouldBe` (SockAddrUnix "") + test . setClientAction client $ unixWithUnlink unixAddr server #endif #ifdef linux_HOST_OS @@ -208,19 +210,21 @@ spec = do -- describe "getPeerCredential" $ do it "can return something" $ do - -- It would be useful to check that we did not get garbage - -- back, but rather the actual uid of the test program. For - -- that we'd need System.Posix.User, but that is not available - -- under Windows. For now, accept the risk that we did not get - -- the right answer. - -- - let server (sock, _) = do - (_, uid, _) <- getPeerCredential sock - uid `shouldNotBe` Nothing - client sock = do - (_, uid, _) <- getPeerCredential sock - uid `shouldNotBe` Nothing - test . setClientAction client $ unixWithUnlink unixAddr server + withSystemTempDirectory "haskell-network" $ \path -> do + let unixAddr = path ++ "/socket-file" + -- It would be useful to check that we did not get garbage + -- back, but rather the actual uid of the test program. For + -- that we'd need System.Posix.User, but that is not available + -- under Windows. For now, accept the risk that we did not get + -- the right answer. + -- + let server (sock, _) = do + (_, uid, _) <- getPeerCredential sock + uid `shouldNotBe` Nothing + client sock = do + (_, uid, _) <- getPeerCredential sock + uid `shouldNotBe` Nothing + test . setClientAction client $ unixWithUnlink unixAddr server {- The below test fails on many *BSD systems, because the getsockopt() call that underlies getpeereid() does not have the same meaning for all address families, but the C-library was not checking that the diff --git a/tests/Network/Test/Common.hs b/tests/Network/Test/Common.hs index 2230a2cd..fd8ee9c1 100644 --- a/tests/Network/Test/Common.hs +++ b/tests/Network/Test/Common.hs @@ -21,7 +21,6 @@ module Network.Test.Common -- * Common constants , serverAddr , serverAddr6 - , unixAddr , testMsg , lazyTestMsg ) where @@ -53,9 +52,6 @@ testMsg = "This is a test message." lazyTestMsg :: L.ByteString lazyTestMsg = L.fromStrict "This is a test message." -unixAddr :: String -unixAddr = "/tmp/network-test" - -- | Establish a connection between client and server and then run -- 'clientAct' and 'serverAct', in different threads. Both actions -- get passed a connected 'Socket', used for communicating between