From a2687d9f1a60cfb72f85962c501a68d110ed6de0 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Sun, 29 Mar 2026 12:36:40 +0200 Subject: [PATCH] test: prevent binding to the same port in parallel with -threaded tasty-1.5.4 [1] will execute test cases in parallel when built with -threaded. Since the test suite reuses the same ports constantly, but needs to test e.g. cancel behavior with multiple threads, we need to make sure that we don't try to bind to the same port in parallel. This commit implements the simplest fix for this, by simply adding inOrderTestGroup where necessary. [1]: https://hackage.haskell.org/package/tasty-1.5.4/changelog --- test/test.hs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/test/test.hs b/test/test.hs index 90f10d8..9305969 100644 --- a/test/test.hs +++ b/test/test.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} module Main where import Control.Concurrent (threadDelay) @@ -25,9 +26,16 @@ import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck as QC +-- Needed to disable test case parallelism with tasty >= 1.5.4, +-- but not available (nor necessary) for tasty < 1.5.4 +#if !MIN_VERSION_tasty(1,5,4) +inOrderTestGroup :: TestName -> [TestTree] -> TestTree +inOrderTestGroup = testGroup +#endif + main :: IO () main = defaultMain $ testGroup "socket" - [ testGroup "System.Socket" + [ inOrderTestGroup "System.Socket" [ group00 , group01 , group02 @@ -50,8 +58,8 @@ port6 :: Inet6Port port6 = 39000 group00 :: TestTree -group00 = testGroup "accept" - [ testGroup "Inet/Stream/TCP" +group00 = inOrderTestGroup "accept" + [ inOrderTestGroup "Inet/Stream/TCP" [ testCase "cancel operation" $ -- | This is to test interruptability of (blocking) calls like -- accept. The implementation may either run the call "safe" @@ -77,7 +85,7 @@ group00 = testGroup "accept" ] group01 :: TestTree -group01 = testGroup "connect" [ testGroup "Inet/Stream/TCP" t1 ] +group01 = inOrderTestGroup "connect" [ inOrderTestGroup "Inet/Stream/TCP" t1 ] where t1 = [ testCase "connect to closed port on inetLoopback" $ bracket @@ -160,8 +168,8 @@ group01 = testGroup "connect" [ testGroup "Inet/Stream/TCP" t1 ] ] group02 :: TestTree -group02 = testGroup "listen" - [ testGroup "Inet/Datagram/UDP" +group02 = inOrderTestGroup "listen" + [ inOrderTestGroup "Inet/Datagram/UDP" [ testCase "listen on bound socket" $ bracket ( socket :: IO (Socket Inet Datagram UDP) ) close $ \sock-> do bind sock (SocketAddressInet inetLoopback port) @@ -170,7 +178,7 @@ group02 = testGroup "listen" _ | e == eOperationNotSupported -> return () _ -> assertFailure "expected eOperationNotSupported" ] - , testGroup "Inet/Stream/TCP" + , inOrderTestGroup "Inet/Stream/TCP" [ testCase "listen on bound socket" $ bracket ( socket :: IO (Socket Inet Stream TCP) ) close $ \sock-> do bind sock (SocketAddressInet inetLoopback port) @@ -180,8 +188,8 @@ group02 = testGroup "listen" ] group03 :: TestTree -group03 = testGroup "send/receive" - [ testGroup "Inet/Stream/TCP" +group03 = inOrderTestGroup "send/receive" + [ inOrderTestGroup "Inet/Stream/TCP" [ testCase "send and receive a chunk" $ bracket ( do server <- socket :: IO (Socket Inet Stream TCP) @@ -264,7 +272,7 @@ group03 = testGroup "send/receive" Left e -> unless (e == ePipe) (throwIO e) ) ] - , testGroup "Inet/Datagram/UDP" + , inOrderTestGroup "Inet/Datagram/UDP" [ testCase "send and receive a datagram" $ bracket ( do server <- socket :: IO (Socket Inet Datagram UDP) @@ -292,8 +300,8 @@ group03 = testGroup "send/receive" ] group07 :: TestTree -group07 = testGroup "sendAll/receiveAll" - [ testGroup "Inet/Stream/TCP" +group07 = inOrderTestGroup "sendAll/receiveAll" + [ inOrderTestGroup "Inet/Stream/TCP" [ testCase "sendAll and receiveAll a 128MB chunk" $ bracket ( do server <- socket :: IO (Socket Inet Stream TCP) @@ -382,7 +390,7 @@ group07 = testGroup "sendAll/receiveAll" ] group80 :: TestTree -group80 = testGroup "setSocketOption" [ testGroup "V6Only" +group80 = inOrderTestGroup "setSocketOption" [ inOrderTestGroup "V6Only" [ testCase "present" $ bracket ( do server <- socket :: IO (Socket Inet6 Datagram UDP) @@ -433,7 +441,7 @@ group80 = testGroup "setSocketOption" [ testGroup "V6Only" ] group98 :: TestTree -group98 = testGroup "getAddress" [ +group98 = inOrderTestGroup "getAddress" [ testCase "getAddress after bind" $ bracket ( socket :: IO (Socket Inet Stream Default) ) close @@ -446,7 +454,7 @@ group98 = testGroup "getAddress" [ ] group99 :: TestTree -group99 = testGroup "getAddrInfo" [ +group99 = inOrderTestGroup "getAddrInfo" [ testCase "getAddrInfo \"127.0.0.1\" \"80\"" $ do ais <- getAddressInfo