From bf9232e99f9ad2b5059924479da08ad703f37008 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Fri, 17 Sep 2021 04:35:49 -0400 Subject: [PATCH] e2e: cleanup on all errors if preserve not specified (#6950) If the e2e tests error, they leave all of the e2e state around including containers and networks etc. We should clean this up when the tests shuts down, even if it exits in error. --- test/e2e/runner/main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/e2e/runner/main.go b/test/e2e/runner/main.go index f65b6d0b1..8de182f3a 100644 --- a/test/e2e/runner/main.go +++ b/test/e2e/runner/main.go @@ -52,6 +52,13 @@ func NewCLI() *CLI { if err := Cleanup(cli.testnet); err != nil { return err } + defer func() { + if cli.preserve { + logger.Info("Preserving testnet contents because -preserve=true") + } else if err := Cleanup(cli.testnet); err != nil { + logger.Error("Error cleaning up testnet contents", "err", err) + } + }() if err := Setup(cli.testnet); err != nil { return err } @@ -103,11 +110,6 @@ func NewCLI() *CLI { if err := Test(cli.testnet); err != nil { return err } - if !cli.preserve { - if err := Cleanup(cli.testnet); err != nil { - return err - } - } return nil }, } @@ -269,6 +271,12 @@ Does not run any perbutations. if err := Cleanup(cli.testnet); err != nil { return err } + defer func() { + if err := Cleanup(cli.testnet); err != nil { + logger.Error("Error cleaning up testnet contents", "err", err) + } + }() + if err := Setup(cli.testnet); err != nil { return err } @@ -302,10 +310,6 @@ Does not run any perbutations. return err } - if err := Cleanup(cli.testnet); err != nil { - return err - } - return nil }, })