From 19866f253bb6da4c2e47ab302f0fc95cb102ced3 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Fri, 20 Oct 2023 11:48:03 +0200 Subject: [PATCH] allow to define a custom cleanup function, when building docker testenv + do not use any default cleanup (#10980) --- .../docker/test_env/test_env_builder.go | 45 ++++++++++++++++--- integration-tests/smoke/automation_test.go | 5 ++- integration-tests/smoke/cron_test.go | 1 + integration-tests/smoke/flux_test.go | 1 + integration-tests/smoke/forwarder_ocr_test.go | 1 + .../smoke/forwarders_ocr2_test.go | 1 + integration-tests/smoke/keeper_test.go | 1 + integration-tests/smoke/ocr2_test.go | 1 + integration-tests/smoke/ocr_test.go | 1 + integration-tests/smoke/runlog_test.go | 1 + integration-tests/smoke/vrf_test.go | 1 + integration-tests/smoke/vrfv2_test.go | 1 + integration-tests/smoke/vrfv2plus_test.go | 2 + 13 files changed, 56 insertions(+), 6 deletions(-) diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index cdae5a9d72b..072728321bf 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -21,6 +21,14 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" ) +type CleanUpType string + +const ( + CleanUpTypeNone CleanUpType = "none" + CleanUpTypeStandard CleanUpType = "standard" + CleanUpTypeCustom CleanUpType = "custom" +) + type CLTestEnvBuilder struct { hasLogWatch bool hasGeth bool @@ -36,6 +44,8 @@ type CLTestEnvBuilder struct { t *testing.T te *CLClusterTestEnv isNonEVM bool + cleanUpType CleanUpType + cleanUpCustomFn func() /* funding */ ETHFunds *big.Float @@ -136,6 +146,22 @@ func (b *CLTestEnvBuilder) WithNonEVM() *CLTestEnvBuilder { return b } +func (b *CLTestEnvBuilder) WithStandardCleanup() *CLTestEnvBuilder { + b.cleanUpType = CleanUpTypeStandard + return b +} + +func (b *CLTestEnvBuilder) WithoutCleanup() *CLTestEnvBuilder { + b.cleanUpType = CleanUpTypeNone + return b +} + +func (b *CLTestEnvBuilder) WithCustomCleanup(customFn func()) *CLTestEnvBuilder { + b.cleanUpType = CleanUpTypeCustom + b.cleanUpCustomFn = customFn + return b +} + func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { if b.te == nil { var err error @@ -171,11 +197,20 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { } } - b.t.Cleanup(func() { - if err := b.te.Cleanup(); err != nil { - b.l.Error().Err(err).Msg("Error cleaning up test environment") - } - }) + switch b.cleanUpType { + case CleanUpTypeStandard: + b.t.Cleanup(func() { + if err := b.te.Cleanup(); err != nil { + b.l.Error().Err(err).Msg("Error cleaning up test environment") + } + }) + case CleanUpTypeCustom: + b.t.Cleanup(b.cleanUpCustomFn) + case CleanUpTypeNone: + b.l.Warn().Msg("test environment won't be cleaned up") + case "": + return b.te, errors.WithMessage(errors.New("explicit cleanup type must be set when building test environment"), "test environment builder failed") + } if b.nonDevGethNetworks != nil { b.te.WithPrivateChain(b.nonDevGethNetworks) diff --git a/integration-tests/smoke/automation_test.go b/integration-tests/smoke/automation_test.go index 001d5f22766..b565d02f423 100644 --- a/integration-tests/smoke/automation_test.go +++ b/integration-tests/smoke/automation_test.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/kelseyhightower/envconfig" "math/big" "net/http" "os" @@ -12,6 +11,8 @@ import ( "testing" "time" + "github.com/kelseyhightower/envconfig" + "github.com/ethereum/go-ethereum/common" "github.com/onsi/gomega" "github.com/stretchr/testify/require" @@ -1054,6 +1055,7 @@ func setupAutomationTestDocker( WithGeth(). WithMockAdapter(). WithFunding(big.NewFloat(testConfig.ChainlinkNodeFunding)). + WithStandardCleanup(). Build() require.NoError(t, err, "Error deploying test environment for Mercury") env.ParallelTransactions(true) @@ -1099,6 +1101,7 @@ func setupAutomationTestDocker( WithCLNodes(clNodesCount). WithCLNodeConfig(clNodeConfig). WithFunding(big.NewFloat(testConfig.ChainlinkNodeFunding)). + WithStandardCleanup(). Build() require.NoError(t, err, "Error deploying test environment") } diff --git a/integration-tests/smoke/cron_test.go b/integration-tests/smoke/cron_test.go index 0da9d6461ca..e9d20f588e2 100644 --- a/integration-tests/smoke/cron_test.go +++ b/integration-tests/smoke/cron_test.go @@ -24,6 +24,7 @@ func TestCronBasic(t *testing.T) { WithGeth(). WithMockAdapter(). WithCLNodes(1). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/flux_test.go b/integration-tests/smoke/flux_test.go index a9a9e848111..8c2b3638bff 100644 --- a/integration-tests/smoke/flux_test.go +++ b/integration-tests/smoke/flux_test.go @@ -30,6 +30,7 @@ func TestFluxBasic(t *testing.T) { WithGeth(). WithMockAdapter(). WithCLNodes(3). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/forwarder_ocr_test.go b/integration-tests/smoke/forwarder_ocr_test.go index 705ae7cd1a6..727b83a601a 100644 --- a/integration-tests/smoke/forwarder_ocr_test.go +++ b/integration-tests/smoke/forwarder_ocr_test.go @@ -25,6 +25,7 @@ func TestForwarderOCRBasic(t *testing.T) { WithForwarders(). WithCLNodes(6). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/forwarders_ocr2_test.go b/integration-tests/smoke/forwarders_ocr2_test.go index be26fd6213b..baa5a781f6b 100644 --- a/integration-tests/smoke/forwarders_ocr2_test.go +++ b/integration-tests/smoke/forwarders_ocr2_test.go @@ -34,6 +34,7 @@ func TestForwarderOCR2Basic(t *testing.T) { WithForwarders(). WithCLNodes(6). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/keeper_test.go b/integration-tests/smoke/keeper_test.go index 4f1a4fde143..21dbeb8753c 100644 --- a/integration-tests/smoke/keeper_test.go +++ b/integration-tests/smoke/keeper_test.go @@ -1112,6 +1112,7 @@ func setupKeeperTest(t *testing.T) ( WithCLNodes(5). WithCLNodeConfig(clNodeConfig). WithFunding(big.NewFloat(.5)). + WithStandardCleanup(). Build() require.NoError(t, err, "Error deploying test environment") diff --git a/integration-tests/smoke/ocr2_test.go b/integration-tests/smoke/ocr2_test.go index e32d86bef82..75f308aee17 100644 --- a/integration-tests/smoke/ocr2_test.go +++ b/integration-tests/smoke/ocr2_test.go @@ -42,6 +42,7 @@ func TestOCRv2Basic(t *testing.T) { )). WithCLNodes(6). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/ocr_test.go b/integration-tests/smoke/ocr_test.go index cba5935cd01..8d71c5d08f8 100644 --- a/integration-tests/smoke/ocr_test.go +++ b/integration-tests/smoke/ocr_test.go @@ -23,6 +23,7 @@ func TestOCRBasic(t *testing.T) { WithMockAdapter(). WithCLNodes(6). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/runlog_test.go b/integration-tests/smoke/runlog_test.go index 99d3a4f6c27..f29cb4bc893 100644 --- a/integration-tests/smoke/runlog_test.go +++ b/integration-tests/smoke/runlog_test.go @@ -28,6 +28,7 @@ func TestRunLogBasic(t *testing.T) { WithMockAdapter(). WithCLNodes(1). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) diff --git a/integration-tests/smoke/vrf_test.go b/integration-tests/smoke/vrf_test.go index ba7e2f17a4a..444d1ce20ee 100644 --- a/integration-tests/smoke/vrf_test.go +++ b/integration-tests/smoke/vrf_test.go @@ -28,6 +28,7 @@ func TestVRFBasic(t *testing.T) { WithGeth(). WithCLNodes(1). WithFunding(big.NewFloat(.1)). + WithStandardCleanup(). Build() require.NoError(t, err) env.ParallelTransactions(true) diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 8d3868f8510..c960bb6c691 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -27,6 +27,7 @@ func TestVRFv2Basic(t *testing.T) { WithGeth(). WithCLNodes(1). WithFunding(vrfConst.ChainlinkNodeFundingAmountEth). + WithStandardCleanup(). Build() require.NoError(t, err) env.ParallelTransactions(true) diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index bb363ed2eb4..b9854d59ad6 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -34,6 +34,7 @@ func TestVRFv2Plus(t *testing.T) { WithGeth(). WithCLNodes(1). WithFunding(big.NewFloat(vrfv2PlusConfig.ChainlinkNodeFunding)). + WithStandardCleanup(). Build() require.NoError(t, err, "error creating test env") @@ -255,6 +256,7 @@ func TestVRFv2PlusMigration(t *testing.T) { WithGeth(). WithCLNodes(1). WithFunding(big.NewFloat(vrfv2PlusConfig.ChainlinkNodeFunding)). + WithStandardCleanup(). Build() require.NoError(t, err, "error creating test env") env.ParallelTransactions(true)