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

Cache several shrink results for every chain step, so it does not re-access state model state during shrink phase #436

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vlsi
Copy link
Contributor

@vlsi vlsi commented Dec 14, 2022

Overview

See "a" in #428 (comment)

a) Sample (and keep) several .shrink() results for each action before the action is executed.
Pro: we would have valid shrink results (the shrink result would strictly correspond to the state)
Cons: it would spend time and memory on keeping .shrink() results even in case the chain succeeds.
Cons: it does not fully fit "try many different shrink types, order them, and start with the most promising ones" since we would be able to keep only a few shrink results for each action.

Details

The number of cached shrinkables could be configured via jqwik.eagerChainShrinkSamples system property. I default it to 2.


I hereby agree to the terms of the jqwik Contributor Agreement.

Vladimir Sitnikov added 2 commits December 12, 2022 15:03
…wrong state object when creating transformations

This change caches the transformation if it accesses state.

fixes jqwik-team#426
…access state model state during shrink phase

This might take slightly more memory and produce suboptimal shrinks,
however makes shrink possible for state-accessing transformations.

Fixes jqwik-team#428
@vlsi vlsi changed the title Cache several shrink resultsfor every chain step, so it does not re-access state model state during shrink phase Cache several shrink results for every chain step, so it does not re-access state model state during shrink phase Dec 14, 2022
Comment on lines +133 to +138
@Property
void chainActionsAreProperlyDescribedEvenAfterChainExecution(@ForAll("setMutatingChain") ActionChain<SetMutatingChainState> chain) {
chain = chain.withInvariant(
state -> {
if (state.hasPrints) {
assertThat(state.actualOps).hasSizeLessThan(5);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the property is going to fail, so I probably need to add some kind of post-processing to treat "hasSizeLessThan violations as expected".

Comment on lines +48 to +49
.sorted(Comparator.comparing(Shrinkable::distance))
.limit(numSamples)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This triggers OOM in case .shrink() stream is big. See #338 (comment)

@vlsi
Copy link
Contributor Author

vlsi commented Dec 15, 2022

I tried re-enabling shrink for my action chain, and it turns out to spend too much time shrinking (too many variations? too many restrictions in the current shrink approach like "after shrink, all the subsequent state-accessing actions must be discarded"?)

I tried this change with my current tests. and the property fails after ~8 minutes with shrink=OFF producing ~15 actions. However, if I enable shrinking and re-run with the same seed, then it can't converge after 40-50 minutes, so I am inclined to just go for shrink=OFF and get the failure faster.

I consider implementing toString-like methods that would print test code instead of "list of actions". Then I would be able to "shrink" the test manually by commenting-out irrelevant bits of the generated test code.

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

Successfully merging this pull request may close these issues.

None yet

1 participant