Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create generator and such-that max retries #28

Closed
jobtravaini opened this issue Jan 3, 2024 · 4 comments
Closed

Create generator and such-that max retries #28

jobtravaini opened this issue Jan 3, 2024 · 4 comments

Comments

@jobtravaini
Copy link
Contributor

jobtravaini commented Jan 3, 2024

Context

A common exception when using a Schema to generate inputs with schema-generators is the Couldn't satisfy such-that predicate after 10 tries..

Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ExceptionInfo: Couldn't satisfy such-that predicate after 10 tries.
{:pred #object[schema_generators.generators$eval23572$fn__23573$fn__23574 0x4b466c6b "schema_generators.generators$eval23572$fn__23573$fn__23574@4b466c6b"], :gen #clojure.test.check.generators.Generator{:gen #object[clojure.test.check.generators$gen_bind$fn__7933 0x19220a00 "clojure.test.check.generators$gen_bind$fn__7933@19220a00"]}, :max-tries 10}
 at clojure.test.check.generators$fn__8055.invokeStatic (generators.cljc:435)
    clojure.test.check.generators/fn (generators.cljc:434)

This is more common for complex schemas with several conditions, and even with targeted generators sometimes a "not so good" generator can cause flakiness to tests when you are using schema to generate inputs.

Issues

It is understandable the suggested approach to create a specific generator for each use case as suggested here #5. There is a implicit downside to this approach which is maintenance of the generator and bug smashing during flakiness of tests.

A developed target generator for a complex defined Schema usually is not a great property tester because developers have tendencies to test the happy path and known paths, this behavior is translated into generators which create only small subsets of the property testing domain.

There is a trade-off between number of retries and domain specific generators for a Schema, such as processing power, test speed, domain property coverage, flakiness.

These trade-offs (and probably others not described here) should be weighted by the development team when deciding which approach to follow to create a test suite for their domain.

Suggestion

Allow targeted generators (as the best option suggested by #5) but also allow to configure such-that max-retries through a Dynamic Var, a function overload on generator, or another option we set fit to allow such feature to be available to development teams.

@jobtravaini jobtravaini changed the title Make-generator and such-that max retries Create generator and such-that max retries Jan 3, 2024
@w01fe
Copy link
Member

w01fe commented Jan 4, 2024

Hi, thanks for the detailed report! Definitely open to making this configurable, do you happen to know which such-that is causing the problem? (The such-that that we expose should be able to take additional parameters, but it looks like there are a few hardcoded ones that could be problematic as well)

@jobtravaini
Copy link
Contributor Author

jobtravaini commented Jan 4, 2024

Hello! Thanks for opening the possibility.

In my use case, the such-that which is causing flakiness is the extend-protocol implementation for the CompositeGenerator protocol here.

If you are comfortable with adding me as a contributor, I can open a PR with a suggestion of change and we can advance to a final solution from there. What do you think?

@w01fe
Copy link
Member

w01fe commented Jan 5, 2024

A PR would be appreciated, thanks!

for implementation, I like the idea of the fourth argument overload to generator, which could be a function from Schema to max-retries. Open to other options too.

@jobtravaini
Copy link
Contributor Author

Hello!

Opened #29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants