Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
66979aa4
Commit
66979aa4
authored
Jan 06, 2017
by
Zsolt Felfoldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
light: fixed data race in TestTxPool
parent
93f9c023
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
txpool_test.go
light/txpool_test.go
+19
-16
No files found.
light/txpool_test.go
View file @
66979aa4
...
...
@@ -32,20 +32,22 @@ import (
)
type
testTxRelay
struct
{
send
,
nhMined
,
nhRollback
,
discard
int
send
,
discard
,
mined
chan
int
}
func
(
self
*
testTxRelay
)
Send
(
txs
types
.
Transactions
)
{
self
.
send
=
len
(
txs
)
self
.
send
<-
len
(
txs
)
}
func
(
self
*
testTxRelay
)
NewHead
(
head
common
.
Hash
,
mined
[]
common
.
Hash
,
rollback
[]
common
.
Hash
)
{
self
.
nhMined
=
len
(
mined
)
self
.
nhRollback
=
len
(
rollback
)
m
:=
len
(
mined
)
if
m
!=
0
{
self
.
mined
<-
m
}
}
func
(
self
*
testTxRelay
)
Discard
(
hashes
[]
common
.
Hash
)
{
self
.
discard
=
len
(
hashes
)
self
.
discard
<-
len
(
hashes
)
}
const
poolTestTxs
=
1000
...
...
@@ -94,7 +96,11 @@ func TestTxPool(t *testing.T) {
}
odr
:=
&
testOdr
{
sdb
:
sdb
,
ldb
:
ldb
}
relay
:=
&
testTxRelay
{}
relay
:=
&
testTxRelay
{
send
:
make
(
chan
int
,
1
),
discard
:
make
(
chan
int
,
1
),
mined
:
make
(
chan
int
,
1
),
}
lightchain
,
_
:=
NewLightChain
(
odr
,
testChainConfig
(),
pow
,
evmux
)
lightchain
.
SetValidator
(
bproc
{})
txPermanent
=
50
...
...
@@ -106,36 +112,33 @@ func TestTxPool(t *testing.T) {
s
:=
sentTx
(
i
-
1
)
e
:=
sentTx
(
i
)
for
i
:=
s
;
i
<
e
;
i
++
{
relay
.
send
=
0
pool
.
Add
(
ctx
,
testTx
[
i
])
got
:=
relay
.
send
got
:=
<-
relay
.
send
exp
:=
1
if
got
!=
exp
{
t
.
Errorf
(
"relay.Send expected len = %d, got %d"
,
exp
,
got
)
}
}
relay
.
nhMined
=
0
relay
.
nhRollback
=
0
relay
.
discard
=
0
if
_
,
err
:=
lightchain
.
InsertHeaderChain
([]
*
types
.
Header
{
block
.
Header
()},
1
);
err
!=
nil
{
panic
(
err
)
}
time
.
Sleep
(
time
.
Millisecond
*
30
)
got
:=
relay
.
nhM
ined
got
:=
<-
relay
.
m
ined
exp
:=
minedTx
(
i
)
-
minedTx
(
i
-
1
)
if
got
!=
exp
{
t
.
Errorf
(
"relay.NewHead expected len(mined) = %d, got %d"
,
exp
,
got
)
}
got
=
relay
.
discard
exp
=
0
if
i
>
int
(
txPermanent
)
+
1
{
exp
=
minedTx
(
i
-
int
(
txPermanent
)
-
1
)
-
minedTx
(
i
-
int
(
txPermanent
)
-
2
)
}
if
got
!=
exp
{
t
.
Errorf
(
"relay.Discard expected len = %d, got %d"
,
exp
,
got
)
if
exp
!=
0
{
got
=
<-
relay
.
discard
if
got
!=
exp
{
t
.
Errorf
(
"relay.Discard expected len = %d, got %d"
,
exp
,
got
)
}
}
}
}
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