Skip to content

fix: avoid sharing echo.Responses across tests #17211

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
Apr 2, 2025

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Apr 2, 2025

Closes coder/internal#551

We've noticed lots of flakes in go test -race tests that use the echo provisioner. I believe the root cause of this to be #17012, where we started mutating the echo.Responses. This only caused issues as we previously shared echo.Responses across multiple test cases.

This PR is therefore the same as #17128, but I believe this is all the cases where an echo.Responses is shared between tests - including tests that haven't flaked (yet).

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ethanndickson ethanndickson marked this pull request as ready for review April 2, 2025 01:47
@ethanndickson ethanndickson changed the title fix: avoid sharing echo.Responses across tests fix: avoid sharing echo.Responses across tests Apr 2, 2025
@ethanndickson ethanndickson requested review from sreya and Copilot April 2, 2025 01:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors test initialization for echo.Responses to eliminate shared mutable state between tests, addressing flakiness related to the echo provisioner.

  • Convert echo.Responses variables into factory functions that return new instances.
  • Update test cases to invoke these factories to avoid data sharing across test runs.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
cli/update_test.go Wrap echo.Responses initialization in a function and update its usages.
cli/start_test.go Replace direct echo.Responses assignment with a factory function invocation.
cli/restart_test.go Apply factory function pattern to create new echo.Responses instances.
Comments suppressed due to low confidence (4)

cli/update_test.go:104

  • [nitpick] Consider renaming 'echoResponses' to 'newEchoResponses' to clarify that it returns a fresh instance on each invocation.
echoResponses := func() *echo.Responses {

cli/start_test.go:82

  • [nitpick] Consider renaming 'echoResponses' to 'newEchoResponses' for clarity since it now functions as a factory method.
echoResponses := func() *echo.Responses {

cli/restart_test.go:23

  • [nitpick] Consider renaming 'echoResponses' to 'newEchoResponses' to better indicate that it creates a new instance each time it is called.
echoResponses := func() *echo.Responses {

cli/restart_test.go:285

  • [nitpick] Consider renaming 'echoResponses' to 'newEchoResponses' to clarify its role as a factory function for generating new instances.
echoResponses := func() *echo.Responses {

@ethanndickson
Copy link
Member Author

ethanndickson commented Apr 2, 2025

$ go test -race -count=50 -run "TestUpdateWithRichParameters" github.com/coder/coder/v2/cli
ok      github.com/coder/coder/v2/cli   58.317s

$ go test -race -count=50 -run "TestStart" github.com/coder/coder/v2/cli
ok      github.com/coder/coder/v2/cli   133.624s                                                                                                                                                                                                                         

Copy link
Collaborator

@sreya sreya left a comment

Choose a reason for hiding this comment

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

Many blessings upon your house 🙏

@ethanndickson ethanndickson merged commit 6fdad02 into main Apr 2, 2025
44 checks passed
@ethanndickson ethanndickson deleted the ethan/fix-echo-flakes branch April 2, 2025 02:06
@github-actions github-actions bot locked and limited conversation to collaborators Apr 2, 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.

flake: TestUpdateValidateRichParameters
2 participants