Skip to content

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

Merged
merged 2 commits into from
May 22, 2025

Conversation

hugodutka
Copy link
Contributor

@hugodutka hugodutka commented May 16, 2025

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.

@hugodutka hugodutka marked this pull request as ready for review May 16, 2025 13:43
@hugodutka hugodutka requested a review from dannykopping May 16, 2025 13:43
Comment on lines 453 to 457
select {
case <-ctx.Done():
t.Fatal("timed out sending deployment")
case deployment <- dd:
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@hugodutka hugodutka force-pushed the hugodutka/test-telemetry-snapshot-timeout branch from 39cbc5b to cc56091 Compare May 22, 2025 11:06
Copy link
Contributor

@dannykopping dannykopping left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, :shipit:

@hugodutka hugodutka merged commit f825477 into main May 22, 2025
34 checks passed
@hugodutka hugodutka deleted the hugodutka/test-telemetry-snapshot-timeout branch May 22, 2025 11:51
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants