Make testplanet.Run and satellitedbtest.Run parallel by default (#1231)

This commit is contained in:
Egon Elbre 2019-02-05 21:44:00 +02:00 committed by GitHub
parent 0b6e8f0764
commit b5d86aa0b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 30 deletions

View File

@ -148,7 +148,7 @@ func NewWithLogger(log *zap.Logger, satelliteCount, storageNodeCount, uplinkCoun
// NewCustom creates a new full system with the specified configuration.
func NewCustom(log *zap.Logger, config Config) (*Planet, error) {
if config.Identities == nil {
config.Identities = pregeneratedIdentities
config.Identities = pregeneratedIdentities.Clone()
}
planet := &Planet{

View File

@ -26,6 +26,8 @@ func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.C
for _, satelliteDB := range satellitedbtest.Databases() {
t.Run(satelliteDB.Name, func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()

View File

@ -41,16 +41,7 @@ func TestGrapqhlMutation(t *testing.T) {
t.Fatal(err)
}
creator := consoleql.TypeCreator{}
if err = creator.Create(service); err != nil {
t.Fatal(err)
}
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: creator.RootQuery(),
Mutation: creator.RootMutation(),
})
schema, err := consoleql.CreateSchema(service)
if err != nil {
t.Fatal(err)
}

View File

@ -0,0 +1,32 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleql
import (
"sync"
"github.com/graphql-go/graphql"
"storj.io/storj/satellite/console"
)
// creatingSchemaMutex locks graphql.NewSchema method because it's not thread-safe
var creatingSchemaMutex sync.Mutex
// CreateSchema creates both type
func CreateSchema(service *console.Service) (graphql.Schema, error) {
creatingSchemaMutex.Lock()
defer creatingSchemaMutex.Unlock()
creator := TypeCreator{}
err := creator.Create(service)
if err != nil {
return graphql.Schema{}, err
}
return graphql.NewSchema(graphql.SchemaConfig{
Query: creator.RootQuery(),
Mutation: creator.RootMutation(),
})
}

View File

@ -9,7 +9,6 @@ import (
"net"
"net/http"
"path/filepath"
"sync"
"github.com/graphql-go/graphql"
"github.com/zeebo/errs"
@ -122,26 +121,10 @@ func (s *Server) grapqlHandler(w http.ResponseWriter, req *http.Request) {
sugar.Debug(result)
}
var creatingSchema sync.Mutex
// Run starts the server that host webapp and api endpoint
func (s *Server) Run(ctx context.Context) error {
creatingSchema.Lock()
creator := consoleql.TypeCreator{}
err := creator.Create(s.service)
if err != nil {
creatingSchema.Unlock()
return Error.Wrap(err)
}
s.schema, err = graphql.NewSchema(graphql.SchemaConfig{
Query: creator.RootQuery(),
Mutation: creator.RootMutation(),
})
creatingSchema.Unlock()
var err error
s.schema, err = consoleql.CreateSchema(s.service)
if err != nil {
return Error.Wrap(err)
}

View File

@ -63,6 +63,8 @@ func Run(t *testing.T, test func(t *testing.T, db satellite.DB)) {
for _, dbInfo := range Databases() {
t.Run(dbInfo.Name, func(t *testing.T) {
t.Parallel()
if dbInfo.URL == "" {
t.Skipf("Database %s connection string not provided. %s", dbInfo.Name, dbInfo.Message)
}