Skip to content

Commit 21b742c

Browse files
committed
fixup: Add panic recovery to load2
1 parent 95b5937 commit 21b742c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

tests/load2/generator.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"golang.org/x/sync/errgroup"
1515

1616
"github.com/ava-labs/avalanchego/tests"
17+
"github.com/ava-labs/avalanchego/utils/logging"
1718
)
1819

1920
type Test interface {
@@ -61,8 +62,8 @@ func NewLoadGenerator(
6162
}
6263

6364
func (l LoadGenerator) Run(
64-
tc tests.TestContext,
6565
ctx context.Context,
66+
log logging.Logger,
6667
loadTimeout time.Duration,
6768
testTimeout time.Duration,
6869
) {
@@ -87,10 +88,18 @@ func (l LoadGenerator) Run(
8788
ctx, cancel := context.WithTimeout(ctx, testTimeout)
8889
defer cancel()
8990

90-
l.test.Run(tc, ctx, l.wallets[i])
91+
execTestWithRecovery(ctx, log, l.test, l.wallets[i])
9192
}
9293
})
9394
}
9495

9596
_ = eg.Wait()
9697
}
98+
99+
// execTestWithRecovery ensures assertion-related panics encountered during test execution are recovered
100+
// and that deferred cleanups are always executed before returning.
101+
func execTestWithRecovery(ctx context.Context, log logging.Logger, test Test, wallet *Wallet) {
102+
tc := tests.NewTestContext(log)
103+
defer tc.Recover()
104+
test.Run(tc, ctx, wallet)
105+
}

tests/load2/main/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func init() {
5050
func main() {
5151
log := tests.NewDefaultLogger("")
5252
tc := tests.NewTestContext(log)
53-
defer tc.Cleanup()
53+
defer tc.RecoverAndExit()
5454

5555
require := require.New(tc)
5656

@@ -116,5 +116,5 @@ func main() {
116116
)
117117
require.NoError(err)
118118

119-
generator.Run(tc, ctx, loadTimeout, testTimeout)
119+
generator.Run(ctx, log, loadTimeout, testTimeout)
120120
}

0 commit comments

Comments
 (0)