expecto icon indicating copy to clipboard operation
expecto copied to clipboard

Expose AsyncTest for FsCheck

Open haf opened this issue 7 years ago • 6 comments

It would be nice to support async FsCheck tests explicitly in the API. /cc @AnthonyLloyd

E.g.

testPropertyAsync fsCheckConfig <| fun a b c ->
  async {
    do! subject a b c
  }

haf avatar Mar 09 '17 15:03 haf

I did think about this a bit but didn't put it in in the end.

I could only make it:

testPropertyAsync fsCheckConfig <| fun (a,b,c) ->
  async {
    do! subject a b c
  }

And I just use Async.RunSynchronously when passing to FsCheck.

FsCheck only offers sync at the moment but they are looking to add async soon.

Could be worth putting it in now if we could get the signature correct.

AnthonyLloyd avatar Mar 09 '17 16:03 AnthonyLloyd

I was thinking we could parametise the IRunner to take a chunk to evaluate and a callback to call with the evaluated chunk. That way we don't have to tie FsCheck to the async implementation (Task/Async/Job/Alt/etc) /cc @kurtschelfthout

haf avatar Mar 09 '17 16:03 haf

@kurtschelfthout @mausch What's your opinion?

haf avatar Apr 03 '17 15:04 haf

Not sure it can work. Things to think about:

  • Sizing. FsCheck linearly increases the size from startsize to endsize during the test. So if you want a similar size distribution of your tests as a sequential test from size 0-100, you could chop it up in 4 parallel runs as 0-24,25-49 etc. But, it's likely that larger size tests will be slower, so perhaps that's not such a great idea. Also, endsize-startsize may not be cleanly divisible by the number of parallel runs.
  • Reproducibility. A run is reproducible if you have the start seed, start size and end size (generated values are dependent on seed and size). I'm not sure there is a good way to track all of that for each parallel run.
  • Parts of FsCheck are not thread-safe.

See also https://github.com/fscheck/FsCheck/pull/351

kurtschelfthout avatar Apr 04 '17 07:04 kurtschelfthout

Now that https://github.com/fscheck/FsCheck/pull/351#issuecomment-327929291 has been merged we should use it in Expecto. @kurtschelfthout I wasn't able to find any docs to link to? How is this feature used?

haf avatar Mar 10 '18 14:03 haf

It's only merged to FsCheck 3. If you take a dependency on that, please use exact versioning constraints, as it's currently in alpha and I do expect the API to change significantly.

To use, run a property that returns Task or Async.

kurtschelfthout avatar Mar 11 '18 16:03 kurtschelfthout