on master help sign in
update test-server to test fd leaks including fsync'd db directory
9d8d1cdAgentM
test/Server/Main.hs+4−8
@@ -14,7 +14,6 @@ import ProjectM36.IsomorphicSchema
14import ProjectM36.Base
14import ProjectM36.Base
15
15
16import System.Exit
16import System.Exit
17−import System.IO
18
17
19import Control.Concurrent
18import Control.Concurrent
20import Network.Transport (EndPointAddress)
19import Network.Transport (EndPointAddress)
@@ -28,8 +27,6 @@ import System.Directory
28#endif
27#endif
29
28
30testList :: SessionId -> Connection -> MVar () -> Test
29testList :: SessionId -> Connection -> MVar () -> Test
31−testList sessionId conn _ = TestList [testFileDescriptorCount]
32−{-
33testList sessionId conn notificationTestMVar = TestList $ serverTests ++ sessionTests
30testList sessionId conn notificationTestMVar = TestList $ serverTests ++ sessionTests
34 where
31 where
35 sessionTests = map (\t -> t sessionId conn) [
32 sessionTests = map (\t -> t sessionId conn) [
@@ -47,7 +44,7 @@ testList sessionId conn notificationTestMVar = TestList $ serverTests ++ session
47 testNotification notificationTestMVar
44 testNotification notificationTestMVar
48 ]
45 ]
49 serverTests = [testRequestTimeout, testFileDescriptorCount]
46 serverTests = [testRequestTimeout, testFileDescriptorCount]
50−-}
47+
51main :: IO ()
48main :: IO ()
52main = do
49main = do
53 (serverAddress, _) <- launchTestServer 0
50 (serverAddress, _) <- launchTestServer 0
@@ -221,18 +218,17 @@ testFileDescriptorCount :: Test
221testFileDescriptorCount = TestCase $ do
218testFileDescriptorCount = TestCase $ do
222 (serverAddress, serverTid) <- launchTestServer 1000
219 (serverAddress, serverTid) <- launchTestServer 1000
223 unusedMVar <- newEmptyMVar
220 unusedMVar <- newEmptyMVar
221+ startCount <- fdCount
224 Right (sess, testConn) <- testConnection serverAddress unusedMVar
222 Right (sess, testConn) <- testConnection serverAddress unusedMVar
225− hPutStrLn stderr "GONK1"
226− startCount <- fdCount
227 --add a test commit to trigger the fsync machinery
223 --add a test commit to trigger the fsync machinery
228 executeDatabaseContextExpr sess testConn (Assign "x" (ExistingRelation relationFalse)) >>= eitherFail
224 executeDatabaseContextExpr sess testConn (Assign "x" (ExistingRelation relationFalse)) >>= eitherFail
229 commit sess testConn >>= eitherFail
225 commit sess testConn >>= eitherFail
230 close testConn
226 close testConn
231 endCount <- fdCount
227 endCount <- fdCount
232 let fd_diff = endCount - startCount
228 let fd_diff = endCount - startCount
233− hPutStrLn stderr "GONK2"
234− assertBool ("fd leak: " ++ show fd_diff) (fd_diff == 0)
229+ assertBool ("fd leak: " ++ show fd_diff) (fd_diff <= 0)
235 killThread serverTid
230 killThread serverTid
231+
236
232
237-- returns the number of open file descriptors -- linux only /proc usage
233-- returns the number of open file descriptors -- linux only /proc usage
238fdCount :: IO Int
234fdCount :: IO Int