-
Notifications
You must be signed in to change notification settings - Fork 201
ai/live: Use synctest in discovery #3739
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
Conversation
a1ec486
to
d8f25d8
Compare
Rebased onto latest master to fix merge conflicts, no other changes |
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.
nice 👍
discovery/discovery_test.go
Outdated
assert.Nil(err, "Should not be error") | ||
assert.Len(infos, 1, "Should return one orchestrator") | ||
assert.Equal("transcoderfromtestserver", infos[0].RemoteInfo.Transcoder) | ||
wgWait(&wg) |
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.
do we need to check the returned bool?
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.
good idea, checked in a6110ec
first := true | ||
serverGetOrchInfo = func(ctx context.Context, bcast common.Broadcaster, orchestratorServer *url.URL, params server.GetOrchestratorInfoParams) (*net.OrchestratorInfo, error) { | ||
mu.Lock() | ||
if first { |
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.
why were we pausing on the first request, don't really understand 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.
me neither - best guess is some early test needed it or had a race condition (probably the deadlock one), and it got copied everywhere else.
I double checked the rest of these tests and seems that I mistakenly removed the sleep from the deadlock test; that apparently was meant to drop one of the orchs so it wouldn't pass discovery. Re-added it, hopefully with a little better explanation in a6110ec (I still have no idea how this could have caused a deadlock though.)
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 synctest is really neat!
The golang 1.25 update turned out into something of an ordeal, so splitting it up from #3739 to allow for better review. While everything compiled in 1.25, some tests and CI steps broke. * Go lint needed to be updated to v2+ to support golang 1.25 * Bumping go vet from v1 to v2 entailed a bunch of CLI changes. Tried to make those 1-to-1 as much as possible, however: Go fmt now needs to be invoked separately for golint. We check go fmt in the CI step right before lint ... so just remove the go fmt step? The revive linter flagged a ton of missing comments. But it seems the linter only applies to the `pm` and `verification` packages which hardly change. Rather than update those packages, remove the use of the `revive` linter. * Some linting step (not sure which one? vet?) now complains about format string functions being used incorrectly, eg using a variable in place of a format string literal. Those were fixed in the code. * The `rand.Seed` function apparently became a no-op as of golang 1.24 and that broke most of our tests that use the RNG. Removed the init() function that sets the seed, and added a package level RNG context (using the same seed as the old init) and updated any failing tests to use that context. Not all uses of the RNG were updated, just ones that broke tests. The global RNG is safely initialized so we can continue to use it by default in the code that still uses it without test coverage.
f3310ea
to
424ddbc
Compare
The new synctest package, introduced in golang 1.25, makes tests much faster and more reliable. All the discovery tests that took more than 100ms on my machine were converted to use synctest. This surfaced a number of race conditions in both the tests and the code itself so these were also fixed. Timings with `go test -timeout 10s -count 1 -race` Before: ok github.com/livepeer/go-livepeer/discovery 7.087s After: ok github.com/livepeer/go-livepeer/discovery 0.817s Since syncest depends on a nested call similar to a sub-test, I opted to just rename the top level test function in the interests of not having to re-indent the entire file, or having yet another level of indentation around the file.
424ddbc
to
b6015f2
Compare
Since the update for golang 1.25 became more involved than I was expecting, separated that out in its own PR in #3745 so this one has just the synctest changes. Once that goes in, this one will go in too. |
The golang 1.25 update turned out into something of an ordeal, so splitting it up from #3739 to allow for better review. While everything compiled in 1.25, some tests and CI steps broke. * Go lint needed to be updated to v2+ to support golang 1.25 * Bumping go vet from v1 to v2 entailed a bunch of CLI changes. Tried to make those 1-to-1 as much as possible, however: Go fmt now needs to be invoked separately for golint. We check go fmt in the CI step right before lint ... so just remove the go fmt step? The revive linter flagged a ton of missing comments. But it seems the linter only applies to the `pm` and `verification` packages which hardly change. Rather than update those packages, remove the use of the `revive` linter. * Some linting step (not sure which one? vet?) now complains about format string functions being used incorrectly, eg using a variable in place of a format string literal. Those were fixed in the code. * The `rand.Seed` function apparently became a no-op as of golang 1.24 and that broke most of our tests that use the RNG. Removed the init() function that sets the seed, and added a package level RNG context (using the same seed as the old init) and updated any failing tests to use that context. Not all uses of the RNG were updated, just ones that broke tests. The global RNG is safely initialized so we can continue to use it by default in the code that still uses it without test coverage. * Fix race condition in discovery uncovered by golang 1.25
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3739 +/- ##
===================================================
- Coverage 31.14906% 31.14775% -0.00131%
===================================================
Files 158 158
Lines 47552 47554 +2
===================================================
Hits 14812 14812
- Misses 31852 31854 +2
Partials 888 888
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
The new synctest package, introduced in golang 1.25, makes tests involving time and concurrency much faster and more reliable. All the discovery tests that took more than 100ms on my machine were converted to use synctest.
This surfaced a number of race conditions in both the tests and the code itself so these were also fixed.
Timings with
go test -timeout 10s -count 1 -race
Before:
ok github.com/livepeer/go-livepeer/discovery 7.087s
After:
ok github.com/livepeer/go-livepeer/discovery 0.817s
Since syncest depends on a nested call similar to a sub-test, I opted to just rename the top level test function in the interests of not having to re-indent the entire file, or having yet another level of indentation around the file.