Skip to content

Commit

Permalink
test(testutil): try retrying for 'panic: pebbledb: closed'
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jan 10, 2025
1 parent 1ed351f commit 6124f53
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/wasmext/wasm_cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,7 @@ func (s *TestSuite) requiredDeployedContractsLen(total int) {
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}
5 changes: 4 additions & 1 deletion eth/rpc/rpcapi/eth_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ type NodeSuite struct {

func TestSuite_RunAll(t *testing.T) {
suite.Run(t, new(Suite))
suite.Run(t, new(NodeSuite))

testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(NodeSuite))
}, 2)
}

// SetupSuite runs before every test in the suite. Implements the
Expand Down
38 changes: 38 additions & 0 deletions x/common/testutil/cases.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testutil

import (
"strings"
"testing"
)

Expand Down Expand Up @@ -34,3 +35,40 @@ func BeforeIntegrationSuite(suiteT *testing.T) {
}
suiteT.Log("setting up integration test suite")
}

// RetrySuiteRunIfDbClosed runs a test suite with retries, recovering from a
// specific panic message, "pebbledb: closed" that often surfaces in CI when tests
// involve "Nibiru/x/common/testutil/testnetwork".
// For full context, see https://github.com/NibiruChain/nibiru/issues/1918.
func RetrySuiteRunIfDbClosed(t *testing.T, runTest func(), maxRetries int) {
panicMessage := "pebbledb: closed"
for attempt := 0; attempt < maxRetries; attempt++ {
panicked := false

func() {
defer func() {
if r := recover(); r != nil {
if errMsg, ok := r.(string); ok && strings.Contains(errMsg, panicMessage) {
t.Logf("Recovered from panic on attempt %d: %v", attempt, r)
panicked = true
} else {
panic(r) // Re-panic if it's not the specific error

Check warning on line 55 in x/common/testutil/cases.go

View check run for this annotation

Codecov / codecov/patch

x/common/testutil/cases.go#L43-L55

Added lines #L43 - L55 were not covered by tests
}
}
}()

// Run the test suite
runTest()

Check warning on line 61 in x/common/testutil/cases.go

View check run for this annotation

Codecov / codecov/patch

x/common/testutil/cases.go#L61

Added line #L61 was not covered by tests
// suite.Run(t, suiteInstance)
}()

if !panicked {
t.Logf("Test suite succeeded on attempt %d", attempt)
return
}

Check warning on line 68 in x/common/testutil/cases.go

View check run for this annotation

Codecov / codecov/patch

x/common/testutil/cases.go#L65-L68

Added lines #L65 - L68 were not covered by tests

t.Logf("Retrying test suite: attempt %d", attempt+1)

Check warning on line 70 in x/common/testutil/cases.go

View check run for this annotation

Codecov / codecov/patch

x/common/testutil/cases.go#L70

Added line #L70 was not covered by tests
}

t.Fatalf("Test suite failed after %d attempts due to '%s'", maxRetries, panicMessage)

Check warning on line 73 in x/common/testutil/cases.go

View check run for this annotation

Codecov / codecov/patch

x/common/testutil/cases.go#L73

Added line #L73 was not covered by tests
}
4 changes: 3 additions & 1 deletion x/common/testutil/testnetwork/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
)

func TestIntegrationTestSuite_RunAll(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}

// Assert network cleanup
Expand Down
4 changes: 3 additions & 1 deletion x/oracle/keeper/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ func (s *TestSuite) currentPrices() map[asset.Pair]sdk.Dec {
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}

func (s *TestSuite) TearDownSuite() {
Expand Down
4 changes: 3 additions & 1 deletion x/sudo/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ type Account struct {
}

func TestSuite_IntegrationSuite_RunAll(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}

// ———————————————————————————————————————————————————————————————————
Expand Down
4 changes: 3 additions & 1 deletion x/tokenfactory/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type TestSuite struct {
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}

// TestTokenFactory: Runs the test suite with a deterministic order.
Expand Down

0 comments on commit 6124f53

Please sign in to comment.