Skip to content

Commit

Permalink
try immediate cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-cll committed Jan 13, 2025
1 parent 9658154 commit 9747218
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions framework/components/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package blockchain

import (
"fmt"
"testing"

"github.com/testcontainers/testcontainers-go"
)

Expand All @@ -26,6 +28,9 @@ type Input struct {
// a map of program name to program id
// there needs to be a matching .so file in contracts_dir
SolanaPrograms map[string]string `toml:"solana_programs"`

// used to cancel container contexts
T *testing.T `toml:"testing"`
}

// Output is a blockchain network output, ChainID and one or more nodes that forms the network
Expand Down
7 changes: 7 additions & 0 deletions framework/components/blockchain/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func newSolana(in *Input) (*Output, error) {
ContainerRequest: req,
Started: true,
})
// Call cleanup container indiscriminately
// This should be called as a defer directly after (before any error check)
// of [GenericContainer](...) or a modules Run(...) in a test to ensure the
// container is stopped when the function ends.
if in.T != nil {
testcontainers.CleanupContainer(in.T, c)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9747218

Please sign in to comment.