-
Notifications
You must be signed in to change notification settings - Fork 889
fix: add timeouts to test telemetry snapshot #17879
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
coderd/telemetry/telemetry_test.go
Outdated
select { | ||
case <-ctx.Done(): | ||
t.Fatal("timed out sending deployment") | ||
case deployment <- dd: | ||
} |
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.
Have a look at testutil.RequireReceive
; that provides a nice abstraction over this pattern.
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 testutil.Require*
functions were not safe to use from helper goroutines, so I ended up creating 3 new helper functions.
39cbc5b
to
cc56091
Compare
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, with a non-blocking nit
// The second return value indicates whether the receive was successful. | ||
// | ||
// Safety: can be called from any goroutine. | ||
func AssertReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, 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.
Nit: could we abstract the logic and either use t.Fatal
or t.Error
in either case? That seems to be the only delta between the implementations.
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.
There's also the extra return value. I suppose we could create internal helper functions which would be called with a bool param by the Require/Assert variants. Not sure if it's worth it here - what do you think?
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.
Nah,
This PR ensures that waits on channels will time out according to the test context, rather than waiting indefinitely. This should alleviate the panic seen in coder/internal#645 and, if the deadlock recurs, allow the test to be retried automatically in CI.