Comments (5)
Arrays/lists can have very long shrink sequences. It tries to remove one element at a time.
from fscheck.
FsCheck has no magic way to prevent shrinking if you literally evaluate it explicitly. Under normal circumstances, it won't shrink unless the random part of the test fails.
Shrinking can take a long time. It can also get stuck in a loop, if shrinking a value yields the same value again somewhere along the way.
from fscheck.
Sorry maybe I didn't explain well. I'm defining an arbitrary instance like
let arbInstance =
{ new Arbitrary<...>() with
override x.Generator = ...
override x.Shrinker(dates) = ...
}
and the issue I'm having is that putting
let _ = (ArbMap.defaults |> ArbMap.arbitrary |> Arb.toShrink) dates |> Seq.length
inside my Shrinker
method override freezes my tests, even when they're passing, in which case I would expect Shrinker
to never be called.
I suppose it doesn't really matter, since the implementation shouldn't evaluate the infinite sequence anyways, it was just confusing behaviour and took me a while to figure out what was happening.
I'll make a PR adding to the docs that the sequence of shrinks may be infinite, and evaluating that sequence may freeze the tests even if no tests are failing.
from fscheck.
I see. Yes, FsCheck relies on the laziness of the returned sequence. It will call Shrinker
during normal evaluation of the test, and capture the resulting sequence. This allows it to pick up shrinking with the values the test failed with. It effectively captures Shrinker(dates)
in a closure, but only evaluates the resulting sequence one at a time, and only evaluates the sequence if the random test fails.
from fscheck.
Thanks for the explanation, I'll update my PR tomorrow.
I managed to minimize the issue I was running into, it turned out to be just that the shrink sequence was a lot bigger than I thought. A minimal repro:
[<Property>]
let ``test`` () =
Prop.forAll (
{ new Arbitrary<int[]>() with
override x.Generator = Seq.init 500 (fun i -> i) |> Seq.toArray |> Gen.constant
override x.Shrinker(vs) =
let shrunk = (ArbMap.defaults |> ArbMap.arbitrary |> Arb.toShrink) vs
// let _ = Seq.length shrunk
Seq.empty }
)
<| fun (vs) -> true
Here, uncommenting the Seq.length
line makes the test take 10 seconds. Commented it takes less than a second.
My original case was generating a datetime array with a size much larger than 500, so it appeared the test was stuck in an infinite loop.
from fscheck.
Related Issues (20)
- feat(FsCheck.Xunit): Support xUnit >= 2.5, < 3 HOT 1
- Modelbased testing? HOT 3
- Expose `Gen.choose64` HOT 1
- feat(FsCheck.NUnit): Support NUnit >= 4.0.0 HOT 1
- Model-based testing examples in C#? HOT 2
- Check.QuickAll does not find testables that return unit HOT 2
- Prop.filter (==>) executes property even if condition does not hold HOT 4
- `StringNoNulls` is passing a null? HOT 6
- FsCheck 3.0.0-rc1 in C# is ignoring Xunit property size values HOT 2
- FsCheck generating test objects in C# HOT 5
- FsCheck 3.0.0-rc1 XUnit Property attribute doesn't respect IAsyncLifetime HOT 1
- FsCheck 3.0.0 RC1 dependency on xunit.extensibility.execution is out of date by three minor versions. HOT 6
- Consider providing a more explicit implementation of `IArbMap` HOT 6
- No instances of class FsCheck.Testable+ITestable1[T] for type Microsoft.FSharp.Collections.FSharpList1[FsCheck.Property] HOT 3
- Fallout from Paket and FAKE deletion HOT 19
- Packaging improvements HOT 8
- Add README to NuGet packages
- Wrong xUnit runner "xunit.execution.dotnet" chosen for .NET Framework property tests HOT 7
- CVE issues from use of old libraries HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fscheck.