quickcheck icon indicating copy to clipboard operation
quickcheck copied to clipboard

Run tests on multiple cores

Open amigalemming opened this issue 8 years ago • 9 comments

There are packages like pqc and tasty-quickcheck that allow to run tests in parallel on multiple cores. Since they run tests on different properties in parallel, they do no longer show the increasing test counter. Would it be possible to run different tests on the same property in parallel? This would still enable the live counter. Maybe it would even save some memory if tests on the same property share some data. Maybe the parallel testing could be enabled by a new field of Args for the number of parallel testing threads?

amigalemming avatar Jul 25 '17 21:07 amigalemming

That would certainly be a nice feature!

It would require re-working the main QuickCheck loop in Test.QuickCheck.Test to spawn several tests and collect the reults. Possibly a bit of work, but something we probably ought to do.

nick8325 avatar Jul 31 '17 21:07 nick8325

@amigalemming Just as a side note, it is possible to show progress information, even when running QuickCheck properties in parallel. hspec does exactly that.

The hairy details:

  • We assume that the user runs a test suite with n tests.
  • The user specifies N, the number of parallel tests to run at a time.
  • Hspec's runner spawns one thread for each test, t₁ to tₙ.
  • Each thread tₓ has an associated Mₓ :: MVar (Either Progress Result).
  • Each thread waits on a semaphore with the capacity N.
  • Once a thread tₓ is signaled to run, it runs the associated test; while doing so it writes progress information into Mₓ and once it's done the result (that is write if the MVar is empty, otherwise replace).
  • The applications main thread folds over the list M₁..ₙ
  • For each Mₓ it reads the current value and writes progress information as long as it gets a Left-value.
  • Once it reads a Right-value it reports the result to the user and moves on to Mₓ₊₁.

With this approach we see progress information for the currently running test with the lowest x only. In practice this works out nicely.

/cc @feuerbach

sol avatar Aug 01 '17 06:08 sol

It seems that QuickCheck-2.11 uses more cores, at least top reports CPU usage higher than 300%. If so, I think it is not a good idea to parallelize without permission by the user. How can I limit the number of cores/threads used?

amigalemming avatar Mar 22 '19 00:03 amigalemming

No, it doesn't parallelise automatically! Not sure what's going on there.

nick8325 avatar Mar 23 '19 23:03 nick8325

I have implemented this :) With some blood, sweat, and tears, it should be in 2.16. Stay tuned

Rewbert avatar Apr 25 '24 11:04 Rewbert

How soon 2.16 is expected? If it's "soon", than I won't care updating to QuickCheck-2.15 at all in between.

phadej avatar Apr 25 '24 13:04 phadej

@phadej There is no timeline. I think it will be a nightmare to merge, but worth it.

Rewbert avatar Apr 25 '24 14:04 Rewbert

To clarify; I would not wait if I were you.

Rewbert avatar Apr 25 '24 14:04 Rewbert

Here is a link to the paper describing the work done on this: https://arxiv.org/pdf/2404.16062

Rewbert avatar May 16 '24 12:05 Rewbert