Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions tests/Network/SocketSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@
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
Expand Down Expand Up @@ -208,19 +210,21 @@
--
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
Expand Down Expand Up @@ -423,7 +427,7 @@
cmsgidGen = biasedGen (\g -> CmsgId <$> g <*> g) cmsgidPatterns arbitrary

genFds :: Gen [Fd]
genFds = listOf (Fd <$> arbitrary)

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

Defined but not used: ‘genFds’

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

Defined but not used: ‘genFds’

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.6)

Defined but not used: ‘genFds’

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.6)

Defined but not used: ‘genFds’

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.8)

Defined but not used: ‘genFds’

Check warning on line 430 in tests/Network/SocketSpec.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.8)

Defined but not used: ‘genFds’

-- pruned lists of pattern synonym values for each type to generate values from

Expand Down
4 changes: 0 additions & 4 deletions tests/Network/Test/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
-- * Common constants
, serverAddr
, serverAddr6
, unixAddr
, testMsg
, lazyTestMsg
) where
Expand All @@ -39,7 +38,7 @@
import Network.Socket
import System.Directory
import System.Timeout (timeout)
import Test.Hspec

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

The import of ‘Test.Hspec’ is redundant

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.4)

The import of ‘Test.Hspec’ is redundant

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.6)

The import of ‘Test.Hspec’ is redundant

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.6)

The import of ‘Test.Hspec’ is redundant

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.8)

The import of ‘Test.Hspec’ is redundant

Check warning on line 41 in tests/Network/Test/Common.hs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 9.8)

The import of ‘Test.Hspec’ is redundant

serverAddr :: String
serverAddr = "127.0.0.1"
Expand All @@ -53,9 +52,6 @@
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
Expand Down
Loading