Skip to content

Commit

Permalink
fix clean up order (#13205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored May 15, 2024
1 parent 37805cd commit dbc971b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions integration-tests/docker/test_env/test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (te *CLClusterTestEnv) handleNodeCoverageReports(testName string) error {
if showHTMLCoverageReport || isCI {
// Stop all nodes in the chainlink cluster.
// This is needed to get go coverage profile from the node containers https://go.dev/doc/build-cover#FAQ
// TODO: fix this as it results in: ERR LOG AFTER TEST ENDED ... INF 🐳 Stopping container
err := te.ClCluster.Stop()
if err != nil {
return err
Expand Down
72 changes: 36 additions & 36 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/networks"
"github.com/smartcontractkit/chainlink-testing-framework/testreporters"
"github.com/smartcontractkit/chainlink-testing-framework/utils/osutil"

evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"

Expand Down Expand Up @@ -283,42 +282,8 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
if err != nil {
return nil, err
}
}

if b.hasKillgrave {
if b.te.DockerNetwork == nil {
return nil, fmt.Errorf("test environment builder failed: %w", fmt.Errorf("cannot start mock adapter without a network"))
}

b.te.MockAdapter = test_env.NewKillgrave([]string{b.te.DockerNetwork.Name}, "", test_env.WithLogStream(b.te.LogStream))

err = b.te.StartMockAdapter()
if err != nil {
return nil, err
}
}

if b.t != nil {
b.te.WithTestInstance(b.t)
}

switch b.cleanUpType {
case CleanUpTypeStandard:
b.t.Cleanup(func() {
// Cleanup test environment
if err := b.te.Cleanup(CleanupOpts{TestName: b.t.Name()}); 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, fmt.Errorf("test environment builder failed: %w", fmt.Errorf("explicit cleanup type must be set when building test environment"))
}

if b.te.LogStream != nil {
// this clean up has to be added as the FIRST one, because cleanup functions are executed in reverse order (LIFO)
if b.t != nil {
b.t.Cleanup(func() {
b.l.Info().Msg("Shutting down LogStream")
Expand Down Expand Up @@ -379,7 +344,42 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
}
})
}
}

if b.hasKillgrave {
if b.te.DockerNetwork == nil {
return nil, fmt.Errorf("test environment builder failed: %w", fmt.Errorf("cannot start mock adapter without a network"))
}

b.te.MockAdapter = test_env.NewKillgrave([]string{b.te.DockerNetwork.Name}, "", test_env.WithLogStream(b.te.LogStream))

err = b.te.StartMockAdapter()
if err != nil {
return nil, err
}
}

if b.t != nil {
b.te.WithTestInstance(b.t)
}

switch b.cleanUpType {
case CleanUpTypeStandard:
b.t.Cleanup(func() {
// Cleanup test environment
if err := b.te.Cleanup(CleanupOpts{TestName: b.t.Name()}); 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, fmt.Errorf("test environment builder failed: %w", fmt.Errorf("explicit cleanup type must be set when building test environment"))
}

if b.te.LogStream != nil {
// this is not the cleanest way to do this, but when we originally build ethereum networks, we don't have the logstream reference
// so we need to rebuild them here and pass logstream to them
for i := range b.privateEthereumNetworks {
Expand Down

0 comments on commit dbc971b

Please sign in to comment.