testplanet: add logger (#649)

This commit is contained in:
Egon Elbre 2018-11-15 10:57:47 +02:00 committed by GitHub
parent 2c36dcc2c8
commit 21a102a05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 11 deletions

View File

@ -7,6 +7,8 @@ import (
"io"
"net"
"go.uber.org/zap"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/pkg/overlay"
"storj.io/storj/pkg/pb"
@ -19,6 +21,7 @@ import (
// Node is a general purpose
type Node struct {
Log *zap.Logger
Info pb.Node
Identity *provider.FullIdentity
Transport transport.Client

View File

@ -10,8 +10,10 @@ import (
"net"
"os"
"path/filepath"
"strconv"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
"google.golang.org/grpc"
"storj.io/storj/internal/memory"
@ -28,6 +30,7 @@ import (
// Planet is a full storj system setup.
type Planet struct {
log *zap.Logger
directory string // TODO: ensure that everything is in-memory to speed things up
nodeInfos []pb.Node
@ -42,8 +45,16 @@ type Planet struct {
}
// New creates a new full system with the given number of nodes.
func New(satelliteCount, storageNodeCount, uplinkCount int) (*Planet, error) {
func New(t zaptest.TestingT, satelliteCount, storageNodeCount, uplinkCount int) (*Planet, error) {
var log *zap.Logger
if t == nil {
log = zap.NewNop()
} else {
log = zaptest.NewLogger(t)
}
planet := &Planet{
log: log,
identities: pregeneratedIdentities.Clone(),
}
@ -53,17 +64,17 @@ func New(satelliteCount, storageNodeCount, uplinkCount int) (*Planet, error) {
return nil, err
}
planet.Satellites, err = planet.newNodes(satelliteCount)
planet.Satellites, err = planet.newNodes("satellite", satelliteCount)
if err != nil {
return nil, utils.CombineErrors(err, planet.Shutdown())
}
planet.StorageNodes, err = planet.newNodes(storageNodeCount)
planet.StorageNodes, err = planet.newNodes("storage", storageNodeCount)
if err != nil {
return nil, utils.CombineErrors(err, planet.Shutdown())
}
planet.Uplinks, err = planet.newNodes(uplinkCount)
planet.Uplinks, err = planet.newNodes("uplink", uplinkCount)
if err != nil {
return nil, utils.CombineErrors(err, planet.Shutdown())
}
@ -79,7 +90,7 @@ func New(satelliteCount, storageNodeCount, uplinkCount int) (*Planet, error) {
for _, node := range planet.Satellites {
server := pointerdb.NewServer(
teststore.New(), node.Overlay,
zap.NewNop(),
node.Log.Named("pdb"),
pointerdb.Config{
MinRemoteSegmentSize: 1240,
MaxInlineSegmentSize: 8000,
@ -156,7 +167,7 @@ func (planet *Planet) Shutdown() error {
}
// newNode creates a new node.
func (planet *Planet) newNode() (*Node, error) {
func (planet *Planet) newNode(name string) (*Node, error) {
identity, err := planet.newIdentity()
if err != nil {
return nil, err
@ -168,6 +179,7 @@ func (planet *Planet) newNode() (*Node, error) {
}
node := &Node{
Log: planet.log.Named(name),
Identity: identity,
Listener: listener,
}
@ -195,10 +207,10 @@ func (planet *Planet) newNode() (*Node, error) {
}
// newNodes creates initializes multiple nodes
func (planet *Planet) newNodes(count int) ([]*Node, error) {
func (planet *Planet) newNodes(prefix string, count int) ([]*Node, error) {
var xs []*Node
for i := 0; i < count; i++ {
node, err := planet.newNode()
node, err := planet.newNode(prefix + strconv.Itoa(i))
if err != nil {
return nil, err
}

View File

@ -13,7 +13,7 @@ import (
func TestBasic(t *testing.T) {
t.Log("New")
planet, err := testplanet.New(2, 4, 1)
planet, err := testplanet.New(t, 2, 4, 1)
if err != nil {
t.Fatal(err)
}
@ -55,7 +55,7 @@ func BenchmarkCreate(b *testing.B) {
b.Run(strconv.Itoa(count), func(b *testing.B) {
ctx := context.Background()
for i := 0; i < b.N; i++ {
planet, err := testplanet.New(1, count, 1)
planet, err := testplanet.New(nil, 1, count, 1)
if err != nil {
b.Fatal(err)
}

View File

@ -313,7 +313,7 @@ func runTest(t *testing.T, test func(context.Context, *DB)) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
planet, err := testplanet.New(1, 4, 1)
planet, err := testplanet.New(t, 1, 4, 1)
if !assert.NoError(t, err) {
return
}