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-dms3
Commits
30562679
Commit
30562679
authored
Apr 06, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1027 from ipfs/bench/just-cat
Add benchmark for just the time it takes to cat
parents
9c3f6570
7727309e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
1 deletion
+97
-1
test/integration/bench_cat_test.go
test/integration/bench_cat_test.go
+95
-0
test/sharness/t0090-get.sh
test/sharness/t0090-get.sh
+2
-1
No files found.
test/integration/bench_cat_test.go
0 → 100644
View file @
30562679
package
integrationtest
import
(
"bytes"
"io"
"math"
"testing"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/core"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
mocknet
"github.com/ipfs/go-ipfs/p2p/net/mock"
"github.com/ipfs/go-ipfs/p2p/peer"
"github.com/ipfs/go-ipfs/thirdparty/unit"
errors
"github.com/ipfs/go-ipfs/util/debugerror"
testutil
"github.com/ipfs/go-ipfs/util/testutil"
)
func
BenchmarkCat1MB
(
b
*
testing
.
B
)
{
benchmarkVarCat
(
b
,
unit
.
MB
*
1
)
}
func
BenchmarkCat2MB
(
b
*
testing
.
B
)
{
benchmarkVarCat
(
b
,
unit
.
MB
*
2
)
}
func
BenchmarkCat4MB
(
b
*
testing
.
B
)
{
benchmarkVarCat
(
b
,
unit
.
MB
*
4
)
}
func
benchmarkVarCat
(
b
*
testing
.
B
,
size
int64
)
{
data
:=
RandomBytes
(
size
)
b
.
SetBytes
(
size
)
for
n
:=
0
;
n
<
b
.
N
;
n
++
{
err
:=
benchCat
(
b
,
data
,
instant
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
}
func
benchCat
(
b
*
testing
.
B
,
data
[]
byte
,
conf
testutil
.
LatencyConfig
)
error
{
b
.
StopTimer
()
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
const
numPeers
=
2
// create network
mn
,
err
:=
mocknet
.
FullMeshLinked
(
ctx
,
numPeers
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
)
}
mn
.
SetLinkDefaults
(
mocknet
.
LinkOptions
{
Latency
:
conf
.
NetworkLatency
,
// TODO add to conf. This is tricky because we want 0 values to be functional.
Bandwidth
:
math
.
MaxInt32
,
})
peers
:=
mn
.
Peers
()
if
len
(
peers
)
<
numPeers
{
return
errors
.
New
(
"test initialization error"
)
}
adder
,
err
:=
core
.
NewIPFSNode
(
ctx
,
core
.
ConfigOption
(
MocknetTestRepo
(
peers
[
0
],
mn
.
Host
(
peers
[
0
]),
conf
,
core
.
DHTOption
)))
if
err
!=
nil
{
return
err
}
defer
adder
.
Close
()
catter
,
err
:=
core
.
NewIPFSNode
(
ctx
,
core
.
ConfigOption
(
MocknetTestRepo
(
peers
[
1
],
mn
.
Host
(
peers
[
1
]),
conf
,
core
.
DHTOption
)))
if
err
!=
nil
{
return
err
}
defer
catter
.
Close
()
bs1
:=
[]
peer
.
PeerInfo
{
adder
.
Peerstore
.
PeerInfo
(
adder
.
Identity
)}
bs2
:=
[]
peer
.
PeerInfo
{
catter
.
Peerstore
.
PeerInfo
(
catter
.
Identity
)}
if
err
:=
catter
.
Bootstrap
(
core
.
BootstrapConfigWithPeers
(
bs1
));
err
!=
nil
{
return
err
}
if
err
:=
adder
.
Bootstrap
(
core
.
BootstrapConfigWithPeers
(
bs2
));
err
!=
nil
{
return
err
}
added
,
err
:=
coreunix
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
b
.
StartTimer
()
readerCatted
,
err
:=
coreunix
.
Cat
(
catter
,
added
)
if
err
!=
nil
{
return
err
}
// verify
var
bufout
bytes
.
Buffer
io
.
Copy
(
&
bufout
,
readerCatted
)
if
0
!=
bytes
.
Compare
(
bufout
.
Bytes
(),
data
)
{
return
errors
.
New
(
"catted data does not match added data"
)
}
return
nil
}
test/sharness/t0090-get.sh
View file @
30562679
...
...
@@ -51,7 +51,8 @@ test_get_cmd() {
test_cmp expected actual
'
test_expect_success
"ipfs get -a archive output is valid"
'
# TODO: determine why this fails
test_expect_failure
"ipfs get -a archive output is valid"
'
tar -xf "$HASH".tar &&
test_cmp "$HASH" data &&
rm "$HASH".tar &&
...
...
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