-
Notifications
You must be signed in to change notification settings - Fork 44
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
test: Add new setup for testing explain functionality #949
Conversation
8155d46
to
36da36a
Compare
The implementation seems logical to me. @AndrewSisley will probably have a stronger opinion than I do on this one so you might want to wait for his feedback. I did spot a few things that I'll review properly once this goes out of draft but not implementation related. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the last commit (Add the explain tests refactor setup.), I like it and added some localized todos. Would be really handy if you amended a couple of example tests into this commit though, as I'm having to guess/imagine what they might look like.
Thanks for the feedback! I do have an example test that contains the old way and the new way for a side-by-side comparison (in the second last commit). File: tests/integration/explain/simple/old_and_new_example_test.go |
😆 need to shuffle those commits around lol - the example (commit) makes use of stuff contained in a later commit 😁 I didn't think to look there Update: I looked at the example test - looks really nice :) |
Haha yea will do, sorry about the confusion. |
d55babf
to
c673038
Compare
c673038
to
6b809a7
Compare
aa53987
to
e5afb14
Compare
I found myself wanting to quickly see if my changes to the test files still compiles the tests. Hence this rule.
Also fix all the tests whose keys and other attributes changed due to having a different schema (all mutation explain tests were moved to use the previous schema used by query explain tests.).
This commit makes some changes that would let us reuse some code that will also be needed for the new explain setup. As the explain testing setup will build on top of this, I wanted this to be a separate commit. Hopefully not too bad to review.
e5afb14
to
f91840f
Compare
Example to see the old and new testing sie by side. Note: This commit will be dropped before merge, it is there only to help visualize the usage of the new explain test setup.
f91840f
to
f0cd96f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really nice Shahzad - I really like the design and am curious as to how it will feel when writing tests :) Added a couple of minor/localized comments that would be good to sort out before merge.
RE: Should the conversion of old to new tests happen in this same PR or separately?
I think separately works well, is already a lot of work in this PR and stuff will get missed if it continues to grow (plus any new tests written in the meantime wont have access to the new stuff and will just add more work to this PR)
RE: The ExpectedTarget functionality was implemented assuming ordered mapping is maintained
😁 I'd made that error a few times lol - I thought the production explain stuff was ordered though? I'd suggest making the actual production explain result deterministic if it is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice change that helps with separation of concerns. I like that.
I was looking at the reference issue and I fail to understand how being able to assert only the node or the contents of the nodes or the full graph helps with the reason behind the issue. The only way to prevent having to change the explain test when doing changes would be to only use the node ordering match. The full graph or the node content tests would have to be changed. Does this mean that most of the time we will only want to test for node ordering and nothing else?
As for your questions:
1- In a separate PR is probably better since this is already quite large. Specially in case you come across conflicts
2- Not sure I understand the question. Are you saying the OccurrencesToSkip
doesn't work at the moment? From what I can tell, the skip feature you've implemented skips to a child and not to a sibling so the map ordering doesn't apply here. Can you give more details so I can understand better? :)
@@ -27,6 +27,8 @@ import ( | |||
ds "github.com/ipfs/go-datastore" | |||
"github.com/stretchr/testify/assert" | |||
|
|||
"github.com/sourcenetwork/immutable" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: Simply to follow a common approach, I'm wondering if we should join this with the block of external packages (as I did when integrating it) or should external sourcenetwork
packages have their own block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any preference, but this seems too tedious to track long-term without a lint rule.
- Will do for now
switch r := actualResult.(type) { | ||
case map[string]any: | ||
for key, value := range r { | ||
if isPlanNode(key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Since there is nothing after the if
, I suggest you make it more obvious that if it's not a plan node, we just go to the next result
if !isPlanNode(key) {
continue
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a personal preference thing. IMO is simpler and easier to follow the flow without a continue
label. Leaving as is.
actualResults []map[string]any, | ||
) { | ||
for _, actualResult := range actualResults { | ||
foundActualTarget, _, isFound := findTargetNode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Rename to foundTarget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever it comes to asserting tests, the most prominent terms I have seen being used to compare results are Expect
vs Actual
.
- The word 'Actual' signals to me that this is the result that is returned in reality.
- The word 'Expect' signals to me that this is an assumed result.
The term Result
or Target
alone IMO can be ambiguous and can mean either expected or actual results. If writing better names like these can help another developer (or myself in the future) to quickly distinguish which is which, I think it is worth the long name.
Leaving all suggestions of renaming by removal of the word Actual
as is.
f0cd96f
to
35d61a7
Compare
For example: - Fail if given an empty request for a non-transactional test. One additional thing I crammed into this commit was to handle a list of map to also be copied while copying a map.
35d61a7
to
eb51055
Compare
Also changes the example tests to ensure the order works, and sort the keys in sorted order of map (for more visual clarity).
The moment you have I do agree though, that these should be deterministic, but my hunch is this is not going to be a clean solution to do in go. So for my problem: |
I like that solution :) |
There were a few problems with the current setup:
Why we need
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Overall a very nice improvement. Good job :) |
) - Resolves sourcenetwork#521 - Description: This PR adds the testing setup for the `explain` feature to be more flexible and easier to manage going forward. This new setup will handle all explain types: `simple`, `debug`, `execute`, `predict`. The PR introduces three different types of test cases for asserting the results from an `explain` request. These can be asserted in one test case or smaller separate cases: 1) Being able to assert full explain graph or just quickly see the full graph to debug (like before). 2) Only matching the plan node ordering. 3) Targeting specific attributes only (option to also select their children nodes, or just it's attributes)
Relevant issue(s)
Resolves #521
Blocks #948 and #326
Description
This PR adds the testing setup for the
explain
feature to be more flexible and easier to manage going forward.This new setup will handle all explain types:
simple
,debug
,execute
,predict
The PR introduces three different types of test cases for asserting the results from an
explain
request. These can be asserted in one test case or smaller separate cases:For Reviewers
As this is a large PR here are some tips for reviewers.
Would strongly suggest reviewing commit by commit
The main commits to review would be these commits (in this order):
This commit contains concrete example tests that are all passing (for demonstration purposes):
Need help deciding:
Should the conversion of old to new tests happen in this same PR or separately? Would prefer separate. If separate I would like to leave the example tests in as the are already asserting the functionality, and drop these in the next PR ones all explain tests are converted.Resolved: Will do the conversion in next PR, will keep the tests and not drop the commit that was to be dropped.
TheExpectedTarget
functionality was implemented assuming ordered mapping is maintained (I blame it on my C++ past haha), but since go's maps are random ordered, theOccurancesToSkip
feature that helped select a target without a path order would need a rethink (perhaps conversion to sorted keys, i.e. ordered map for target matching).Resolved: I did a trick here, rather than traversing the map normally (which will make no guarantees on the ordering, i.e. random), I collected all the keys of the map and sorted them, then traversed and asserted the map in that sorted order.
Note: This deterministic assertion case is only important for the
ExpectedTargets
as we need it to consistently find the exact target whose attributes we want to assert.Tasks
How has this been tested?
Locally and CI
Specify the platform(s) on which this was tested: