Skip to content

e2e: move per-test resource cleanup into bats teardown() #2583

Description

@myasnikovdaniil

Problem

E2E tests under hack/e2e-apps/*.bats perform resource cleanup inline at the
end of each @test body (e.g. kubectl delete vminstance ... after the wait
assertions). When an earlier kubectl wait or until step fails, the test
exits before reaching the delete lines, so resources leak into the cluster
and can pollute subsequent retries or unrelated app tests sharing the
tenant-test namespace.

Surfaced in #2555 (comment)
on hack/e2e-apps/vminstance.bats, but the same pattern exists in most
e2e-apps/*.bats files.

Proposal

Move resource deletion into a framework-level teardown() (bats hook that
always runs, even on test failure). Track created resource names in a
shell-array or temp file in setup()/test body, and have teardown()
iterate them with kubectl delete --ignore-not-found --timeout=....

Keep test bodies focused on create + assert; cleanup becomes guaranteed.

Scope

  • Audit all files under hack/e2e-apps/ for inline kubectl delete at
    end-of-test.
  • Introduce a shared cleanup helper (likely in hack/e2e-apps/ as a sourced
    .sh) that test files can register resources with.
  • Migrate each app's .bats file individually so churn is reviewable.

Out of scope

  • Changing the actual create/assert logic of any test.
  • Reworking cozytest.sh runner semantics.

Acceptance criteria

  • A failing kubectl wait in any e2e-apps/*.bats test still removes the
    resources it created before the next test runs.
  • No inline post-assertion kubectl delete calls remain in test bodies.

Activity

  1. added
    kind/cleanupCategorizes issue or PR as related to cleanup of code, process, or technical debt
    area/testingIssues or PRs related to testing (e2e, bats, unit tests)
    on Jun 4, 2026
  2. myasnikovdaniil commented on Aug 14, 2026

    @myasnikovdaniil
    ContributorAuthor

    Suite doesn't have that shape anymore. App tests moved to chainsaw in #2826, and hack/e2e-apps/ is down to two files where neither uses teardown(): cozytest.sh never invokes setup()/teardown(), so cleanup sits in cozy_cleanup() (monitoring-oidc-system.bats:46, monitoring-oidc-customconfig.bats:37) which runs at suite exit and on the first failing test.

    Those two files also have no invocation site in any Makefile, hack script or workflow. So there is no per-test cleanup left to move and no lane to move it in, closing. #3778 is the gate for the no-runner class, and #3453 decides whether these two get deleted or given a lane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/testingIssues or PRs related to testing (e2e, bats, unit tests)kind/cleanupCategorizes issue or PR as related to cleanup of code, process, or technical debtpriority/backlogGeneral backlog priority. Lower than priority/important-longtermtriage/acceptedIndicates an issue is ready to be actively worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions