nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
714 stars 119 forks source link

memory leak when using collect #238

Closed luochen1990 closed 5 years ago

luochen1990 commented 5 years ago

When I'm using collect in my test code, I find that the memory of my PC grows slow when the progress is far from complete, and suddenly grows very fast when the progress is close to complete (such as 9999876/10000000), and my 8GB memory is not enough for this process, so it failed with the following message:

Test suite failure for package xxx
    xxx-test:  exited with: ExitFailure (-9)
Logs printed to console

And when I remove the collect part, it works well without using lot of memory.

I'm using stack with resolver: lts-12.22, following is the version info about QuickCheck:

$ stack ls dependencies | grep QuickCheck
QuickCheck 2.11.3

I can reproduce this problem on both Windows 10 and Ubuntu 18.04, following is my code to reproduce the problem:

main :: IO ()
main = hspec $ do
  describe "arith" $ do
    prop "plus-comm" $
      \(x :: Int) (y :: Int) ->
        collect (x == y) $ x + y === y + x

I'm running the test via stack test --test-arguments "-a 10000000 --match arith"

Since I'm collecting on a Bool, which has only 2 possible values, I don't think so many memory is necessary. I think there is a "memory leak" here for collect, I'm not sure whether other function such as classify and label will have the same problem yet.

nick8325 commented 5 years ago

collect was rewritten in QuickCheck 2.12. Could you try this on the latest version of QuickCheck (2.12.6.1) and see if you run into the same problem?

luochen1990 commented 5 years ago

@nick8325 Thanks for your suggestion, but I'm using stack to install QuickCheck, and the latest version on stackage nightly is still 2.11.3 , should we update it on stackage?

Lysxia commented 5 years ago

You can tell stack to install a different version of quickcheck by adding to stack.yaml:

extra-deps:
- "QuickCheck-2.12.6.1"
luochen1990 commented 5 years ago

@Lysxia Thanks for your suggestion, I tried it and stack will throw the following error in this case:

    Configuring hspec-core-2.5.5...
    Preprocessing library for hspec-core-2.5.5..
    Building library for hspec-core-2.5.5..
    [ 1 of 27] Compiling Control.Concurrent.Async ( vendor\Control\Concurrent\Async.hs, .stack-work\dist\e626a42b\build\Control\Concurrent\Async.o )
    [ 2 of 27] Compiling Data.Algorithm.Diff ( vendor\Data\Algorithm\Diff.hs, .stack-work\dist\e626a42b\build\Data\Algorithm\Diff.o )
    [ 3 of 27] Compiling Paths_hspec_core ( .stack-work\dist\e626a42b\build\autogen\Paths_hspec_core.hs, .stack-work\dist\e626a42b\build\Paths_hspec_core.o )
    [ 4 of 27] Compiling Test.Hspec.Core.Clock ( src\Test\Hspec\Core\Clock.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Clock.o )
    [ 5 of 27] Compiling Test.Hspec.Core.Compat ( src\Test\Hspec\Core\Compat.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Compat.o )
    [ 6 of 27] Compiling Test.Hspec.Core.Example.Location ( src\Test\Hspec\Core\Example\Location.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Example\Location.o )
    [ 7 of 27] Compiling Test.Hspec.Core.Formatters.Diff ( src\Test\Hspec\Core\Formatters\Diff.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Formatters\Diff.o )
    [ 8 of 27] Compiling Test.Hspec.Core.Formatters.Free ( src\Test\Hspec\Core\Formatters\Free.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Formatters\Free.o )
    [ 9 of 27] Compiling Test.Hspec.Core.Timer ( src\Test\Hspec\Core\Timer.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Timer.o )
    [10 of 27] Compiling Test.Hspec.Core.Util ( src\Test\Hspec\Core\Util.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\Util.o )
    [11 of 27] Compiling Test.Hspec.Core.QuickCheckUtil ( src\Test\Hspec\Core\QuickCheckUtil.hs, .stack-work\dist\e626a42b\build\Test\Hspec\Core\QuickCheckUtil.o )

    C:\dev\msys2\tmp\stack8300\hspec-core-2.5.5\src\Test\Hspec\Core\QuickCheckUtil.hs:23:40: error:
        Module ‘Test.QuickCheck.Test’ does not export ‘formatLabel’
       |
    23 | import           Test.QuickCheck.Test (formatLabel)
       |                                        ^^^^^^^^^^^

I think this is because the package hspec dependents on the function formatLabel which is removed from the new version.

luochen1990 commented 5 years ago

I find this PR of hspec, I will update my hspec and try again.

And I also found that the package version of both hspec & QuickCheck is updated in today's nightly snapshot on stackage.

luochen1990 commented 5 years ago

checked on latest version and it is fixed, closing this issue