Skip to content

Commit

Permalink
golint util/, thirdparty/
Browse files Browse the repository at this point in the history
and exchange/bitswap/testutils.go

License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Jun 17, 2015
1 parent 91548ef commit 20b87d1
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 38 deletions.
6 changes: 3 additions & 3 deletions exchange/bitswap/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (g *SessionGenerator) Next() Instance {
}

func (g *SessionGenerator) Instances(n int) []Instance {
instances := make([]Instance, 0)
var instances []Instance
for j := 0; j < n; j++ {
inst := g.Next()
instances = append(instances, inst)
Expand Down Expand Up @@ -87,12 +87,12 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// just a much better idea.
func session(ctx context.Context, net tn.Network, p testutil.Identity) Instance {
bsdelay := delay.Fixed(0)
const kWriteCacheElems = 100
const writeCacheElems = 100

adapter := net.Adapter(p)
dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay))

bstore, err := blockstore.WriteCached(blockstore.NewBlockstore(ds_sync.MutexWrap(dstore)), kWriteCacheElems)
bstore, err := blockstore.WriteCached(blockstore.NewBlockstore(ds_sync.MutexWrap(dstore)), writeCacheElems)
if err != nil {
panic(err.Error()) // FIXME perhaps change signature and return error.
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/addcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestDegenerateSlowRouting(t *testing.T) {

func Test100MBMacbookCoastToCoast(t *testing.T) {
SkipUnlessEpic(t)
conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
conf := testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow()
if err := DirectAddCat(RandomBytes(100*1024*1024), conf); err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func benchmarkAddCat(numBytes int64, conf testutil.LatencyConfig, b *testing.B)
}
}

var instant = testutil.LatencyConfig{}.All_Instantaneous()
var instant = testutil.LatencyConfig{}.AllInstantaneous()

func BenchmarkInstantaneousAddCat1KB(b *testing.B) { benchmarkAddCat(1*unit.KB, instant, b) }
func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, instant, b) }
Expand All @@ -34,7 +34,7 @@ func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.M
func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, instant, b) }
func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, instant, b) }

var routing = testutil.LatencyConfig{}.Routing_Slow()
var routing = testutil.LatencyConfig{}.RoutingSlow()

func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, routing, b) }
func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, routing, b) }
Expand All @@ -47,7 +47,7 @@ func BenchmarkRoutingSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB
func BenchmarkRoutingSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, routing, b) }
func BenchmarkRoutingSlowAddCat512MB(b *testing.B) { benchmarkAddCat(512*unit.MB, routing, b) }

var network = testutil.LatencyConfig{}.Network_NYtoSF()
var network = testutil.LatencyConfig{}.NetworkNYtoSF()

func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, network, b) }
func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, network, b) }
Expand All @@ -59,7 +59,7 @@ func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB,
func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, network, b) }
func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, network, b) }

var hdd = testutil.LatencyConfig{}.Blockstore_7200RPM()
var hdd = testutil.LatencyConfig{}.Blockstore7200RPM()

func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, hdd, b) }
func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, hdd, b) }
Expand All @@ -71,7 +71,7 @@ func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.
func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, hdd, b) }
func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, hdd, b) }

var mixed = testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
var mixed = testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow()

func BenchmarkMixedAddCat1MBXX(b *testing.B) { benchmarkAddCat(1*unit.MB, mixed, b) }
func BenchmarkMixedAddCat2MBXX(b *testing.B) { benchmarkAddCat(2*unit.MB, mixed, b) }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/three_legged_cat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestThreeLeggedCatDegenerateSlowRouting(t *testing.T) {

func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) {
SkipUnlessEpic(t)
conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
conf := testutil.LatencyConfig{}.NetworkNYtoSF().BlockstoreSlowSSD2014().RoutingSlow()
if err := RunThreeLeggedCat(RandomBytes(100*unit.MB), conf); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/eventlog/loggable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (l LoggableMap) Loggable() map[string]interface{} {
return l
}

// Loggable converts a func into a Loggable
// LoggableF converts a func into a Loggable
type LoggableF func() map[string]interface{}

func (l LoggableF) Loggable() map[string]interface{} {
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (n *Notifier) Notify(e Notifiee) {
n.mu.Unlock()
}

// StopNotifying stops notifying Notifiee e. This function
// StopNotify stops notifying Notifiee e. This function
// is meant to be called behind your own type-safe function(s):
//
// // generic function for pattern-following
Expand Down
22 changes: 11 additions & 11 deletions thirdparty/redis-datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import (
query "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query"
)

var _ datastore.Datastore = &RedisDatastore{}
var _ datastore.ThreadSafeDatastore = &RedisDatastore{}
var _ datastore.Datastore = &Datastore{}
var _ datastore.ThreadSafeDatastore = &Datastore{}

var ErrInvalidType = errors.New("redis datastore: invalid type error. this datastore only supports []byte values")

func NewExpiringDatastore(client *redis.Client, ttl time.Duration) (datastore.ThreadSafeDatastore, error) {
return &RedisDatastore{
return &Datastore{
client: client,
ttl: ttl,
}, nil
}

func NewDatastore(client *redis.Client) (datastore.ThreadSafeDatastore, error) {
return &RedisDatastore{
return &Datastore{
client: client,
}, nil
}

type RedisDatastore struct {
type Datastore struct {
mu sync.Mutex
client *redis.Client
ttl time.Duration
}

func (ds *RedisDatastore) Put(key datastore.Key, value interface{}) error {
func (ds *Datastore) Put(key datastore.Key, value interface{}) error {
ds.mu.Lock()
defer ds.mu.Unlock()

Expand All @@ -59,26 +59,26 @@ func (ds *RedisDatastore) Put(key datastore.Key, value interface{}) error {
return nil
}

func (ds *RedisDatastore) Get(key datastore.Key) (value interface{}, err error) {
func (ds *Datastore) Get(key datastore.Key) (value interface{}, err error) {
ds.mu.Lock()
defer ds.mu.Unlock()
return ds.client.Cmd("GET", key.String()).Bytes()
}

func (ds *RedisDatastore) Has(key datastore.Key) (exists bool, err error) {
func (ds *Datastore) Has(key datastore.Key) (exists bool, err error) {
ds.mu.Lock()
defer ds.mu.Unlock()
return ds.client.Cmd("EXISTS", key.String()).Bool()
}

func (ds *RedisDatastore) Delete(key datastore.Key) (err error) {
func (ds *Datastore) Delete(key datastore.Key) (err error) {
ds.mu.Lock()
defer ds.mu.Unlock()
return ds.client.Cmd("DEL", key.String()).Err
}

func (ds *RedisDatastore) Query(q query.Query) (query.Results, error) {
func (ds *Datastore) Query(q query.Query) (query.Results, error) {
return nil, errors.New("TODO implement query for redis datastore?")
}

func (ds *RedisDatastore) IsThreadSafe() {}
func (ds *Datastore) IsThreadSafe() {}
2 changes: 1 addition & 1 deletion thirdparty/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (i Information) String() string {
tmp := int64(i)

// default
var d int64 = tmp
var d = tmp
symbol := "B"

switch {
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *PeerNetParams) checkKeys() error {
return fmt.Errorf("sig verify failed: %s", err)
}
if !sigok {
return fmt.Errorf("sig verify failed: sig invalid!")
return fmt.Errorf("sig verify failed: sig invalid")
}

return nil // ok. move along.
Expand Down
14 changes: 7 additions & 7 deletions util/testutil/latency_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@ type LatencyConfig struct {
RoutingLatency time.Duration
}

func (c LatencyConfig) All_Instantaneous() LatencyConfig {
func (c LatencyConfig) AllInstantaneous() LatencyConfig {
// Could use a zero value but whatever. Consistency of interface
c.NetworkLatency = 0
c.RoutingLatency = 0
c.BlockstoreLatency = 0
return c
}

func (c LatencyConfig) Network_NYtoSF() LatencyConfig {
func (c LatencyConfig) NetworkNYtoSF() LatencyConfig {
c.NetworkLatency = 20 * time.Millisecond
return c
}

func (c LatencyConfig) Network_IntraDatacenter2014() LatencyConfig {
func (c LatencyConfig) NetworkIntraDatacenter2014() LatencyConfig {
c.NetworkLatency = 250 * time.Microsecond
return c
}

func (c LatencyConfig) Blockstore_FastSSD2014() LatencyConfig {
func (c LatencyConfig) BlockstoreFastSSD2014() LatencyConfig {
const iops = 100000
c.BlockstoreLatency = (1 / iops) * time.Second
return c
}

func (c LatencyConfig) Blockstore_SlowSSD2014() LatencyConfig {
func (c LatencyConfig) BlockstoreSlowSSD2014() LatencyConfig {
c.BlockstoreLatency = 150 * time.Microsecond
return c
}

func (c LatencyConfig) Blockstore_7200RPM() LatencyConfig {
func (c LatencyConfig) Blockstore7200RPM() LatencyConfig {
c.BlockstoreLatency = 8 * time.Millisecond
return c
}

func (c LatencyConfig) Routing_Slow() LatencyConfig {
func (c LatencyConfig) RoutingSlow() LatencyConfig {
c.RoutingLatency = 200 * time.Millisecond
return c
}
10 changes: 4 additions & 6 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package util implements various utility functions used within ipfs
// Package util implements various utility functions used within ipfs
// that do not currently have a better place to live.
package util

Expand Down Expand Up @@ -95,7 +95,7 @@ func GetenvBool(name string) bool {
return v == "true" || v == "t" || v == "1"
}

// multiErr is a util to return multiple errors
// MultiErr is a util to return multiple errors
type MultiErr []error

func (m MultiErr) Error() string {
Expand All @@ -116,17 +116,15 @@ func (m MultiErr) Error() string {
func Partition(subject string, sep string) (string, string, string) {
if i := strings.Index(subject, sep); i != -1 {
return subject[:i], subject[i : i+len(sep)], subject[i+len(sep):]
} else {
return subject, "", ""
}
return subject, "", ""
}

func RPartition(subject string, sep string) (string, string, string) {
if i := strings.LastIndex(subject, sep); i != -1 {
return subject[:i], subject[i : i+len(sep)], subject[i+len(sep):]
} else {
return subject, "", ""
}
return subject, "", ""
}

// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
Expand Down

0 comments on commit 20b87d1

Please sign in to comment.