Skip to content

Commit 9747218

Browse files
committed
try immediate cleanup
1 parent 9658154 commit 9747218

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

framework/components/blockchain/blockchain.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package blockchain
22

33
import (
44
"fmt"
5+
"testing"
6+
57
"github.com/testcontainers/testcontainers-go"
68
)
79

@@ -26,6 +28,9 @@ type Input struct {
2628
// a map of program name to program id
2729
// there needs to be a matching .so file in contracts_dir
2830
SolanaPrograms map[string]string `toml:"solana_programs"`
31+
32+
// used to cancel container contexts
33+
T *testing.T `toml:"testing"`
2934
}
3035

3136
// Output is a blockchain network output, ChainID and one or more nodes that forms the network

framework/components/blockchain/solana.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func newSolana(in *Input) (*Output, error) {
131131
ContainerRequest: req,
132132
Started: true,
133133
})
134+
// Call cleanup container indiscriminately
135+
// This should be called as a defer directly after (before any error check)
136+
// of [GenericContainer](...) or a modules Run(...) in a test to ensure the
137+
// container is stopped when the function ends.
138+
if in.T != nil {
139+
testcontainers.CleanupContainer(in.T, c)
140+
}
134141
if err != nil {
135142
return nil, err
136143
}

0 commit comments

Comments
 (0)