@@ -1,3 +1,4 @@
2test client/server interaction
3test client/server interaction
@@ -13,6 +14,7 @@ import ProjectM36.IsomorphicSchema
13import ProjectM36.Base
14import ProjectM36.Base
15import System.Exit
16import System.Exit
16import Control.Concurrent
18import Control.Concurrent
17import Network.Transport (EndPointAddress)
19import Network.Transport (EndPointAddress)
18import Network.Transport.TCP (encodeEndPointAddress, decodeEndPointAddress)
20import Network.Transport.TCP (encodeEndPointAddress, decodeEndPointAddress)
@@ -20,6 +22,9 @@ import Data.Either (isRight)
20import Data.Maybe (isJust)
22import Data.Maybe (isJust)
21import Control.Exception
23import Control.Exception
22--import Control.Monad.IO.Class
24--import Control.Monad.IO.Class
25+#if defined(linux_HOST_OS)
26+import System.Directory
24testList :: SessionId -> Connection -> MVar () -> Test
29testList :: SessionId -> Connection -> MVar () -> Test
25testList sessionId conn notificationTestMVar = TestList $ serverTests ++ sessionTests
30testList sessionId conn notificationTestMVar = TestList $ serverTests ++ sessionTests
@@ -38,7 +43,7 @@ testList sessionId conn notificationTestMVar = TestList $ serverTests ++ session
38 testRelationVariableSummary,
43 testRelationVariableSummary,
39 testNotification notificationTestMVar
44 testNotification notificationTestMVar
41− serverTests = [testRequestTimeout]
46+ serverTests = [testRequestTimeout, testFileDescriptorCount]
43main :: IO ()
48main :: IO ()
@@ -205,4 +210,27 @@ testRequestTimeout = TestCase $ do
205 Right (session, testConn) -> do
210 Right (session, testConn) -> do
206 res <- catchJust (\exc -> if exc == RequestTimeoutException then Just exc else Nothing) (callTestTimeout_ session testConn) (const (pure False))
211 res <- catchJust (\exc -> if exc == RequestTimeoutException then Just exc else Nothing) (callTestTimeout_ session testConn) (const (pure False))
207 assertBool "exception was not thrown" (not res)
212 assertBool "exception was not thrown" (not res)
208− killThread serverTid
213+ killThread serverTid
215+testFileDescriptorCount :: Test
216+#if defined(linux_HOST_OS)
217+--validate that creating a server, connecting a client, and then disconnecting doesn't leak file descriptors
218+testFileDescriptorCount = TestCase $ do
219+ (serverAddress, serverTid) <- launchTestServer 1000
220+ startCount <- fdCount
221+ unusedMVar <- newEmptyMVar
222+ Right (_, testConn) <- testConnection serverAddress unusedMVar
225+ assertEqual "fd leak" startCount endCount
226+ killThread serverTid
228+-- returns the number of open file descriptors -- linux only /proc usage
231+ fds <- getDirectoryContents "/proc/self/fd"
232+ pure ((length fds) - 2)
234+ --pass on non-linux platforms
235+ testFileDescriptorCount = TestCase (pure ())