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

Rapid test ensure bitstream consumed #2013

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

VenelinMartinov
Copy link
Contributor

[rapid] flaky test, can not reproduce a failure
        Traceback (group did not use any data from bitstream; this is likely a result of Custom generator not calling any of the built-in generators):

rapid wants us to always consume from the random bitstream but we don't do that when we generate empty collection values. This just adds some generators in those cases so that rapid doesn't panic.

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 60.77%. Comparing base (2094289) to head (cf0801e).

Files Patch % Lines
pkg/tests/cross-tests/rapid_tv_gen.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2013   +/-   ##
=======================================
  Coverage   60.76%   60.77%           
=======================================
  Files         350      350           
  Lines       45686    45689    +3     
=======================================
+ Hits        27762    27766    +4     
  Misses      16405    16405           
+ Partials     1519     1518    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -401,6 +402,7 @@ func (tvg *tvGen) WithNullAndUnknown(gen *rapid.Generator[tv]) *rapid.Generator[
nullGen := rapid.Just(tftypes.NewValue(tv0.typ, nil))
options = append(options, nullGen)
}
_ = rapid.Bool().Draw(t, "consumeBitstream2")
Copy link
Member

Choose a reason for hiding this comment

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

Well, hmm, I bet this is not idiomatic but I don't know if this introduces any semantic problems also.

Is the problem simply in the degenerate case where we have:

tvg.generateUnknowns == false
!tv0.schema.Required == false
options == []*rapid.Generator[tftypes.Value]{gen}
gen == rapid.OneOf(options...)

Should it stop wrapping gen with rapid.OneOf(gen) in that case maybe that fixes the problem?

Copy link
Member

Choose a reason for hiding this comment

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

This one feels especially wrong. We do draw entropy from t on L393+: tv0 := gen.Draw(t, "tv"). The only way we can get this error message (as I understand it), is if gen.Draw(t, "tv") doesn't draw entropy, implying the bug is somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not verified both are needed, just that the panic no longer happens with them.

@@ -209,6 +209,7 @@ func (tvg *tvGen) GenBlockWithDepth(depth int) *rapid.Generator[tb] {
return tftypes.NewValue(objType, fields)
})
} else {
_ = rapid.Bool().Draw(t, "consumeBitstream1")
Copy link
Member

Choose a reason for hiding this comment

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

This is really weird also. I think perhaps issue could be with this code when minFields=3 and there's no entropy going into the result?

nFields := rapid.IntRange(minFields, 3).Draw(t, "nFields")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the issue comes when drawing the values, not the schema.

I suspect if we run into this branch, we produce a rapid.Just(tftypes.NewValue(objType, map[string]tftypes.Value{})) which consumes none of the entropy.

I don't see why this has to consume the bitstream, really - am I misunderstanding the framework here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The whole thing is a bit tricky since I haven't found a reliable way of reproducing the issue - it's sensitive to code changes, so the same seed does not produce the error after changing the code.

Copy link
Member

Choose a reason for hiding this comment

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

rapid.Just should be fine so long as something else drew entropy. I think the problem arises where rapid.Custom(f) draws no entropy in f.

Copy link
Member

Choose a reason for hiding this comment

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

We always draw entropy, when calling rapid.IntRange(minFields, 3).Draw(t, "nFields"). @VenelinMartinov If we leave a hack like this in, can you please mark it with a TODO and create an issue to track removing the hack.

That would be a good issue for help-wanted and good-first-issue.

Copy link
Member

Choose a reason for hiding this comment

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

That would be a good issue for help-wanted and good-first-issue.

Well FWIW I do not think so, unfortunately I do not think this would work very well.. As an external contributor I'd expect to have zero interest in verification work as it is too indirectly connected to end-user problems and outcomes. Perhaps we can make a distinction between easy onboarding tasks and welcoming external contributors.

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

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

OK to merge as workaround but feels a little off.

VenelinMartinov added a commit that referenced this pull request May 22, 2024
The encompassing if check was flipped and this didn't work correctly.
#2013 should take
care of the rapid panics for unconsumed bitrstreams, so the encompassing
if check should not be needed any more.
@iwahbe
Copy link
Member

iwahbe commented Jun 5, 2024

@VenelinMartinov Do we want to merge this?

@VenelinMartinov
Copy link
Contributor Author

VenelinMartinov commented Jun 6, 2024

I've meant to revisit but haven't managed to yet. If you are seeing the panics here then I'm happy to merge this until we find time to root-cause

@iwahbe
Copy link
Member

iwahbe commented Jun 6, 2024

I've meant to revisit but haven't managed to yet.

No problem.

If you are seeing the panics here then I'm happy to merge this until we find time to root-cause

I'm not sure what you mean here.

@VenelinMartinov
Copy link
Contributor Author

I'm not sure what you mean here.

Are you blocked on this PR getting merged or were you just revisiting old PRs?

@iwahbe
Copy link
Member

iwahbe commented Jun 6, 2024

I'm not sure what you mean here.

Are you blocked on this PR getting merged or were you just revisiting old PRs?

Just revisiting old PRs.

@iwahbe
Copy link
Member

iwahbe commented Dec 3, 2024

@VenelinMartinov Are you still interested in pushing this PR forward?

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.

3 participants