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
0e32c4c9
Unverified
Commit
0e32c4c9
authored
Dec 05, 2023
by
Mark Tyneway
Committed by
GitHub
Dec 05, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8441 from ethereum-optimism/seb/receipts-tests-atomic-numcalls
op-service: Use atomic int in receipts tests
parents
132e8fbf
b3b462da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
receipts_basic_test.go
op-service/sources/receipts_basic_test.go
+10
-8
No files found.
op-service/sources/receipts_basic_test.go
View file @
0e32c4c9
...
...
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/rand"
"sync/atomic"
"testing"
"time"
...
...
@@ -54,9 +55,9 @@ func TestBasicRPCReceiptsFetcher_Reuse(t *testing.T) {
txHashes
[
2
]
:
false
,
txHashes
[
3
]
:
false
,
}
var
numCalls
int
var
numCalls
atomic
.
Int32
mrpc
.
batchCallFn
=
func
(
_
context
.
Context
,
b
[]
rpc
.
BatchElem
)
(
err
error
)
{
numCalls
++
numCalls
.
Add
(
1
)
for
i
,
el
:=
range
b
{
if
el
.
Method
==
"eth_getTransactionReceipt"
{
txHash
:=
el
.
Args
[
0
]
.
(
common
.
Hash
)
...
...
@@ -78,7 +79,7 @@ func TestBasicRPCReceiptsFetcher_Reuse(t *testing.T) {
recs
,
err
:=
rp
.
FetchReceipts
(
ctx
,
blockid
,
txHashes
)
require
.
Error
(
err
)
require
.
Nil
(
recs
)
require
.
Equal
(
2
,
numCalls
)
require
.
Equal
Values
(
2
,
numCalls
.
Load
()
)
// prepare 2nd fetching - all should succeed now
response
[
txHashes
[
2
]]
=
true
...
...
@@ -89,7 +90,7 @@ func TestBasicRPCReceiptsFetcher_Reuse(t *testing.T) {
for
i
,
rec
:=
range
recs
{
requireEqualReceipt
(
t
,
receipts
[
i
],
rec
)
}
require
.
Equal
(
3
,
numCalls
)
require
.
Equal
Values
(
3
,
numCalls
.
Load
()
)
}
func
TestBasicRPCReceiptsFetcher_Concurrency
(
t
*
testing
.
T
)
{
...
...
@@ -105,10 +106,10 @@ func TestBasicRPCReceiptsFetcher_Concurrency(t *testing.T) {
rp
:=
NewBasicRPCReceiptsFetcher
(
mrpc
,
batchSize
)
// prepare mock
var
numCalls
int
var
numCalls
atomic
.
Int32
mrpc
.
On
(
"BatchCallContext"
,
mock
.
Anything
,
mock
.
AnythingOfType
(
"[]rpc.BatchElem"
))
.
Run
(
func
(
args
mock
.
Arguments
)
{
numCalls
++
numCalls
.
Add
(
1
)
els
:=
args
.
Get
(
1
)
.
([]
rpc
.
BatchElem
)
for
_
,
el
:=
range
els
{
if
el
.
Method
==
"eth_getTransactionReceipt"
{
...
...
@@ -124,8 +125,9 @@ func TestBasicRPCReceiptsFetcher_Concurrency(t *testing.T) {
runConcurrentFetchingTest
(
t
,
rp
,
numFetchers
,
receipts
,
block
)
mrpc
.
AssertExpectations
(
t
)
require
.
NotZero
(
numCalls
,
"BatchCallContext should have been called."
)
require
.
Less
(
numCalls
,
numFetchers
,
"Some IterativeBatchCalls should have been shared."
)
finalNumCalls
:=
int
(
numCalls
.
Load
())
require
.
NotZero
(
finalNumCalls
,
"BatchCallContext should have been called."
)
require
.
Less
(
finalNumCalls
,
numFetchers
,
"Some IterativeBatchCalls should have been shared."
)
}
func
runConcurrentFetchingTest
(
t
*
testing
.
T
,
rp
ReceiptsProvider
,
numFetchers
int
,
receipts
types
.
Receipts
,
block
*
rpcBlock
)
{
...
...
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