-
Notifications
You must be signed in to change notification settings - Fork 111
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
[RSDK-782] Flaky tests: TestSingleOperationManager in operation manager test go #1610
[RSDK-782] Flaky tests: TestSingleOperationManager in operation manager test go #1610
Conversation
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 like the way you split up the tests! Lots of tiny tests that do one thing each are easier to deal with than a single big test that does lots of things.
operation/manager_test.go
Outdated
@@ -105,44 +129,65 @@ func TestSingleOperationManager(t *testing.T) { | |||
<-c | |||
|
|||
som.CancelRunning(ctx) | |||
test.That(t, ctx.Err(), test.ShouldNotBeNil) | |||
if ctx.Err() == nil { | |||
t.Skip("skipping test since context was not cancelled, no race condition started") |
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.
Not sure how to reconcile som.CancelRunning(ctx)
with "context was not cancelled." Are you sure about this? I had expected the flaky test to be fixed by waiting for the SOM to finish cancelling the thing before asserting that it was cancelled, but it kinda looks like we continue to have a race condition and are just ignoring the times when the wrong thing wins the race. but maybe I've misunderstood what's going on here?
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.
removed.
operation/manager_test.go
Outdated
ctx := context.Background() | ||
som := SingleOperationManager{} | ||
var ( | ||
ctx = context.Background() |
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 context should be within tests. it's better practice to not have these two globals
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.
Okay, I'll move them back. Why is is better practice not to have them global?
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.
Expanding the answer I gave below: if they're global and reused in lots of tests, a failure in test A can leave it in a bad state, causing a failure in test B. and now you're stuck trying to figure out what's wrong with test B, and the answer is nothing at all, that the state was corrupted by test A, and it's really hard to figure that out because B is one of the tests that's failing so surely there's something wrong with B.
By not reusing state between tests, you keep them independent of each other so that the failures are limited to the tests that actually have problems.
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.
so context is probably fine as a global since it's immutable but context in general is to be used on a request by request basis (it's request/api context)
op manager is very dangerous as global because of what Alan mentioned, shared state
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 feel like my previous comments led you astray; I'm sorry about that. 😞
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
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!
@@ -176,5 +187,5 @@ func (m *mock) stopFail(ctx context.Context, extra map[string]interface{}) error | |||
} | |||
|
|||
func (m *mock) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, float64, error) { | |||
return false, 0, nil | |||
return true, 1, nil |
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.
One more time: you're sure this line needed changing? I don't see a call to IsPowered
anywhere in this file. which doesn't mean it's not used, just that it's hard for me to see that.
…2-flaky-test-test-single-operation-manager-in-operation-manager-test-go
|
Testing out with 10000 counts on my machine right now. Feel free to ask me to recombine tests, separated them out in a pretty mindless way.