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
b23b4dbd
Commit
b23b4dbd
authored
Aug 06, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: close Table during testing
Not closing the table used to be fine, but now the table has a database.
parent
f12e0161
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
table.go
p2p/discover/table.go
+3
-1
table_test.go
p2p/discover/table_test.go
+5
-3
No files found.
p2p/discover/table.go
View file @
b23b4dbd
...
@@ -164,7 +164,9 @@ func randUint(max uint32) uint32 {
...
@@ -164,7 +164,9 @@ func randUint(max uint32) uint32 {
// Close terminates the network listener and flushes the node database.
// Close terminates the network listener and flushes the node database.
func
(
tab
*
Table
)
Close
()
{
func
(
tab
*
Table
)
Close
()
{
tab
.
net
.
close
()
if
tab
.
net
!=
nil
{
tab
.
net
.
close
()
}
tab
.
db
.
close
()
tab
.
db
.
close
()
}
}
...
...
p2p/discover/table_test.go
View file @
b23b4dbd
...
@@ -35,6 +35,7 @@ func TestTable_pingReplace(t *testing.T) {
...
@@ -35,6 +35,7 @@ func TestTable_pingReplace(t *testing.T) {
doit
:=
func
(
newNodeIsResponding
,
lastInBucketIsResponding
bool
)
{
doit
:=
func
(
newNodeIsResponding
,
lastInBucketIsResponding
bool
)
{
transport
:=
newPingRecorder
()
transport
:=
newPingRecorder
()
tab
:=
newTable
(
transport
,
NodeID
{},
&
net
.
UDPAddr
{},
""
)
tab
:=
newTable
(
transport
,
NodeID
{},
&
net
.
UDPAddr
{},
""
)
defer
tab
.
Close
()
pingSender
:=
newNode
(
MustHexID
(
"a502af0f59b2aab7746995408c79e9ca312d2793cc997e44fc55eda62f0150bbb8c59a6f9269ba3a081518b62699ee807c7c19c20125ddfccca872608af9e370"
),
net
.
IP
{},
99
,
99
)
pingSender
:=
newNode
(
MustHexID
(
"a502af0f59b2aab7746995408c79e9ca312d2793cc997e44fc55eda62f0150bbb8c59a6f9269ba3a081518b62699ee807c7c19c20125ddfccca872608af9e370"
),
net
.
IP
{},
99
,
99
)
// fill up the sender's bucket.
// fill up the sender's bucket.
...
@@ -158,9 +159,7 @@ func newPingRecorder() *pingRecorder {
...
@@ -158,9 +159,7 @@ func newPingRecorder() *pingRecorder {
func
(
t
*
pingRecorder
)
findnode
(
toid
NodeID
,
toaddr
*
net
.
UDPAddr
,
target
NodeID
)
([]
*
Node
,
error
)
{
func
(
t
*
pingRecorder
)
findnode
(
toid
NodeID
,
toaddr
*
net
.
UDPAddr
,
target
NodeID
)
([]
*
Node
,
error
)
{
panic
(
"findnode called on pingRecorder"
)
panic
(
"findnode called on pingRecorder"
)
}
}
func
(
t
*
pingRecorder
)
close
()
{
func
(
t
*
pingRecorder
)
close
()
{}
panic
(
"close called on pingRecorder"
)
}
func
(
t
*
pingRecorder
)
waitping
(
from
NodeID
)
error
{
func
(
t
*
pingRecorder
)
waitping
(
from
NodeID
)
error
{
return
nil
// remote always pings
return
nil
// remote always pings
}
}
...
@@ -180,6 +179,7 @@ func TestTable_closest(t *testing.T) {
...
@@ -180,6 +179,7 @@ func TestTable_closest(t *testing.T) {
// for any node table, Target and N
// for any node table, Target and N
tab
:=
newTable
(
nil
,
test
.
Self
,
&
net
.
UDPAddr
{},
""
)
tab
:=
newTable
(
nil
,
test
.
Self
,
&
net
.
UDPAddr
{},
""
)
tab
.
add
(
test
.
All
)
tab
.
add
(
test
.
All
)
defer
tab
.
Close
()
// check that doClosest(Target, N) returns nodes
// check that doClosest(Target, N) returns nodes
result
:=
tab
.
closest
(
test
.
Target
,
test
.
N
)
.
entries
result
:=
tab
.
closest
(
test
.
Target
,
test
.
N
)
.
entries
...
@@ -237,6 +237,7 @@ func TestTable_ReadRandomNodesGetAll(t *testing.T) {
...
@@ -237,6 +237,7 @@ func TestTable_ReadRandomNodesGetAll(t *testing.T) {
}
}
test
:=
func
(
buf
[]
*
Node
)
bool
{
test
:=
func
(
buf
[]
*
Node
)
bool
{
tab
:=
newTable
(
nil
,
NodeID
{},
&
net
.
UDPAddr
{},
""
)
tab
:=
newTable
(
nil
,
NodeID
{},
&
net
.
UDPAddr
{},
""
)
defer
tab
.
Close
()
for
i
:=
0
;
i
<
len
(
buf
);
i
++
{
for
i
:=
0
;
i
<
len
(
buf
);
i
++
{
ld
:=
cfg
.
Rand
.
Intn
(
len
(
tab
.
buckets
))
ld
:=
cfg
.
Rand
.
Intn
(
len
(
tab
.
buckets
))
tab
.
add
([]
*
Node
{
nodeAtDistance
(
tab
.
self
.
sha
,
ld
)})
tab
.
add
([]
*
Node
{
nodeAtDistance
(
tab
.
self
.
sha
,
ld
)})
...
@@ -279,6 +280,7 @@ func (*closeTest) Generate(rand *rand.Rand, size int) reflect.Value {
...
@@ -279,6 +280,7 @@ func (*closeTest) Generate(rand *rand.Rand, size int) reflect.Value {
func
TestTable_Lookup
(
t
*
testing
.
T
)
{
func
TestTable_Lookup
(
t
*
testing
.
T
)
{
self
:=
nodeAtDistance
(
common
.
Hash
{},
0
)
self
:=
nodeAtDistance
(
common
.
Hash
{},
0
)
tab
:=
newTable
(
lookupTestnet
,
self
.
ID
,
&
net
.
UDPAddr
{},
""
)
tab
:=
newTable
(
lookupTestnet
,
self
.
ID
,
&
net
.
UDPAddr
{},
""
)
defer
tab
.
Close
()
// lookup on empty table returns no nodes
// lookup on empty table returns no nodes
if
results
:=
tab
.
Lookup
(
lookupTestnet
.
target
);
len
(
results
)
>
0
{
if
results
:=
tab
.
Lookup
(
lookupTestnet
.
target
);
len
(
results
)
>
0
{
...
...
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