Skip to content

Commit

Permalink
allow to define a custom cleanup function, when building docker teste…
Browse files Browse the repository at this point in the history
…nv + do not use any default cleanup (#10980)
  • Loading branch information
Tofel authored Oct 20, 2023
1 parent bdec2c1 commit 19866f2
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 6 deletions.
45 changes: 40 additions & 5 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +44,8 @@ type CLTestEnvBuilder struct {
t *testing.T
te *CLClusterTestEnv
isNonEVM bool
cleanUpType CleanUpType
cleanUpCustomFn func()

/* funding */
ETHFunds *big.Float
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/smoke/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kelseyhightower/envconfig"
"math/big"
"net/http"
"os"
"strconv"
"testing"
"time"

"github.com/kelseyhightower/envconfig"

"github.com/ethereum/go-ethereum/common"
"github.com/onsi/gomega"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestCronBasic(t *testing.T) {
WithGeth().
WithMockAdapter().
WithCLNodes(1).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/flux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestFluxBasic(t *testing.T) {
WithGeth().
WithMockAdapter().
WithCLNodes(3).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/forwarder_ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestForwarderOCRBasic(t *testing.T) {
WithForwarders().
WithCLNodes(6).
WithFunding(big.NewFloat(.1)).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/forwarders_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestForwarderOCR2Basic(t *testing.T) {
WithForwarders().
WithCLNodes(6).
WithFunding(big.NewFloat(.1)).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestOCRv2Basic(t *testing.T) {
)).
WithCLNodes(6).
WithFunding(big.NewFloat(.1)).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestOCRBasic(t *testing.T) {
WithMockAdapter().
WithCLNodes(6).
WithFunding(big.NewFloat(.1)).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/runlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestRunLogBasic(t *testing.T) {
WithMockAdapter().
WithCLNodes(1).
WithFunding(big.NewFloat(.1)).
WithStandardCleanup().
Build()
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions integration-tests/smoke/vrfv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestVRFv2Basic(t *testing.T) {
WithGeth().
WithCLNodes(1).
WithFunding(vrfConst.ChainlinkNodeFundingAmountEth).
WithStandardCleanup().
Build()
require.NoError(t, err)
env.ParallelTransactions(true)
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/smoke/vrfv2plus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19866f2

Please sign in to comment.