0c23b12038
Instead of printing RFC3339 timestamp, we'll print relative time since the creation of the testplanet. Before: logger.go:130: 2020-11-02T14:54:53.864+0200 DEBUG versioncontrol addr= 127.0.0.1:30904 After: log.go:54: 00:00.002 DEBUG versioncontrol addr= 127.0.0.1:30945 Change-Id: Ifa423f9d54d4e7c583d9290fe36a791d28166f8f
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information
|
|
|
|
package testplanet
|
|
|
|
import (
|
|
"context"
|
|
"runtime/pprof"
|
|
"strings"
|
|
"testing"
|
|
|
|
"storj.io/common/testcontext"
|
|
"storj.io/storj/private/dbutil/pgtest"
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
"storj.io/uplink"
|
|
)
|
|
|
|
// Run runs testplanet in multiple configurations.
|
|
func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.Context, planet *Planet)) {
|
|
databases := satellitedbtest.Databases()
|
|
hasDatabase := false
|
|
for _, db := range databases {
|
|
hasDatabase = hasDatabase || (db.MasterDB.URL != "" && db.MasterDB.URL != "omit")
|
|
}
|
|
if !hasDatabase {
|
|
t.Fatal("Databases flag missing, set at least one:\n" +
|
|
"-postgres-test-db=" + pgtest.DefaultPostgres + "\n" +
|
|
"-cockroach-test-db=" + pgtest.DefaultCockroach)
|
|
}
|
|
|
|
for _, satelliteDB := range satellitedbtest.Databases() {
|
|
satelliteDB := satelliteDB
|
|
if strings.EqualFold(satelliteDB.MasterDB.URL, "omit") {
|
|
continue
|
|
}
|
|
t.Run(satelliteDB.Name, func(t *testing.T) {
|
|
parallel := !config.NonParallel
|
|
if parallel {
|
|
t.Parallel()
|
|
}
|
|
|
|
ctx := testcontext.New(t)
|
|
defer ctx.Cleanup()
|
|
|
|
if satelliteDB.MasterDB.URL == "" {
|
|
t.Skipf("Database %s connection string not provided. %s", satelliteDB.MasterDB.Name, satelliteDB.MasterDB.Message)
|
|
}
|
|
|
|
planetConfig := config
|
|
if planetConfig.Name == "" {
|
|
planetConfig.Name = t.Name()
|
|
}
|
|
|
|
pprof.Do(ctx, pprof.Labels("planet", planetConfig.Name), func(namedctx context.Context) {
|
|
planet, err := NewCustom(namedctx, newLogger(t), planetConfig, satelliteDB)
|
|
if err != nil {
|
|
t.Fatalf("%+v", err)
|
|
}
|
|
defer ctx.Check(planet.Shutdown)
|
|
|
|
planet.Start(namedctx)
|
|
|
|
provisionUplinks(namedctx, t, planet)
|
|
|
|
test(t, ctx, planet)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func provisionUplinks(ctx context.Context, t *testing.T, planet *Planet) {
|
|
for _, planetUplink := range planet.Uplinks {
|
|
for _, satellite := range planet.Satellites {
|
|
apiKey := planetUplink.APIKey[satellite.ID()]
|
|
access, err := uplink.RequestAccessWithPassphrase(ctx, satellite.URL(), apiKey.Serialize(), "")
|
|
if err != nil {
|
|
t.Fatalf("%+v", err)
|
|
}
|
|
planetUplink.Access[satellite.ID()] = access
|
|
}
|
|
}
|
|
}
|