flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
579 stars 25 forks source link

More explanation on when "group did not use any data from bitstream" occurs. #42

Closed pierre-fastly closed 1 year ago

pierre-fastly commented 1 year ago

I have a generator + a filter and try to draw from this. And in some cases, I get this error:

[rapid] flaky test, can not reproduce a failure
...

Traceback (group did not use any data from bitstream):

vendor/pgregory.net/rapid/engine.go:77 in pgregory.net/rapid.assertf
vendor/pgregory.net/rapid/data.go:128 in pgregory.net/rapid.(*recordedBits).endGroup
vendor/pgregory.net/rapid/combinators.go:107 in pgregory.net/rapid.find[...]
vendor/pgregory.net/rapid/combinators.go:33 in pgregory.net/rapid.(*customGen[...]).value
vendor/pgregory.net/rapid/generator.go:72 in pgregory.net/rapid.(*Generator[...]).value
vendor/pgregory.net/rapid/collections.go:78 in pgregory.net/rapid.(*sliceGen[...]).value
vendor/pgregory.net/rapid/generator.go:72 in pgregory.net/rapid.(*Generator[...]).value
vendor/pgregory.net/rapid/generator.go:45 in pgregory.net/rapid.(*Generator[...]).Draw
vendor/pgregory.net/rapid/combinators.go:47 in pgregory.net/rapid.(*customGen[...]).maybeValue
vendor/pgregory.net/rapid/combinators.go:106 in pgregory.net/rapid.find[...]
vendor/pgregory.net/rapid/combinators.go:33 in pgregory.net/rapid.(*customGen[...]).value
vendor/pgregory.net/rapid/generator.go:72 in pgregory.net/rapid.(*Generator[...]).value
vendor/pgregory.net/rapid/combinators.go:94 in pgregory.net/rapid.(*filteredGen[...]).maybeValue
vendor/pgregory.net/rapid/combinators.go:106 in pgregory.net/rapid.find[...]
vendor/pgregory.net/rapid/combinators.go:90 in pgregory.net/rapid.(*filteredGen[...]).value
vendor/pgregory.net/rapid/generator.go:72 in pgregory.net/rapid.(*Generator[...]).value
vendor/pgregory.net/rapid/generator.go:45 in pgregory.net/rapid.(*Generator[...]).Draw
testing/integration/my_rapid_test.go:167 in testing/integration.(*myStateMachine).AddSiteMissing
vendor/pgregory.net/rapid/statemachine.go:174 in pgregory.net/rapid.runAction
vendor/pgregory.net/rapid/statemachine.go:149 in pgregory.net/rapid.(*stateMachine).executeAction
vendor/pgregory.net/rapid/statemachine.go:83 in pgregory.net/rapid.Run[...].func1
vendor/pgregory.net/rapid/engine.go:319 in pgregory.net/rapid.checkOnce

Original traceback:

vendor/pgregory.net/rapid/engine.go:596 in pgregory.net/rapid.(*T).fail
vendor/pgregory.net/rapid/engine.go:559 in pgregory.net/rapid.(*T).Fatalf
testing/integration/my_rapid_test.go:276 in testing/integration.(*myStateMachine).RemoveNonExisting
vendor/pgregory.net/rapid/statemachine.go:174 in pgregory.net/rapid.runAction
vendor/pgregory.net/rapid/statemachine.go:149 in pgregory.net/rapid.(*stateMachine).executeAction
vendor/pgregory.net/rapid/statemachine.go:83 in pgregory.net/rapid.Run[...].func1
vendor/pgregory.net/rapid/engine.go:319 in pgregory.net/rapid.checkOnce

...

I'm unsure how to fix this TBH. My guess is the filter filters everything and rapid gives up at some point but... that's just a guess.

Also, the test I have is pretty huge, I cannot reproduce this with a small example. Any idea what I can try?

flyingmutant commented 1 year ago

Can there be a case where you custom generator does not, in fact, use any data from the bitstream? This can happen when it under some conditions never calls one of the built-in generators (which should always draw some data even when they end up not generating anything).

bilus commented 1 year ago

Here's an example:

_ = rapid.Permutation([]int{1}).Draw(t, "foo")

This will trigger the ^ error.

flyingmutant commented 1 year ago

@bilus thanks for the Permutation case, good catch! I've found and fixed one more (for 0-field structs generated with Make), I hope there are no other built-in generators with this problem. Feel free to reopen this issue in case the error will strike back!