Commit 9d6a8ccb authored by Adrian Sutton's avatar Adrian Sutton

op-e2e: Wait for game data to be deleted

Fixes a race condition which could cause flaky e2e tests.
parent 589b00ab
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
...@@ -13,6 +14,7 @@ import ( ...@@ -13,6 +14,7 @@ import (
op_challenger "github.com/ethereum-optimism/optimism/op-challenger" op_challenger "github.com/ethereum-optimism/optimism/op-challenger"
"github.com/ethereum-optimism/optimism/op-challenger/config" "github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog" "github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
...@@ -24,6 +26,7 @@ import ( ...@@ -24,6 +26,7 @@ import (
type Helper struct { type Helper struct {
log log.Logger log log.Logger
t *testing.T
require *require.Assertions require *require.Assertions
dir string dir string
cancel func() cancel func()
...@@ -108,6 +111,7 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st ...@@ -108,6 +111,7 @@ func NewChallenger(t *testing.T, ctx context.Context, l1Endpoint string, name st
}() }()
return &Helper{ return &Helper{
log: log, log: log,
t: t,
require: require.New(t), require: require.New(t),
dir: cfg.Datadir, dir: cfg.Datadir,
cancel: cancel, cancel: cancel,
...@@ -171,11 +175,27 @@ func (h *Helper) VerifyGameDataExists(games ...GameAddr) { ...@@ -171,11 +175,27 @@ func (h *Helper) VerifyGameDataExists(games ...GameAddr) {
} }
} }
func (h *Helper) VerifyNoGameDataExists(games ...GameAddr) { func (h *Helper) WaitForGameDataDeletion(ctx context.Context, games ...GameAddr) {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
err := wait.For(ctx, time.Second, func() (bool, error) {
for _, game := range games { for _, game := range games {
addr := game.Addr() addr := game.Addr()
h.require.NoDirExistsf(h.gameDataDir(addr), "should have data for game %v", addr) dir := h.gameDataDir(addr)
_, err := os.Stat(dir)
if errors.Is(err, os.ErrNotExist) {
// This game has been successfully deleted
continue
} }
if err != nil {
return false, fmt.Errorf("failed to check dir %v is deleted: %w", dir, err)
}
h.t.Errorf("Game data directory %v not yet deleted", dir)
return false, nil
}
return true, nil
})
h.require.NoErrorf(err, "should have deleted game data directories")
} }
func (h *Helper) gameDataDir(addr common.Address) string { func (h *Helper) gameDataDir(addr common.Address) string {
......
...@@ -102,7 +102,7 @@ func TestMultipleCannonGames(t *testing.T) { ...@@ -102,7 +102,7 @@ func TestMultipleCannonGames(t *testing.T) {
game2.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) game2.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
// Check that the game directories are removed // Check that the game directories are removed
challenger.VerifyNoGameDataExists(game1, game2) challenger.WaitForGameDataDeletion(ctx, game1, game2)
} }
func TestResolveDisputeGame(t *testing.T) { func TestResolveDisputeGame(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment