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
8b64e041
Commit
8b64e041
authored
Jun 16, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/fetcher: add test to check for duplicate downloads
parent
2a1b722d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
fetcher_test.go
eth/fetcher/fetcher_test.go
+38
-0
No files found.
eth/fetcher/fetcher_test.go
View file @
8b64e041
...
...
@@ -200,3 +200,41 @@ func TestOverlappingAnnouncements(t *testing.T) {
t
.
Fatalf
(
"synchronised block mismatch: have %v, want %v"
,
imported
,
targetBlocks
+
1
)
}
}
// Tests that announces already being retrieved will not be duplicated.
func
TestPendingDeduplication
(
t
*
testing
.
T
)
{
// Create a hash and corresponding block
hashes
:=
createHashes
(
1
,
knownHash
)
blocks
:=
createBlocksFromHashes
(
hashes
)
// Assemble a tester with a built in counter and delayed fetcher
tester
:=
newTester
()
fetcher
:=
tester
.
makeFetcher
(
blocks
)
delay
:=
50
*
time
.
Millisecond
counter
:=
uint32
(
0
)
wrapper
:=
func
(
hashes
[]
common
.
Hash
)
error
{
atomic
.
AddUint32
(
&
counter
,
uint32
(
len
(
hashes
)))
// Simulate a long running fetch
go
func
()
{
time
.
Sleep
(
delay
)
fetcher
(
hashes
)
}()
return
nil
}
// Announce the same block many times until it's fetched (wait for any pending ops)
for
!
tester
.
hasBlock
(
hashes
[
0
])
{
tester
.
fetcher
.
Notify
(
"repeater"
,
hashes
[
0
],
time
.
Now
()
.
Add
(
-
arriveTimeout
),
wrapper
)
time
.
Sleep
(
time
.
Millisecond
)
}
time
.
Sleep
(
delay
)
// Check that all blocks were imported and none fetched twice
if
imported
:=
len
(
tester
.
ownBlocks
);
imported
!=
2
{
t
.
Fatalf
(
"synchronised block mismatch: have %v, want %v"
,
imported
,
2
)
}
if
int
(
counter
)
!=
1
{
t
.
Fatalf
(
"retrieval count mismatch: have %v, want %v"
,
counter
,
1
)
}
}
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