-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AddCat Bitswap Integration Tests #444
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1c8acd0
fix(bs/testnet) rm named error
866ef72
misc(blockstore) comment
ae79ac0
feat(util/delay) add Delay
c3b3d73
feat(util/ds2/delayed) add delayed datastore
8e0c8a7
refactor(mdag, bserv, bs) mocks, etc.
3c44ad1
feat(bs/testnet) use delay in virtual network
193004a
refac(bs/test) provide a shared net delay constant
3ecdec9
refactor(mockrouting) misc
cf43cdd
feat(bs/testutil) use write cache
be98226
feat(epictest) tests and benchmarks
c00a7a2
misc(bitswap/strat) rm noisy message
71d6e5c
fix(epic) use PRNG
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package blockservice | ||
|
||
import ( | ||
"testing" | ||
|
||
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap" | ||
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet" | ||
mockrouting "github.com/jbenet/go-ipfs/routing/mock" | ||
delay "github.com/jbenet/go-ipfs/util/delay" | ||
) | ||
|
||
// Mocks returns |n| connected mock Blockservices | ||
func Mocks(t *testing.T, n int) []*BlockService { | ||
net := tn.VirtualNetwork(delay.Fixed(0)) | ||
rs := mockrouting.NewServer() | ||
sg := bitswap.NewSessionGenerator(net, rs) | ||
|
||
instances := sg.Instances(n) | ||
|
||
var servs []*BlockService | ||
for _, i := range instances { | ||
bserv, err := New(i.Blockstore(), i.Exchange) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
servs = append(servs, bserv) | ||
} | ||
return servs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package epictest | ||
|
||
import ( | ||
"bytes" | ||
randcrypto "crypto/rand" | ||
"fmt" | ||
"io" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
blockservice "github.com/jbenet/go-ipfs/blockservice" | ||
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap" | ||
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet" | ||
importer "github.com/jbenet/go-ipfs/importer" | ||
chunk "github.com/jbenet/go-ipfs/importer/chunk" | ||
merkledag "github.com/jbenet/go-ipfs/merkledag" | ||
path "github.com/jbenet/go-ipfs/path" | ||
mockrouting "github.com/jbenet/go-ipfs/routing/mock" | ||
uio "github.com/jbenet/go-ipfs/unixfs/io" | ||
util "github.com/jbenet/go-ipfs/util" | ||
errors "github.com/jbenet/go-ipfs/util/debugerror" | ||
delay "github.com/jbenet/go-ipfs/util/delay" | ||
) | ||
|
||
func Test100MBInstantaneous(t *testing.T) { | ||
t.Log("a sanity check") | ||
|
||
t.Parallel() | ||
|
||
conf := Config{ | ||
NetworkLatency: 0, | ||
RoutingLatency: 0, | ||
BlockstoreLatency: 0, | ||
DataAmountBytes: 100 * 1024 * 1024, | ||
} | ||
|
||
AddCatBytes(conf) | ||
} | ||
|
||
func TestDegenerateSlowBlockstore(t *testing.T) { | ||
SkipUnlessEpic(t) | ||
t.Parallel() | ||
|
||
conf := Config{BlockstoreLatency: 50 * time.Millisecond} | ||
|
||
if err := AddCatPowers(conf, 128); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestDegenerateSlowNetwork(t *testing.T) { | ||
SkipUnlessEpic(t) | ||
t.Parallel() | ||
|
||
conf := Config{NetworkLatency: 400 * time.Millisecond} | ||
|
||
if err := AddCatPowers(conf, 128); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestDegenerateSlowRouting(t *testing.T) { | ||
SkipUnlessEpic(t) | ||
t.Parallel() | ||
|
||
conf := Config{RoutingLatency: 400 * time.Millisecond} | ||
|
||
if err := AddCatPowers(conf, 128); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func Test100MBMacbookCoastToCoast(t *testing.T) { | ||
SkipUnlessEpic(t) | ||
t.Parallel() | ||
|
||
conf := Config{ | ||
DataAmountBytes: 100 * 1024 * 1024, | ||
}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow() | ||
|
||
if err := AddCatBytes(conf); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func AddCatPowers(conf Config, megabytesMax int64) error { | ||
var i int64 | ||
for i = 1; i < megabytesMax; i = i * 2 { | ||
fmt.Printf("%d MB\n", i) | ||
conf.DataAmountBytes = i * 1024 * 1024 | ||
if err := AddCatBytes(conf); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func AddCatBytes(conf Config) error { | ||
|
||
sessionGenerator := bitswap.NewSessionGenerator( | ||
tn.VirtualNetwork(delay.Fixed(conf.NetworkLatency)), // TODO rename VirtualNetwork | ||
mockrouting.NewServerWithDelay(delay.Fixed(conf.RoutingLatency)), | ||
) | ||
|
||
adder := sessionGenerator.Next() | ||
catter := sessionGenerator.Next() | ||
catter.SetBlockstoreLatency(conf.BlockstoreLatency) | ||
|
||
adder.SetBlockstoreLatency(0) // disable blockstore latency during add operation | ||
var data bytes.Buffer | ||
// FIXME replace with a random data generator that reproduces data given a seed value | ||
io.Copy(&data, &io.LimitedReader{R: randcrypto.Reader, N: conf.DataAmountBytes}) | ||
keyAdded, err := add(adder, bytes.NewReader(data.Bytes())) | ||
if err != nil { | ||
return err | ||
} | ||
adder.SetBlockstoreLatency(conf.BlockstoreLatency) // add some blockstore delay to make the catter wait | ||
|
||
readerCatted, err := cat(catter, keyAdded) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// verify | ||
var bufout bytes.Buffer | ||
io.Copy(&bufout, readerCatted) | ||
if 0 != bytes.Compare(bufout.Bytes(), data.Bytes()) { | ||
return errors.New("catted data does not match added data") | ||
} | ||
return nil | ||
} | ||
|
||
func cat(catter bitswap.Instance, k util.Key) (io.Reader, error) { | ||
catterdag := merkledag.NewDAGService(&blockservice.BlockService{catter.Blockstore(), catter.Exchange}) | ||
nodeCatted, err := (&path.Resolver{catterdag}).ResolvePath(k.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return uio.NewDagReader(nodeCatted, catterdag) | ||
} | ||
|
||
func add(adder bitswap.Instance, r io.Reader) (util.Key, error) { | ||
nodeAdded, err := importer.BuildDagFromReader( | ||
r, | ||
merkledag.NewDAGService(&blockservice.BlockService{adder.Blockstore(), adder.Exchange}), | ||
nil, | ||
chunk.DefaultSplitter, | ||
) | ||
if err != nil { | ||
return "", err | ||
} | ||
return nodeAdded.Key() | ||
} | ||
|
||
func SkipUnlessEpic(t *testing.T) { | ||
if os.Getenv("IPFS_EPIC_TEST") == "" { | ||
t.SkipNow() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package epictest | ||
|
||
import "testing" | ||
|
||
func benchmarkAddCat(conf Config, b *testing.B) { | ||
b.SetBytes(conf.DataAmountBytes) | ||
for n := 0; n < b.N; n++ { | ||
if err := AddCatBytes(conf); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
var instant = Config{}.All_Instantaneous() | ||
|
||
func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(1), b) } | ||
func BenchmarkInstantaneousAddCat2MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(2), b) } | ||
func BenchmarkInstantaneousAddCat4MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(4), b) } | ||
func BenchmarkInstantaneousAddCat8MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(8), b) } | ||
func BenchmarkInstantaneousAddCat16MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(16), b) } | ||
func BenchmarkInstantaneousAddCat32MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(32), b) } | ||
func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(64), b) } | ||
func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(128), b) } | ||
func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(instant.Megabytes(256), b) } | ||
|
||
var routing = Config{}.Routing_Slow() | ||
|
||
func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(1), b) } | ||
func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(2), b) } | ||
func BenchmarkRoutingSlowAddCat4MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(4), b) } | ||
func BenchmarkRoutingSlowAddCat8MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(8), b) } | ||
func BenchmarkRoutingSlowAddCat16MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(16), b) } | ||
func BenchmarkRoutingSlowAddCat32MB(b *testing.B) { benchmarkAddCat(routing.Megabytes(32), b) } | ||
|
||
var network = Config{}.Network_NYtoSF() | ||
|
||
func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(network.Megabytes(1), b) } | ||
func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(network.Megabytes(2), b) } | ||
func BenchmarkNetworkSlowAddCat4MB(b *testing.B) { benchmarkAddCat(network.Megabytes(4), b) } | ||
func BenchmarkNetworkSlowAddCat8MB(b *testing.B) { benchmarkAddCat(network.Megabytes(8), b) } | ||
func BenchmarkNetworkSlowAddCat16MB(b *testing.B) { benchmarkAddCat(network.Megabytes(16), b) } | ||
func BenchmarkNetworkSlowAddCat32MB(b *testing.B) { benchmarkAddCat(network.Megabytes(32), b) } | ||
func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(network.Megabytes(64), b) } | ||
func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(network.Megabytes(128), b) } | ||
func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(network.Megabytes(256), b) } | ||
|
||
var blockstore = Config{}.Blockstore_7200RPM() | ||
|
||
func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(1), b) } | ||
func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(2), b) } | ||
func BenchmarkBlockstoreSlowAddCat4MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(4), b) } | ||
func BenchmarkBlockstoreSlowAddCat8MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(8), b) } | ||
func BenchmarkBlockstoreSlowAddCat16MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(16), b) } | ||
func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(32), b) } | ||
func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(64), b) } | ||
func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(128), b) } | ||
func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(blockstore.Megabytes(256), b) } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
go-random
for a Reader with much faster randomness generation. dont really need cryptographic strength for these tests, and randcrypto is slow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Wonderful. I was looking for a way to get determinism.
71d6e5c
The icing on the cake would be for random to provide an
io.Reader
. It would cut down peak memory usage and make it possible to create larger tests. Not critical yet. The blockstore will limit test size before that will.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, i thought it did. oh well
On Sat, Dec 13, 2014 at 7:41 AM, Brian Tiger Chow [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before
after