Skip to content

Commit 95b5937

Browse files
committed
fixup: Add RecoverAndRethrow as per review feedback
1 parent 9052d5f commit 95b5937

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

tests/antithesis/avalanchego/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (w *workload) run(ctx context.Context) {
170170
tc := w.newTestContext(ctx)
171171
// Any assertion failure from this test context will result in process exit due to the
172172
// panic being rethrown. This ensures that failures in test setup are fatal.
173-
defer tc.Recover(true /* rethrow */)
173+
defer tc.RecoverAndRethrow()
174174

175175
xAVAX, pAVAX := e2e.GetWalletBalances(tc, w.wallet)
176176
assert.Reachable("wallet starting", map[string]any{
@@ -215,7 +215,7 @@ func (w *workload) run(ctx context.Context) {
215215
func (w *workload) executeTest(ctx context.Context) {
216216
tc := w.newTestContext(ctx)
217217
// Panics will be recovered without being rethrown, ensuring that test failures are not fatal.
218-
defer tc.Recover(false /* rethrow */)
218+
defer tc.Recover()
219219
require := require.New(tc)
220220

221221
val, err := rand.Int(rand.Reader, big.NewInt(5))

tests/antithesis/xsvm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (w *workload) run(ctx context.Context) {
151151
)
152152
// Any assertion failure from this test context will result in process exit due to the
153153
// panic being rethrown. This ensures that failures in test setup are fatal.
154-
defer tc.Recover(true /* rethrow */)
154+
defer tc.RecoverAndRethrow()
155155
require := require.New(tc)
156156

157157
uri := w.uris[w.id%len(w.uris)]

tests/simple_test_context.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,25 @@ func (tc *SimpleTestContext) RecoverAndExit() {
102102
}
103103
}
104104

105+
// Recover is intended to be deferred in a function executing a test whose
106+
// assertions may result in panics. Such a panic is intended to be recovered to
107+
// allow cleanup functions to be called before execution continues.
108+
func (tc *SimpleTestContext) Recover() {
109+
tc.recover(false /* rethrow */)
110+
}
111+
112+
// RecoverAndRethrow is intended to be deferred in a function executing a test
113+
// whose assertions may result in panics. Such a panic is intended to be recovered
114+
// to allow cleanup functions to be called before the panic is rethrown.
115+
func (tc *SimpleTestContext) RecoverAndRethrow() {
116+
tc.recover(true /* rethrow */)
117+
}
118+
105119
// Recover is intended to be deferred in a function executing a test
106120
// whose assertions may result in panics. Such a panic is intended to
107121
// be recovered to allow cleanup functions to be called. A panic can
108122
// be optionally rethrown by setting `rethrow` to true.
109-
func (tc *SimpleTestContext) Recover(rethrow bool) {
123+
func (tc *SimpleTestContext) recover(rethrow bool) {
110124
// Recover from test failure
111125
var panicData any
112126
if panicData = recover(); panicData != nil {

0 commit comments

Comments
 (0)