Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
27d45ee0
Unverified
Commit
27d45ee0
authored
Aug 23, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Cache the completed status of the game
parent
5ba697a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
19 deletions
+17
-19
player.go
op-challenger/fault/player.go
+6
-7
player_test.go
op-challenger/fault/player_test.go
+11
-12
No files found.
op-challenger/fault/player.go
View file @
27d45ee0
...
@@ -30,6 +30,8 @@ type GamePlayer struct {
...
@@ -30,6 +30,8 @@ type GamePlayer struct {
caller
GameInfo
caller
GameInfo
logger
log
.
Logger
logger
log
.
Logger
cleanup
func
()
error
cleanup
func
()
error
completed
bool
}
}
func
NewGamePlayer
(
func
NewGamePlayer
(
...
@@ -100,13 +102,9 @@ func NewGamePlayer(
...
@@ -100,13 +102,9 @@ func NewGamePlayer(
}
}
func
(
g
*
GamePlayer
)
ProgressGame
(
ctx
context
.
Context
)
bool
{
func
(
g
*
GamePlayer
)
ProgressGame
(
ctx
context
.
Context
)
bool
{
status
,
err
:=
g
.
caller
.
GetGameStatus
(
ctx
)
if
g
.
completed
{
if
err
!=
nil
{
g
.
logger
.
Warn
(
"Unable to retrieve game status"
,
"err"
,
err
)
return
false
}
if
status
!=
types
.
GameStatusInProgress
{
// Game is already complete so don't try to perform further actions.
// Game is already complete so don't try to perform further actions.
g
.
logger
.
Trace
(
"Skipping completed game"
)
return
true
return
true
}
}
g
.
logger
.
Trace
(
"Checking if actions are required"
)
g
.
logger
.
Trace
(
"Checking if actions are required"
)
...
@@ -117,7 +115,8 @@ func (g *GamePlayer) ProgressGame(ctx context.Context) bool {
...
@@ -117,7 +115,8 @@ func (g *GamePlayer) ProgressGame(ctx context.Context) bool {
g
.
logger
.
Warn
(
"Unable to retrieve game status"
,
"err"
,
err
)
g
.
logger
.
Warn
(
"Unable to retrieve game status"
,
"err"
,
err
)
}
else
{
}
else
{
g
.
logGameStatus
(
ctx
,
status
)
g
.
logGameStatus
(
ctx
,
status
)
return
status
!=
types
.
GameStatusInProgress
g
.
completed
=
status
!=
types
.
GameStatusInProgress
return
g
.
completed
}
}
return
false
return
false
}
}
...
...
op-challenger/fault/player_test.go
View file @
27d45ee0
...
@@ -93,8 +93,7 @@ func TestProgressGame_LogGameStatus(t *testing.T) {
...
@@ -93,8 +93,7 @@ func TestProgressGame_LogGameStatus(t *testing.T) {
test
:=
test
test
:=
test
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
handler
,
game
,
gameState
:=
setupProgressGameTest
(
t
,
test
.
agreeWithOutput
)
handler
,
game
,
gameState
:=
setupProgressGameTest
(
t
,
test
.
agreeWithOutput
)
gameState
.
preStatus
=
types
.
GameStatusInProgress
gameState
.
status
=
test
.
status
gameState
.
postStatus
=
test
.
status
done
:=
game
.
ProgressGame
(
context
.
Background
())
done
:=
game
.
ProgressGame
(
context
.
Background
())
require
.
Equal
(
t
,
1
,
gameState
.
callCount
,
"should perform next actions"
)
require
.
Equal
(
t
,
1
,
gameState
.
callCount
,
"should perform next actions"
)
...
@@ -109,13 +108,17 @@ func TestProgressGame_LogGameStatus(t *testing.T) {
...
@@ -109,13 +108,17 @@ func TestProgressGame_LogGameStatus(t *testing.T) {
func
TestDoNotActOnCompleteGame
(
t
*
testing
.
T
)
{
func
TestDoNotActOnCompleteGame
(
t
*
testing
.
T
)
{
for
_
,
status
:=
range
[]
types
.
GameStatus
{
types
.
GameStatusChallengerWon
,
types
.
GameStatusDefenderWon
}
{
for
_
,
status
:=
range
[]
types
.
GameStatus
{
types
.
GameStatusChallengerWon
,
types
.
GameStatusDefenderWon
}
{
t
.
Run
(
status
.
String
(),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
status
.
String
(),
func
(
t
*
testing
.
T
)
{
handler
,
game
,
gameState
:=
setupProgressGameTest
(
t
,
true
)
_
,
game
,
gameState
:=
setupProgressGameTest
(
t
,
true
)
gameState
.
preS
tatus
=
status
gameState
.
s
tatus
=
status
done
:=
game
.
ProgressGame
(
context
.
Background
())
done
:=
game
.
ProgressGame
(
context
.
Background
())
require
.
Equal
(
t
,
0
,
gameState
.
callCount
,
"should not perform actions
"
)
require
.
Equal
(
t
,
1
,
gameState
.
callCount
,
"acts the first time
"
)
require
.
True
(
t
,
done
,
"should be done"
)
require
.
True
(
t
,
done
,
"should be done"
)
require
.
Empty
(
t
,
handler
.
Logs
,
"should not log game status"
)
// Should not act when it knows the game is already complete
done
=
game
.
ProgressGame
(
context
.
Background
())
require
.
Equal
(
t
,
1
,
gameState
.
callCount
,
"does not act after game is complete"
)
require
.
True
(
t
,
done
,
"should still be done"
)
})
})
}
}
}
}
...
@@ -137,8 +140,7 @@ func setupProgressGameTest(t *testing.T, agreeWithProposedRoot bool) (*testlog.C
...
@@ -137,8 +140,7 @@ func setupProgressGameTest(t *testing.T, agreeWithProposedRoot bool) (*testlog.C
}
}
type
stubGameState
struct
{
type
stubGameState
struct
{
preStatus
types
.
GameStatus
status
types
.
GameStatus
postStatus
types
.
GameStatus
claimCount
uint64
claimCount
uint64
callCount
int
callCount
int
actErr
error
actErr
error
...
@@ -151,10 +153,7 @@ func (s *stubGameState) Act(ctx context.Context) error {
...
@@ -151,10 +153,7 @@ func (s *stubGameState) Act(ctx context.Context) error {
}
}
func
(
s
*
stubGameState
)
GetGameStatus
(
ctx
context
.
Context
)
(
types
.
GameStatus
,
error
)
{
func
(
s
*
stubGameState
)
GetGameStatus
(
ctx
context
.
Context
)
(
types
.
GameStatus
,
error
)
{
if
s
.
callCount
==
0
{
return
s
.
status
,
nil
return
s
.
preStatus
,
nil
}
return
s
.
postStatus
,
nil
}
}
func
(
s
*
stubGameState
)
GetClaimCount
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
func
(
s
*
stubGameState
)
GetClaimCount
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment