2a0c4e60d2
* preparing for use of `customtype` gogo extension with `NodeID` type * review changes * preparing for use of `customtype` gogo extension with `NodeID` type * review changes * wip * tests passing * wip fixing tests * more wip test fixing * remove NodeIDList from proto files * linter fixes * linter fixes * linter/review fixes * more freaking linter fixes * omg just kill me - linterrrrrrrr * travis linter, i will muder you and your family in your sleep * goimports everything - burn in hell travis * goimports update * go mod tidy
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package tally
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/storj/internal/teststorj"
|
|
"storj.io/storj/pkg/accounting"
|
|
"storj.io/storj/pkg/kademlia"
|
|
"storj.io/storj/pkg/overlay"
|
|
"storj.io/storj/pkg/overlay/mocks"
|
|
"storj.io/storj/pkg/pb"
|
|
"storj.io/storj/pkg/pointerdb"
|
|
"storj.io/storj/pkg/storj"
|
|
"storj.io/storj/storage/teststore"
|
|
)
|
|
|
|
var ctx = context.Background()
|
|
|
|
func TestIdentifyActiveNodes(t *testing.T) {
|
|
|
|
}
|
|
func TestOnlineNodes(t *testing.T) {
|
|
logger := zap.NewNop()
|
|
pointerdb := pointerdb.NewServer(teststore.New(), &overlay.Cache{}, logger, pointerdb.Config{}, nil)
|
|
|
|
const N = 50
|
|
nodes := []*pb.Node{}
|
|
nodeIDs := storj.NodeIDList{}
|
|
expectedOnline := []*pb.Node{}
|
|
for i := 0; i < N; i++ {
|
|
nodeID := teststorj.NodeIDFromString(strconv.Itoa(i))
|
|
n := &pb.Node{Id: nodeID, Type: pb.NodeType_STORAGE, Address: &pb.NodeAddress{Address: ""}}
|
|
nodes = append(nodes, n)
|
|
if i%(rand.Intn(5)+2) == 0 {
|
|
id := teststorj.NodeIDFromString("id" + nodeID.String())
|
|
nodeIDs = append(nodeIDs, id)
|
|
} else {
|
|
nodeIDs = append(nodeIDs, nodeID)
|
|
expectedOnline = append(expectedOnline, n)
|
|
}
|
|
}
|
|
overlayServer := mocks.NewOverlay(nodes)
|
|
kad := &kademlia.Kademlia{}
|
|
limit := 0
|
|
interval := time.Second
|
|
|
|
accountingDb, err := accounting.NewDb("sqlite3://file::memory:?mode=memory&cache=shared")
|
|
assert.NoError(t, err)
|
|
defer func() { _ = accountingDb.Close() }()
|
|
tally, err := newTally(logger, accountingDb, pointerdb, overlayServer, kad, limit, interval)
|
|
assert.NoError(t, err)
|
|
online, err := tally.onlineNodes(ctx, nodeIDs)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, expectedOnline, online)
|
|
}
|
|
|
|
func TestTallyAtRestStorage(t *testing.T) {
|
|
|
|
}
|
|
|
|
func TestNeedToContact(t *testing.T) {
|
|
|
|
}
|
|
|
|
func TestUpdateGranularTable(t *testing.T) {
|
|
|
|
}
|