2019-02-04 20:37:46 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet
|
|
|
|
|
|
|
|
import (
|
2020-05-26 09:05:43 +01:00
|
|
|
"context"
|
2020-10-29 11:58:36 +00:00
|
|
|
"runtime/pprof"
|
2020-06-11 10:37:13 +01:00
|
|
|
"strings"
|
2019-02-04 20:37:46 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2020-04-27 20:34:42 +01:00
|
|
|
"storj.io/storj/private/dbutil/pgtest"
|
2019-02-04 20:37:46 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2020-05-26 09:05:43 +01:00
|
|
|
"storj.io/uplink"
|
2019-02-04 20:37:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run runs testplanet in multiple configurations.
|
|
|
|
func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.Context, planet *Planet)) {
|
2020-04-27 20:34:42 +01:00
|
|
|
databases := satellitedbtest.Databases()
|
|
|
|
hasDatabase := false
|
|
|
|
for _, db := range databases {
|
2020-06-09 10:29:55 +01:00
|
|
|
hasDatabase = hasDatabase || (db.MasterDB.URL != "" && db.MasterDB.URL != "omit")
|
2020-04-27 20:34:42 +01:00
|
|
|
}
|
|
|
|
if !hasDatabase {
|
|
|
|
t.Fatal("Databases flag missing, set at least one:\n" +
|
|
|
|
"-postgres-test-db=" + pgtest.DefaultPostgres + "\n" +
|
|
|
|
"-cockroach-test-db=" + pgtest.DefaultCockroach)
|
|
|
|
}
|
|
|
|
|
2019-02-04 20:37:46 +00:00
|
|
|
for _, satelliteDB := range satellitedbtest.Databases() {
|
2019-02-06 09:16:05 +00:00
|
|
|
satelliteDB := satelliteDB
|
2020-06-11 10:37:13 +01:00
|
|
|
if strings.EqualFold(satelliteDB.MasterDB.URL, "omit") {
|
2020-06-09 10:29:55 +01:00
|
|
|
continue
|
|
|
|
}
|
2020-04-27 17:28:40 +01:00
|
|
|
t.Run(satelliteDB.Name, func(t *testing.T) {
|
2020-02-27 13:31:05 +00:00
|
|
|
parallel := !config.NonParallel
|
|
|
|
if parallel {
|
|
|
|
t.Parallel()
|
|
|
|
}
|
2019-02-05 19:44:00 +00:00
|
|
|
|
2019-02-04 20:37:46 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-10-04 15:12:21 +01:00
|
|
|
if satelliteDB.MasterDB.URL == "" {
|
|
|
|
t.Skipf("Database %s connection string not provided. %s", satelliteDB.MasterDB.Name, satelliteDB.MasterDB.Message)
|
2019-02-04 20:37:46 +00:00
|
|
|
}
|
2020-04-27 20:34:42 +01:00
|
|
|
|
2019-02-04 20:37:46 +00:00
|
|
|
planetConfig := config
|
2020-03-27 16:18:19 +00:00
|
|
|
if planetConfig.Name == "" {
|
|
|
|
planetConfig.Name = t.Name()
|
2019-10-04 15:12:21 +01:00
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
pprof.Do(ctx, pprof.Labels("planet", planetConfig.Name), func(namedctx context.Context) {
|
2020-10-27 11:12:40 +00:00
|
|
|
planet, err := NewCustom(namedctx, newLogger(t), planetConfig, satelliteDB)
|
2020-10-29 11:58:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
2019-02-04 20:37:46 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
planet.Start(namedctx)
|
2019-04-22 10:07:50 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
provisionUplinks(namedctx, t, planet)
|
2020-05-26 09:05:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
test(t, ctx, planet)
|
|
|
|
})
|
2019-02-04 20:37:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-05-26 09:05:43 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|