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
0b6524cf
Commit
0b6524cf
authored
Dec 15, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some cleanup, use WaitGroup over channel ugliness
parent
d5fcd17e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
61 deletions
+11
-61
merkledag_test.go
merkledag_test.go
+11
-61
No files found.
merkledag_test.go
View file @
0b6524cf
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"sync"
"testing"
"testing"
blockservice
"github.com/jbenet/go-ipfs/blockservice"
blockservice
"github.com/jbenet/go-ipfs/blockservice"
...
@@ -95,72 +96,22 @@ func makeZeroDag(t *testing.T) *Node {
...
@@ -95,72 +96,22 @@ func makeZeroDag(t *testing.T) *Node {
}
}
func
TestBatchFetch
(
t
*
testing
.
T
)
{
func
TestBatchFetch
(
t
*
testing
.
T
)
{
var
dagservs
[]
DAGService
for
_
,
bsi
:=
range
blockservice
.
Mocks
(
t
,
5
)
{
dagservs
=
append
(
dagservs
,
NewDAGService
(
bsi
))
}
t
.
Log
(
"finished setup."
)
root
:=
makeTestDag
(
t
)
root
:=
makeTestDag
(
t
)
read
,
err
:=
uio
.
NewDagReader
(
root
,
nil
)
runBatchFetchTest
(
t
,
root
)
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
}
}
}
func
TestBatchFetchDupBlock
(
t
*
testing
.
T
)
{
func
TestBatchFetchDupBlock
(
t
*
testing
.
T
)
{
root
:=
makeZeroDag
(
t
)
runBatchFetchTest
(
t
,
root
)
}
func
runBatchFetchTest
(
t
*
testing
.
T
,
root
*
Node
)
{
var
dagservs
[]
DAGService
var
dagservs
[]
DAGService
for
_
,
bsi
:=
range
blockservice
.
Mocks
(
t
,
5
)
{
for
_
,
bsi
:=
range
blockservice
.
Mocks
(
t
,
5
)
{
dagservs
=
append
(
dagservs
,
NewDAGService
(
bsi
))
dagservs
=
append
(
dagservs
,
NewDAGService
(
bsi
))
}
}
t
.
Log
(
"finished setup."
)
t
.
Log
(
"finished setup."
)
root
:=
makeZeroDag
(
t
)
read
,
err
:=
uio
.
NewDagReader
(
root
,
nil
)
read
,
err
:=
uio
.
NewDagReader
(
root
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -182,9 +133,11 @@ func TestBatchFetchDupBlock(t *testing.T) {
...
@@ -182,9 +133,11 @@ func TestBatchFetchDupBlock(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
done
:=
make
(
chan
struct
{}
)
wg
:=
sync
.
WaitGroup
{}
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
wg
.
Add
(
1
)
go
func
(
i
int
)
{
go
func
(
i
int
)
{
defer
wg
.
Done
()
first
,
err
:=
dagservs
[
i
]
.
Get
(
k
)
first
,
err
:=
dagservs
[
i
]
.
Get
(
k
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -203,11 +156,8 @@ func TestBatchFetchDupBlock(t *testing.T) {
...
@@ -203,11 +156,8 @@ func TestBatchFetchDupBlock(t *testing.T) {
if
!
bytes
.
Equal
(
datagot
,
expected
)
{
if
!
bytes
.
Equal
(
datagot
,
expected
)
{
t
.
Fatal
(
"Got bad data back!"
)
t
.
Fatal
(
"Got bad data back!"
)
}
}
done
<-
struct
{}{}
}(
i
)
}(
i
)
}
}
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
wg
.
Done
()
<-
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