Skip to content
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

E2E tests (run in CI) are not cleaning up server and project artifacts #343

Open
displague opened this issue Sep 6, 2023 · 4 comments · Fixed by #405
Open

E2E tests (run in CI) are not cleaning up server and project artifacts #343

displague opened this issue Sep 6, 2023 · 4 comments · Fixed by #405
Labels
bug Something isn't working

Comments

@displague
Copy link
Member

What happened?

Servers created through E2E testing are not being deleted after the tests complete.

The project name is the same in each test so it is difficult to say which test triggered the project (and to identify if the devices were orphaned as a result of a failed run).

It is possible that an attempt was made to delete the servers and this failed (on the API side). This would block the deletion of the project.

How can we reproduce it?

Ensure that deletion is always carried out on the servers in the project and the project.

Create test servers with a deletion value so that they are automatically reaped.

CLI version (metal --version):

@displague displague added the bug Something isn't working label Sep 6, 2023
@aayushrangwala
Copy link
Contributor

Additionally:

  • Each project, device or any resource should have a random generated uuid append ex: metal-cli-project-xxxxx
  • Need to add t.Helper() in each test helper in helper.go
  • Use t.Cleanup() for declaring the cleanups of the resources created. Suggested here chore: Migrate gateways command from packngo to metal-go client #376 (comment)
  • Each resource created, should have a cleanup method called in the test

@aayushrangwala
Copy link
Contributor

/assign @aayushrangwala

@ctreatma
Copy link
Contributor

E2E test runs are still leaving resources behind, even after #405 was merged (and it should be noted that they're also taking far longer to complete).

displague added a commit that referenced this issue Dec 20, 2023
A recent refactor of the test code introduced persistent timeouts, even
in tests that do not perform API-intensive tasks (for example, read-only
tests that request capacity information).

These timeouts were happening because the tests temporarily replace
stdout with a byte buffer in order to capture command output for
validation; during the most recent refactor, the code that closes the
byte buffer and restores stdout was moved to a `t.Cleanup` handler, so
the buffer was not closed until after the test finished, causing the
test to hang until it timed out.

This moves the stdout-juggling code into a helper function to ensure
that we are using the same logic across all tests. The helper function
logs any errors that happen while closing or reading the byte buffer,
but does not fail the test for those errors; the tests themselves should
fail if those errors impact the behavior under test.

Fixes #416.  Related to #343.

In addition, existing test helpers are refactored to more easily ensure
that resources created with test helpers are automatically cleaned up
after a test runs and to ensure that tests fail early if a test resource
could not be created. Test helpers for deleting resources now log the ID
of the resource they are trying to delete so we can more easily triage
issues with test cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants