-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Issue #3349 - enable -shuffle=on
in tests
#3350
Conversation
b0a8b62
to
7f57003
Compare
Codecov Report
@@ Coverage Diff @@
## master #3350 +/- ##
=======================================
Coverage 96.47% 96.47%
=======================================
Files 259 259
Lines 15178 15178
=======================================
Hits 14643 14643
- Misses 451 452 +1
+ Partials 84 83 -1
Continue to review full report at Codecov.
|
One of the nice features of e.g.: go test -v -race -shuffle=on ./...
-test.shuffle 1635607575548663755 you can use the test shuffle to reproduce the issue: go test -v -race -shuffle=1635607575548663755 ./... |
85d6a01
to
e23af42
Compare
Generally I am not aware of inter-test dependencies, we always tried to keep tests independent. I see that TestAggregateThroughput is failing, which is a relatively recent test, some side-effect dependency might have sneaked in & we should fix it. |
Signed-off-by: rbroggi <ro_broggi@hotmail.com>
…ritten to) Signed-off-by: rbroggi <ro_broggi@hotmail.com>
e23af42
to
315e910
Compare
p := &Processor{} | ||
aggregatedThroughput := p.aggregateThroughput(testThroughputs) |
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.
It's very likely that this global variable is the source of the flakiness as it's not read-only
as it should therefore impacting also this case.
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 am a bit concerned by this approach. The input to p.aggregateThroughput
is supposed to be treated as read-only by that function. If it's not, that might be the bug / source of the test dependencies, not the fault of the test. The testThroughputs
is not a global variable, it's logically a constant. By using a function instead of the same value we simply obscure the bug elsewhere.
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.
Let me see if I understand your point:
since method p.aggregateThroughput
is supposed to treat its inputs as read-only
, you think that my approach could hide a potential bug in the p.aggregateThroughput
that could potentially mutate the input?
If this is what you mean I think my change is still valid because it's enforcing independence between tests. And what we could have is a specific test that tests for p.aggregateThroughput
immutability. Currently the thing that is actually mutating the content of the global variable is a test on its body (see in master TestRealisticRunCalculationLoop
in processor_test:445
)
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 have created the following test case and to your point it indeed fail (which means that the method is indeed mutating the arguments):
func TestAggregateThroughputInputsImmutability(t *testing.T) {
p := &Processor{}
in := testThroughputs()
_ = p.aggregateThroughput(in)
assert.Equal(t, in, testThroughputs())
}
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.
And if indeed it's supposed not to mutate the arguments the issue is exactly here:
plugin/sampling/strategystore/adaptive/processor.go:313
Pointer semantics 😋
Signed-off-by: rbroggi <ro_broggi@hotmail.com>
Found the source of the bug: global variable 😌 My approach in the test was to change all the global variables of the file to methods which return the same value, this way we cannot share state across tests (even in future developments) |
Update on this one:
Another intriguing thing is that the |
Signed-off-by: rbroggi <ro_broggi@hotmail.com>
) | ||
} | ||
|
||
func TestAggregateThroughputInputsImmutability(t *testing.T) { |
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.
if you run this test method on master
branch it will fail
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.
+1
Given that the CI still fails due to some other issues, do you want to merge this PR without the -shuffle=on
in the Makefile?
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 think it will profitable to keep the interesting commenting history therefore:
@@ -310,12 +310,26 @@ func (p *Processor) aggregateThroughput(throughputs []*model.Throughput) service | |||
t.Count += throughput.Count | |||
t.Probabilities = merge(t.Probabilities, throughput.Probabilities) | |||
} else { | |||
aggregatedThroughput[service][operation] = throughput |
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 probably a bug (unintended pointer copy makes so that the input argument throughputs
is changed during this method execution). Could you please @yurishkuro / @albertteoh confirm whether this method is supposed to be immutable on its arguments?
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.
bug hunted thanks to shuffle
😋
…able-test-shuffle
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. You may re-open it if you need more time. |
This pull request has been automatically closed due to inactivity. You may re-open it if you need more time. We really appreciate your contribution and we are sorry that this has not been completed. |
Which problem is this PR solving?
Short description of the changes
shuffling
in tests