Skip to content

Linter rule for using context.Background() without a timeout in tests #7304

@atollena

Description

@atollena

Use case(s) - what problem will this feature solve?

We want timeouts in every test, so anytime an operation needs a context (even during test setup), we want to avoid code using context.Background() or context.TODO() is needed there should be something like context.WithTimeout(context.Background(), defaultTestTimeout).

Proposed Solution

Add a linter rule that makes sure whenever we use context.Background() in test, it is using WithTimeout. Something like

git grep 'context.Background()' -- "*_test.go" | not grep -v 'context.WithTimeout(context.Background()'

Alternatives Considered

Do not lint this and continue relying on reviews to catch this.

Additional Context

Prompted by #7271 (comment)

Metadata

Metadata

Assignees

Labels

Area: ToolingIncludes anything related to Go builds, modules etc and includes Releases & Github Workflows.P2Type: Internal CleanupRefactors, etc

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions