Fix flaky 'TestAggregateTopByFunction` #847
Merged
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.
This sorts the list by the meta location address, so the flaky
TestAggregateTopByFunction
passes every time. (#770)I ran the test multiple times without any changes, and encountered 2 types of failures:
UniqueFunction
andUniqueAddress
.Logs for failing `UniqueFunction` test
Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestAggregateTopByFunction$ github.com/parca-dev/parca/pkg/query
--- FAIL: TestAggregateTopByFunction (0.00s)
--- FAIL: TestAggregateTopByFunction/UniqueFunction (0.00s)
/home/ujjwal/oss/parca-dev/parca/pkg/query/top_test.go:300:
Error Trace: top_test.go:300
Error: Not equal:
expected: &queryv1alpha1.Top{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(nil)}, sizeCache:0, unknownFields:[]uint8(nil), List:[]*queryv1alpha1.TopNode{(*queryv1alpha1.TopNode)(0xc00012a280), (*queryv1alpha1.TopNode)(0xc00012a2c0)}, Reported:2, Total:2, Unit:""}
actual : &queryv1alpha1.Top{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(nil)}, sizeCache:0, unknownFields:[]uint8(nil), List:[]*queryv1alpha1.TopNode{(*queryv1alpha1.TopNode)(0xc00012a240), (*queryv1alpha1.TopNode)(0xc00012a200)}, Reported:2, Total:2, Unit:""}
FAIL
FAIL github.com/parca-dev/parca/pkg/query 0.008s
FAIL
Logs for failing `UniqueAddress` test
Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestAggregateTopByFunction$ github.com/parca-dev/parca/pkg/query
--- FAIL: TestAggregateTopByFunction (0.00s)
--- FAIL: TestAggregateTopByFunction/UniqueAddress (0.00s)
/home/ujjwal/oss/parca-dev/parca/pkg/query/top_test.go:300:
Error Trace: top_test.go:300
Error: Not equal:
expected: &queryv1alpha1.Top{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(nil)}, sizeCache:0, unknownFields:[]uint8(nil), List:[]*queryv1alpha1.TopNode{(*queryv1alpha1.TopNode)(0xc0004b6180), (*queryv1alpha1.TopNode)(0xc0004b61c0)}, Reported:2, Total:2, Unit:""}
actual : &queryv1alpha1.Top{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(nil)}, sizeCache:0, unknownFields:[]uint8(nil), List:[]*queryv1alpha1.TopNode{(*queryv1alpha1.TopNode)(0xc0004b6140), (*queryv1alpha1.TopNode)(0xc0004b6100)}, Reported:2, Total:2, Unit:""}
FAIL
FAIL github.com/parca-dev/parca/pkg/query 0.008s
FAIL
As had been suggested in the comments of the issue, I first sorted by
Flat
value for eachTopNode
in theList
, but eventually I encountered the errors. I then added a second sort condition to sort based on the meta location address, as follows:I ran the
TestAggregateTopByFunction
about 20 times (clearing testcache for each run) to ensure this worked. I didn't encounter any errors, and I decided to try only sorting by the address (the current code). I ran it 20 times again, and still didn't find any errors.If this is only required for tests, we could add the sorting to only the test instead of changing the function. If the sorting is required for regular usage as well, however, I would suggest that we use a more detailed sort:
Please let me know which approach to take.