-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
ActionChain failure include never-executed actions since it uses wrong state object when creating transformations #426
Comments
Here's a better test case: class SetMutatingChainState {
final List<String> actualOps = new ArrayList<>();
final Set<Integer> set = new HashSet<>();
@Override
public String toString() {
return "set=" + set + ", actualOps=" + actualOps;
}
}
@Property
void chainActionsAreProperlyDescribedEvenAfterChainExecution(@ForAll("setMutatingChain") ActionChain<SetMutatingChainState> chain) {
SetMutatingChainState finalState = chain.run();
assertThat(chain.transformations())
.describedAs("chain.transformations(), final state is %s", finalState.set)
.isEqualTo(finalState.actualOps);
}
@Provide
public ActionChainArbitrary<SetMutatingChainState> setMutatingChain() {
return
ActionChain
.startWith(SetMutatingChainState::new)
.addAction(
1, (Action.Dependent<SetMutatingChainState>) state -> Arbitraries.just(
state.set.isEmpty()
? Transformer.noop()
: Transformer.<SetMutatingChainState>mutate("clear " + state.set, set -> {
state.actualOps.add("clear " + set.set);
state.set.clear();
})
)
)
.addAction(
2,
(Action.Dependent<SetMutatingChainState>)
state ->
Arbitraries
.integers()
.between(1, 10)
.map(i -> {
if (state.set.contains(i)) {
return Transformer.noop();
} else {
return Transformer.mutate("add " + i + " to " + state.set, newState -> {
newState.actualOps.add("add " + i + " to " + newState.set);
newState.set.add(i);
});
}
}
)
)
.withMaxTransformations(4);
} The failure is like
|
vlsi
pushed a commit
to vlsi/jqwik
that referenced
this issue
Dec 12, 2022
…wrong state object when creating transformations This change caches the transformation if it accesses state. fixes jqwik-team#426
jlink
pushed a commit
that referenced
this issue
Dec 18, 2022
…wrong state object when creating transformations This change caches the transformation if it accesses state. fixes #426
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing Problem
The issue has initially been described here: #134 (comment)
State-depending transformation might use the state for, well, figuring out the available transformations.
However, after the transformation is applied, the set of "allowable" transformations might change, so jqwik should use only the valid state objects when deriving transformations.
Here's a test case that shows invalid result produced by
chain.transformations()
.I believe, the root cause here is that
net.jqwik.engine.properties.state.ShrinkableChainIteration#transformer
re-instantiates transformation shrinkable, and it uses the same state object for instantiating transformers and taking their names.The exact seed does not matter much, however, the failure scenarios are different depending on the seed.
The text was updated successfully, but these errors were encountered: