satellite/metabase/metabasetest: remove STORJ_TEST_DATABASES

Initially metabase was developed separately and it was useful to have a
separate environment flag for tests, however, it's more convenient to
use the same as rest of the testsuite.

Change-Id: Ia4d79be27ce5911cbae68d57cdf0b30f63459444
This commit is contained in:
Egon Elbre 2021-05-11 13:08:06 +03:00
parent a11698f370
commit 2ae80690cb
5 changed files with 23 additions and 73 deletions

View File

@ -71,7 +71,6 @@ pipeline {
'cockroach://root@localhost:26259/testcockroach?sslmode=disable'
STORJ_TEST_COCKROACH_ALT = 'cockroach://root@localhost:26260/testcockroach?sslmode=disable'
STORJ_TEST_POSTGRES = 'postgres://postgres@localhost/teststorj?sslmode=disable'
STORJ_TEST_DATABASES = 'crdb|pgx|cockroach://root@localhost:26259/testmetabase?sslmode=disable;pg|pgx|postgres://postgres@localhost/testmetabase?sslmode=disable'
COVERFLAGS = "${ env.BRANCH_NAME == 'main' ? '-coverprofile=.build/coverprofile -coverpkg=storj.io/storj/private/...,storj.io/storj/satellite/...,storj.io/storj/storage/...,storj.io/storj/storagenode/...,storj.io/storj/versioncontrol/...' : ''}"
}
steps {
@ -118,7 +117,6 @@ pipeline {
environment {
STORJ_TEST_COCKROACH = 'cockroach://root@localhost:26256/benchcockroach?sslmode=disable'
STORJ_TEST_POSTGRES = 'postgres://postgres@localhost/benchstorj?sslmode=disable'
STORJ_TEST_DATABASES = 'crdb|pgx|cockroach://root@localhost:26256/benchcockroach?sslmode=disable;pg|pgx|postgres://postgres@localhost/benchstorj?sslmode=disable'
}
steps {
sh 'cockroach sql --insecure --host=localhost:26256 -e \'create database benchcockroach;\''

View File

@ -179,9 +179,6 @@ func test(t *testing.T, prepare func(t *testing.T, ctx context.Context, rawDB *d
for _, satelliteDB := range satellitedbtest.Databases() {
satelliteDB := satelliteDB
if strings.EqualFold(satelliteDB.MasterDB.URL, "omit") {
continue
}
t.Run(satelliteDB.Name, func(t *testing.T) {
schemaSuffix := satellitedbtest.SchemaSuffix()
schema := satellitedbtest.SchemaName(t.Name(), "category", 0, schemaSuffix)

View File

@ -6,7 +6,6 @@ package testplanet
import (
"context"
"runtime/pprof"
"strings"
"testing"
"storj.io/common/testcontext"
@ -18,21 +17,14 @@ import (
// 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 {
if len(databases) == 0 {
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() {
for _, satelliteDB := range databases {
satelliteDB := satelliteDB
if strings.EqualFold(satelliteDB.MasterDB.URL, "omit") {
continue
}
t.Run(satelliteDB.Name, func(t *testing.T) {
parallel := !config.NonParallel
if parallel {

View File

@ -4,9 +4,6 @@
package metabasetest
import (
"flag"
"os"
"strings"
"testing"
"go.uber.org/zap/zaptest"
@ -16,46 +13,17 @@ import (
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
var databasesFlag = flag.String("databases", os.Getenv("STORJ_TEST_DATABASES"), "databases to use for testing")
// Database contains info about a test database connection.
type Database struct {
Name string
Driver string
ConnStr string
}
// DatabaseEntries returns databases passed in with -databases or STORJ_TEST_DATABASES flag.
func DatabaseEntries() []Database {
infos := []Database{
{"pg", "pgx", "postgres://storj:storj-pass@localhost/metabase?sslmode=disable"},
{"crdb", "pgx", "cockroach://root@localhost:26257/metabase?sslmode=disable"},
}
if *databasesFlag != "" {
infos = nil
for _, db := range strings.Split(*databasesFlag, ";") {
toks := strings.Split(strings.TrimSpace(db), "|")
infos = append(infos, Database{toks[0], toks[1], toks[2]})
}
}
return infos
}
// Run runs tests against all configured databases.
func Run(t *testing.T, fn func(ctx *testcontext.Context, t *testing.T, db *metabase.DB)) {
for _, info := range DatabaseEntries() {
info := info
t.Run(info.Name, func(t *testing.T) {
for _, dbinfo := range satellitedbtest.Databases() {
dbinfo := dbinfo
t.Run(dbinfo.Name, func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()
db, err := satellitedbtest.CreateMetabaseDB(ctx, zaptest.NewLogger(t), t.Name(), "M", 0, satellitedbtest.Database{
Name: info.Name,
URL: info.ConnStr,
Message: "",
})
db, err := satellitedbtest.CreateMetabaseDB(ctx, zaptest.NewLogger(t), t.Name(), "M", 0, dbinfo.MetabaseDB)
if err != nil {
t.Fatal(err)
}
@ -76,17 +44,13 @@ func Run(t *testing.T, fn func(ctx *testcontext.Context, t *testing.T, db *metab
// Bench runs benchmark for all configured databases.
func Bench(b *testing.B, fn func(ctx *testcontext.Context, b *testing.B, db *metabase.DB)) {
for _, info := range DatabaseEntries() {
info := info
b.Run(info.Name, func(b *testing.B) {
for _, dbinfo := range satellitedbtest.Databases() {
dbinfo := dbinfo
b.Run(dbinfo.Name, func(b *testing.B) {
ctx := testcontext.New(b)
defer ctx.Cleanup()
db, err := satellitedbtest.CreateMetabaseDB(ctx, zaptest.NewLogger(b), b.Name(), "M", 0, satellitedbtest.Database{
Name: info.Name,
URL: info.ConnStr,
Message: "",
})
db, err := satellitedbtest.CreateMetabaseDB(ctx, zaptest.NewLogger(b), b.Name(), "M", 0, dbinfo.MetabaseDB)
if err != nil {
b.Fatal(err)
}

View File

@ -46,20 +46,27 @@ func (ignoreSkip) Skip(...interface{}) {}
// Databases returns default databases.
func Databases() []SatelliteDatabases {
cockroachConnStr := pgtest.PickCockroach(ignoreSkip{})
var dbs []SatelliteDatabases
postgresConnStr := pgtest.PickPostgres(ignoreSkip{})
return []SatelliteDatabases{
{
if !strings.EqualFold(postgresConnStr, "omit") {
dbs = append(dbs, SatelliteDatabases{
Name: "Postgres",
MasterDB: Database{"Postgres", postgresConnStr, "Postgres flag missing, example: -postgres-test-db=" + pgtest.DefaultPostgres + " or use STORJ_TEST_POSTGRES environment variable."},
MetabaseDB: Database{"Postgres", postgresConnStr, ""},
},
{
})
}
cockroachConnStr := pgtest.PickCockroach(ignoreSkip{})
if !strings.EqualFold(cockroachConnStr, "omit") {
dbs = append(dbs, SatelliteDatabases{
Name: "Cockroach",
MasterDB: Database{"Cockroach", cockroachConnStr, "Cockroach flag missing, example: -cockroach-test-db=" + pgtest.DefaultCockroach + " or use STORJ_TEST_COCKROACH environment variable."},
MetabaseDB: Database{"Cockroach", cockroachConnStr, ""},
},
})
}
return dbs
}
// SchemaSuffix returns a suffix for schemas.
@ -168,10 +175,6 @@ func CreateMetabaseDBOnTopOf(ctx context.Context, log *zap.Logger, tempDB *dbuti
func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db satellite.DB)) {
for _, dbInfo := range Databases() {
dbInfo := dbInfo
if strings.EqualFold(dbInfo.MasterDB.URL, "omit") {
continue
}
t.Run(dbInfo.Name, func(t *testing.T) {
t.Parallel()
@ -208,10 +211,6 @@ func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db sate
func Bench(b *testing.B, bench func(b *testing.B, db satellite.DB)) {
for _, dbInfo := range Databases() {
dbInfo := dbInfo
if strings.EqualFold(dbInfo.MasterDB.URL, "omit") {
continue
}
b.Run(dbInfo.Name, func(b *testing.B) {
if dbInfo.MasterDB.URL == "" {
b.Skipf("Database %s connection string not provided. %s", dbInfo.MasterDB.Name, dbInfo.MasterDB.Message)