-
Notifications
You must be signed in to change notification settings - Fork 800
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
Concurrency primitives need concurrent tests #6274
Conversation
Honestly I think it's shocking that this was ever approved. The good news though is that it does seem to work. I also took the opportunity to remove the wildly unnecessary test suite use.
lock.Unlock() | ||
} | ||
|
||
func BenchmarkLock(b *testing.B) { | ||
l := NewMutex() | ||
ctx := context.Background() | ||
for n := 0; n < b.N; n++ { | ||
l.Lock(ctx) //nolint:errcheck | ||
l.Unlock() //nolint:staticcheck | ||
_ = l.Lock(ctx) |
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.
The lockInternal
could be optimized by keeping an internal state in an atomic variable. When there's noone holding the lock (state=0) it can be a lightweight operation bypassing the goroutine + channel wait.
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.
yea, I've got a different PR for making changes. this is just setting groundwork for "verify that this thing actually works"
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted filessee 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Spotted while looking into other racy code.
Honestly I think it's shocking that this was ever approved.
The good news though is that it does seem to work.
I also took the opportunity to remove the wildly unnecessary testify/suite, and add some comparative benchmarks:
At the moment I'm not sure if this is an acceptable cost or not tbh (though it feels like "no").