Skip to content

test(agent): Improve use of inv.Context() #7696

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 26, 2023

Conversation

mafredri
Copy link
Member

This will ensure tests timeout instead of hang indefinitely since
inv.Context() is assigned a timeout by default.

This will ensure tests timeout instead of hang indefinitely since
`inv.Context()` is assigned a timeout by default.
@mafredri mafredri requested review from johnstcn and mtojek May 26, 2023 13:20
@mafredri mafredri enabled auto-merge (squash) May 26, 2023 13:29
require.NoError(t, err)
defer dialer.Close()
require.True(t, dialer.AwaitReachable(context.Background()))
Copy link
Member

Choose a reason for hiding this comment

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

I think that this is a second PR fixing context.Background(). I'm curious if there is a lint-way to prevent this dev mistake.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be unfortunate to ban context.Background() entirely since there are valid use-cases. But most of our tests should try to have a timeout so maybe? Ruleguard (scripts/rules.go) would probably be the place to put it, but it's a bit finicky to get right.

In theory, we have a lot of "debt" here:

❯ rg 'context\.Background\(\)' **/*_test.go | grep -E -v 'context\.With(Timeout|Deadline|Value)\(' | wc -l
451

@mafredri mafredri merged commit 66f5d39 into main May 26, 2023
@mafredri mafredri deleted the mafredri/test-agent-use-inv-context branch May 26, 2023 13:48
@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2023
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.

3 participants