Skip to content

Commit 98a4d1b

Browse files
committed
Fix flaky tests
1 parent 030e3af commit 98a4d1b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/Properties.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE BangPatterns #-}
23
{-# LANGUAGE QuasiQuotes #-}
34
{-# LANGUAGE OverloadedStrings #-}
45
{-# LANGUAGE TypeApplications #-}
@@ -124,8 +125,9 @@ concFile = do
124125
baseDir <- OSP.encodeFS baseDir'
125126
let fp = baseDir </> [osp|foo|]
126127
OSP.writeFile fp ""
127-
_ <- OSP.openFile fp ReadMode
128+
!h <- OSP.openFile fp ReadMode
128129
r <- try @IOException $ OSP.withFile fp WriteMode $ \h' -> do BS.hPut h' "test"
130+
_ <- try @IOException $ BS.hPut h ""
129131
IOError Nothing fileLockedType "withFile" fileLockedMsg Nothing (Just $ baseDir' FP.</> "foo") @==? r
130132

131133
concFile2 :: Assertion
@@ -134,8 +136,9 @@ concFile2 = do
134136
baseDir <- OSP.encodeFS baseDir'
135137
let fp = baseDir </> [osp|foo|]
136138
OSP.writeFile fp "h"
137-
_ <- OSP.openFile fp ReadMode
139+
!h <- OSP.openFile fp ReadMode
138140
r <- try @IOException $ OSP.withFile fp ReadMode BS.hGetContents
141+
_ <- try @IOException $ BS.hPut h ""
139142
Right "h" @=? r
140143

141144
concFile3 :: Assertion
@@ -144,8 +147,9 @@ concFile3 = do
144147
baseDir <- OSP.encodeFS baseDir'
145148
let fp = baseDir </> [osp|foo|]
146149
OSP.writeFile fp ""
147-
_ <- OSP.openFile fp WriteMode
150+
!h <- OSP.openFile fp ReadMode
148151
r <- try @IOException $ OSP.withFile fp WriteMode (flip BS.hPut "test")
152+
_ <- try @IOException $ BS.hPut h ""
149153
IOError Nothing fileLockedType "withFile" fileLockedMsg Nothing (Just $ baseDir' FP.</> "foo") @==? r
150154

151155
existingFile :: Assertion
@@ -221,9 +225,10 @@ existingFile4' = do
221225
OSP.openExistingFile fp ReadWriteMode >>= \h -> do
222226
hSetBuffering h NoBuffering
223227
BS.hPut h "boo"
224-
c <- BS.hGetSome h 5
228+
!c <- BS.hGetSome h 5
225229
hSeek h AbsoluteSeek 0
226-
c' <- BS.hGetSome h 5
230+
!c' <- BS.hGetSome h 5
231+
hClose h
227232
pure (c, c')
228233
Right ("tx", "bootx") @=? r
229234

@@ -232,7 +237,7 @@ openTempFile1 open = do
232237
withSystemTempDirectory "test" $ \baseDir' -> do
233238
baseDir <- OSP.encodeFS baseDir'
234239
let file = [osp|foo.ext|]
235-
(fp, h') <- open baseDir file
240+
(!fp, h') <- open baseDir file
236241
hClose h'
237242
r <- try @IOException $ do
238243
OSP.openExistingFile fp ReadWriteMode >>= \h -> BS.hPut h "boo" >> hClose h
@@ -255,8 +260,10 @@ openTempFile3 open = do
255260
withSystemTempDirectory "test" $ \baseDir' -> do
256261
baseDir <- OSP.encodeFS baseDir'
257262
let file = [osp|foo.ext|]
258-
(fp, _) <- open baseDir file
259-
(fp', _) <- open baseDir file
263+
(!fp, h) <- open baseDir file
264+
(!fp', h') <- open baseDir file
265+
hClose h
266+
hClose h'
260267
(fp /= fp') @? "Filepaths are different"
261268

262269

0 commit comments

Comments
 (0)