Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(testutil): try retrying for 'panic: pebbledb: closed' #2162

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ needed to include double quotes around the hexadecimal string.
- [#2156](https://github.com/NibiruChain/nibiru/pull/2156) - test(evm-e2e): add E2E test using the Nibiru Oracle's ChainLink impl
- [#2157](https://github.com/NibiruChain/nibiru/pull/2157) - fix(evm): Fix unit inconsistency related to AuthInfo.Fee and txData.Fee using effective fee
- [#2160](https://github.com/NibiruChain/nibiru/pull/2160) - fix(evm-precompile): use bank.MsgServer Send in precompile IFunToken.bankMsgSend
- [#2162](https://github.com/NibiruChain/nibiru/pull/2162) - test(testutil): try retrying for 'panic: pebbledb: closed'

#### Nibiru EVM | Before Audit 2 - 2024-12-06

Expand Down
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 @@
}
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
Loading