-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from jbenet/test/mocks-on-mocks-on-mocks
AddCat Bitswap Integration Tests
- Loading branch information
Showing
28 changed files
with
707 additions
and
297 deletions.
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,161 @@ | ||
package epictest | ||
|
||
import ( | ||
"bytes" | ||
"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" | ||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random" | ||
) | ||
|
||
const kSeed = 1 | ||
|
||
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 | ||
random.WritePseudoRandomBytes(conf.DataAmountBytes, &data, kSeed) // FIXME get a lazy reader | ||
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.