testutils: use a rows parser for test comparisons#12138
Merged
systay merged 6 commits intovitessio:mainfrom Feb 14, 2023
Merged
testutils: use a rows parser for test comparisons#12138systay merged 6 commits intovitessio:mainfrom
systay merged 6 commits intovitessio:mainfrom
Conversation
Contributor
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
systay
reviewed
Jan 24, 2023
systay
approved these changes
Jan 24, 2023
Collaborator
systay
left a comment
There was a problem hiding this comment.
This is really great. Thank you!
frouioui
approved these changes
Jan 24, 2023
3 tasks
040d29c to
af5903f
Compare
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Vicent Marti <vmg@strn.cat>
af5903f to
6464bf4
Compare
Collaborator
Author
|
🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A pretty common pattern in Vitess end2end tests is comparing the results of a query against a hardcoded string that represents a
%v-formatted syntax of the rows we're expecting. It usually looks something like this:This is all well and good! There are several helpers that print the rows directly without having to call
Sprintfand that compare them directly. I like the literal strings to define the expectations for row results.However, shit gets funky when testing queries whose result from Vitess/MySQL doesn't have consistent ordering. How can we handle such comparisons when the
sql.Rowsreturned by Vitess can have any ordering but our expectation string is obviously fixed?This is how it's done at the moment:
This... doesn't seem generally safe? Is
SortStringdoing something very smart here? If you look at its implementation, you can see that, huh, it's doing the opposite of something very smart. It re-arranges all the individual bytes of the string alphabetically and returns that.So, for a rows string like
"[[INT64(1) INT64(8)] [INT64(1) INT64(9)]]", it generates" (((())))114444666689IIIINNNNTTTT[[[]]]"and compares that against the other formatted rows. The many ways in which this is not a generally safe way to compare row results are left to the reader. I bet you can come up with hundreds!So, onto the actual content of the PR: this PR introduces a generally safe way to compare unordered sets of rows! 🎉
It works by implementing a simple Lexer + Parser that can take a "row string" like the ones we use in our tests and converts it into an actual
sql.Row(i.e. a[]sql.Valueslice). Then, it performs an ordering-agnostic comparison of thesql.Valueentries against the values returned by Vitess/MySQL. It works very well in practice! We've tested it internally at PlanetScale.I'm hoping this will catch some actual mismatches in our end2end tests down the road.
Related Issue(s)
Checklist
Deployment Notes