Skip to content

Commit

Permalink
core: fix nar test failing when there's no /proc
Browse files Browse the repository at this point in the history
Closes #109.
  • Loading branch information
sorki authored and Anton-Latukha committed Feb 25, 2021
1 parent cf04083 commit 2a897ab
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions hnix-store-core/tests/NarFormat.hs
Expand Up @@ -231,7 +231,7 @@ test_streamManyFilesToNar = HU.testCaseSteps "streamManyFilesToNar" $ \step ->
IO.withFile "hnar" IO.WriteMode $ \h ->
buildNarIO narEffectsIO narFilePath h
filesPostcount <- countProcessFiles
pure $ filesPostcount - filesPrecount
pure $ (-) <$> filesPostcount <*> filesPrecount

step "create test files"
Directory.createDirectory packagePath
Expand All @@ -252,7 +252,9 @@ test_streamManyFilesToNar = HU.testCaseSteps "streamManyFilesToNar" $ \step ->

step "check constant file usage"
filesPostcount <- countProcessFiles
(filesPostcount - filesPrecount) `shouldSatisfy` (< 50)
case ((-) <$> filesPostcount <*> filesPrecount) of
Nothing -> pure ()
Just c -> c `shouldSatisfy` (< 50)

-- step "check file exists"
-- e <- doesPathExist packagePath'
Expand Down Expand Up @@ -361,12 +363,16 @@ packThenExtract testName setup =
pure ()

-- | Count file descriptors owned by the current process
countProcessFiles :: IO Int
countProcessFiles :: IO (Maybe Int)
countProcessFiles = do
pid <- Unix.getProcessID
let fdDir = "/proc/" <> show pid <> "/fd"
fds <- P.readProcess "ls" [fdDir] ""
pure $ length $ words fds
hasProc <- doesDirectoryExist "/proc"
if not hasProc
then pure Nothing
else do
let fdDir = "/proc/" <> show pid <> "/fd"
fds <- P.readProcess "ls" [fdDir] ""
pure $ pure $ length $ words fds


-- | Read the binary output of `nix-store --dump` for a filepath
Expand Down

0 comments on commit 2a897ab

Please sign in to comment.