Skip to content

Commit

Permalink
[stackage#4312] Relax network upper bound
Browse files Browse the repository at this point in the history
- Fixes:  commercialhaskell/stackage#4312
- Address some compiler warnings in tests (IO with unused result).
- Updated deprecated/removed upstream API usage in tests with conditional blocks to support older test matrices.
  • Loading branch information
naushadh committed Jan 20, 2019
1 parent c9c4d28 commit b9b74fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion io-streams.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Library
attoparsec >= 0.10 && <0.14,
bytestring >= 0.9 && <0.11,
bytestring-builder >= 0.10 && <0.11,
network >= 2.3 && <2.9,
network >= 2.3 && <3.1,
primitive >= 0.2 && <0.7,
process >= 1.1 && <1.7,
text >= 0.10 && <1.3,
Expand Down
2 changes: 1 addition & 1 deletion test/System/IO/Streams/Tests/Concurrent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ testConcurrentMerge = testCase "concurrent/concurrentMerge" $ do
chans
inputs <- mapM Streams.chanToInput chans
resultMVar <- newEmptyMVar
forkIO (Streams.concurrentMerge inputs >>= Streams.toList
_ <- forkIO (Streams.concurrentMerge inputs >>= Streams.toList
>>= putMVar resultMVar)
putMVar firstMVar 0
result <- takeMVar resultMVar
Expand Down
34 changes: 26 additions & 8 deletions test/System/IO/Streams/Tests/Network.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}

module System.IO.Streams.Tests.Network (tests) where

Expand All @@ -13,6 +14,10 @@ import System.Timeout (timeout)
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
#if MIN_VERSION_network(2,7,0)
#else
import Data.List (intercalate)
#endif
------------------------------------------------------------------------------
import qualified System.IO.Streams.Internal as Streams
import qualified System.IO.Streams.Internal.Network as Streams
Expand All @@ -32,39 +37,52 @@ testSocket = testCase "network/socket" $
assertEqual "ok" (Just ()) x

where
-- compats
#if MIN_VERSION_network(2,7,0)
mkAddr = pure . N.tupleToHostAddress
defaultPort = N.defaultPort
close = N.close
bind = N.bind
#else
mkAddr (o1,o2,o3,o4) = N.inet_addr . intercalate "." $ map show [o1,o2,o3,o4]
defaultPort = N.aNY_PORT
close = N.sClose
bind = N.bindSocket
#endif

go = do
portMVar <- newEmptyMVar
resultMVar <- newEmptyMVar
forkIO $ client portMVar resultMVar
_ <- forkIO $ client portMVar resultMVar
server portMVar
l <- takeMVar resultMVar
assertEqual "testSocket" l ["ok"]

client mvar resultMVar = do
port <- takeMVar mvar
sock <- N.socket N.AF_INET N.Stream N.defaultProtocol
addr <- N.inet_addr "127.0.0.1"
addr <- mkAddr (127, 0, 0, 1)
let saddr = N.SockAddrInet port addr
N.connect sock saddr
(is, os) <- Streams.socketToStreams sock
Streams.fromList ["", "ok"] >>= Streams.connectTo os
N.shutdown sock N.ShutdownSend
Streams.toList is >>= putMVar resultMVar
N.sClose sock
close sock

server mvar = do
sock <- N.socket N.AF_INET N.Stream N.defaultProtocol
addr <- N.inet_addr "127.0.0.1"
let saddr = N.SockAddrInet N.aNY_PORT addr
N.bindSocket sock saddr
addr <- mkAddr (127, 0, 0, 1)
let saddr = N.SockAddrInet defaultPort addr
bind sock saddr
N.listen sock 5
port <- N.socketPort sock
putMVar mvar port
(csock, _) <- N.accept sock
(is, os) <- Streams.socketToStreams csock
Streams.toList is >>= flip Streams.writeList os
N.sClose csock
N.sClose sock
close csock
close sock

testSocketWithError :: Test
testSocketWithError = testCase "network/socket-error" $ N.withSocketsDo $ do
Expand Down

0 comments on commit b9b74fa

Please sign in to comment.