Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
a604200d
Commit
a604200d
authored
Dec 14, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug where a file containing duplicate blocks would fail to be read properly
parent
5284b7cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
merkledag.go
merkledag.go
+7
-0
merkledag_test.go
merkledag_test.go
+78
-0
No files found.
merkledag.go
View file @
a604200d
...
...
@@ -332,6 +332,13 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) <-chan *Node {
break
}
nodes
[
i
]
=
nd
for
{
//Check for duplicate links
ni
,
err
:=
FindLink
(
root
,
blk
.
Key
(),
nodes
)
if
err
!=
nil
{
break
}
nodes
[
ni
]
=
nd
}
if
next
==
i
{
sig
<-
nd
...
...
merkledag_test.go
View file @
a604200d
...
...
@@ -75,6 +75,25 @@ func makeTestDag(t *testing.T) *Node {
return
root
}
type
devZero
struct
{}
func
(
_
devZero
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
for
i
,
_
:=
range
b
{
b
[
i
]
=
0
}
return
len
(
b
),
nil
}
func
makeZeroDag
(
t
*
testing
.
T
)
*
Node
{
read
:=
io
.
LimitReader
(
devZero
{},
1024
*
32
)
spl
:=
&
chunk
.
SizeSplitter
{
512
}
root
,
err
:=
imp
.
NewDagFromReaderWithSplitter
(
read
,
spl
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
root
}
func
TestBatchFetch
(
t
*
testing
.
T
)
{
var
dagservs
[]
DAGService
for
_
,
bsi
:=
range
blockservice
.
Mocks
(
t
,
5
)
{
...
...
@@ -133,3 +152,62 @@ func TestBatchFetch(t *testing.T) {
<-
done
}
}
func
TestBatchFetchDupBlock
(
t
*
testing
.
T
)
{
var
dagservs
[]
DAGService
for
_
,
bsi
:=
range
blockservice
.
Mocks
(
t
,
5
)
{
dagservs
=
append
(
dagservs
,
NewDAGService
(
bsi
))
}
t
.
Log
(
"finished setup."
)
root
:=
makeZeroDag
(
t
)
read
,
err
:=
uio
.
NewDagReader
(
root
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expected
,
err
:=
ioutil
.
ReadAll
(
read
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
dagservs
[
0
]
.
AddRecursive
(
root
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Log
(
"Added file to first node."
)
k
,
err
:=
root
.
Key
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
done
:=
make
(
chan
struct
{})
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
go
func
(
i
int
)
{
first
,
err
:=
dagservs
[
i
]
.
Get
(
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
fmt
.
Println
(
"Got first node back."
)
read
,
err
:=
uio
.
NewDagReader
(
first
,
dagservs
[
i
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
datagot
,
err
:=
ioutil
.
ReadAll
(
read
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
datagot
,
expected
)
{
t
.
Fatal
(
"Got bad data back!"
)
}
done
<-
struct
{}{}
}(
i
)
}
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
<-
done
}
}
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