diff --git a/test/performance/Earthfile b/test/performance/Earthfile index 685823a70..424948bd7 100644 --- a/test/performance/Earthfile +++ b/test/performance/Earthfile @@ -5,7 +5,7 @@ IMPORT github.com/formancehq/earthly:tags/v0.16.2 AS core run: LOCALLY ARG args="" - RUN go test -bench="Write" -run ^$ -tags it -report.file ./report/report.json -timeout 60m $args + RUN go test -bench="Write" -run ^$ -tags it,local -report.file ./report/report.json -timeout 60m $args generate-graphs: FROM core+base-image diff --git a/test/performance/README.md b/test/performance/README.md index 614e48f96..8aef6bbaf 100644 --- a/test/performance/README.md +++ b/test/performance/README.md @@ -5,10 +5,7 @@ The benchmarks also test the minimal set of features and the full set of feature Refer to [features](../../CONTRIBUTING.md/#features) for more information about features. -Three types of script are actually tested: -* world->bank : A transaction from `@world` to `@bank` -* world->any : A transaction from `@world` to `@dst:` -* any(unbounded)->any : A transaction from `@src:` to `@dst:` +Scripts can be found in directory [scripts](./scripts). ## Run locally diff --git a/test/performance/env_test.go b/test/performance/env_test.go index 5a573c272..4c7a9ecf7 100644 --- a/test/performance/env_test.go +++ b/test/performance/env_test.go @@ -10,15 +10,6 @@ import ( ledger "github.com/formancehq/ledger/internal" ) -type TransactionExecutor interface { - ExecuteScript(context.Context, string, map[string]string) (*ledger.Transaction, error) -} -type TransactionExecutorFn func(context.Context, string, map[string]string) (*ledger.Transaction, error) - -func (fn TransactionExecutorFn) ExecuteScript(ctx context.Context, script string, vars map[string]string) (*ledger.Transaction, error) { - return fn(ctx, script, vars) -} - type Env interface { Client() *ledgerclient.Formance URL() string diff --git a/test/performance/env_testserver_test.go b/test/performance/env_testserver_test.go index 61c248e97..6c87c8766 100644 --- a/test/performance/env_testserver_test.go +++ b/test/performance/env_testserver_test.go @@ -1,13 +1,16 @@ -//go:build it +//go:build it && local package performance_test import ( "context" + "github.com/formancehq/go-libs/v2/logging" "github.com/formancehq/go-libs/v2/otlp/otlpmetrics" + "github.com/formancehq/go-libs/v2/testing/docker" ledgerclient "github.com/formancehq/ledger/pkg/client" "io" "os" + "sync" "testing" "github.com/formancehq/go-libs/v2/pointer" @@ -40,12 +43,22 @@ func (e *TestServerEnv) Stop(ctx context.Context) error { var _ Env = (*TestServerEnv)(nil) type TestServerEnvFactory struct { - pgServer *pgtesting.PostgresServer + dockerPool *docker.Pool + + once sync.Once } func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger ledger.Ledger) Env { - db := f.pgServer.NewDatabase(b) + f.once.Do(func() { + // Configure the environment to run benchmarks locally. + // Start a docker connection + f.dockerPool = docker.NewPool(b, logging.Testing()) + }) + + pgServer := pgtesting.CreatePostgresServer(b, f.dockerPool, pgtesting.WithPGCrypto()) + + db := pgServer.NewDatabase(b) b.Logf("database: %s", db.Name()) connectionOptions := db.ConnectionOptions() connectionOptions.MaxOpenConns = 100 @@ -89,8 +102,10 @@ func (f *TestServerEnvFactory) Create(ctx context.Context, b *testing.B, ledger var _ EnvFactory = (*TestServerEnvFactory)(nil) -func NewTestServerEnvFactory(pgServer *pgtesting.PostgresServer) *TestServerEnvFactory { - return &TestServerEnvFactory{ - pgServer: pgServer, - } +func NewTestServerEnvFactory() *TestServerEnvFactory { + return &TestServerEnvFactory{} +} + +func init() { + envFactory = NewTestServerEnvFactory() } diff --git a/test/performance/main_test.go b/test/performance/main_test.go index 2b049c8b5..b20e2b776 100644 --- a/test/performance/main_test.go +++ b/test/performance/main_test.go @@ -6,9 +6,6 @@ import ( "context" "crypto/tls" "flag" - "github.com/formancehq/go-libs/v2/logging" - "github.com/formancehq/go-libs/v2/testing/docker" - "github.com/formancehq/go-libs/v2/testing/platform/pgtesting" . "github.com/formancehq/go-libs/v2/testing/utils" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" @@ -17,9 +14,6 @@ import ( ) var ( - dockerPool *docker.Pool - pgServer *Deferred[*pgtesting.PostgresServer] - authClientID string authClientSecret string @@ -50,14 +44,7 @@ func TestMain(m *testing.M) { flag.Parse() WithTestMain(func(t *TestingTForMain) int { - selectedEnv := 0 - if stackURL != "" { - selectedEnv++ - } - if ledgerURL != "" { - selectedEnv++ - } - if selectedEnv > 1 { + if stackURL != "" && ledgerURL != "" { t.Errorf("Cannot specify both --stack.url and --ledger.url") t.FailNow() } @@ -67,23 +54,13 @@ func TestMain(m *testing.M) { envFactory = NewRemoteLedgerEnvFactory(getHttpClient(stackURL+"/api/auth"), stackURL+"/api/ledger") case ledgerURL != "": envFactory = NewRemoteLedgerEnvFactory(getHttpClient(authIssuerURL), ledgerURL) - default: - // Configure the environment to run benchmarks locally. - // Start a docker connection and create a new postgres server. - dockerPool = docker.NewPool(t, logging.Testing()) - - pgServer = NewDeferred[*pgtesting.PostgresServer]() - pgServer.LoadAsync(func() *pgtesting.PostgresServer { - return pgtesting.CreatePostgresServer( - t, - dockerPool, - pgtesting.WithPGCrypto(), - ) - }) - - Wait(pgServer) - - envFactory = NewTestServerEnvFactory(pgServer.GetValue()) + } + + testing.Verbose() + + if envFactory == nil { + t.Errorf("no env selected, you need to specify either --stack.url or --ledger.url\n") + t.FailNow() } return m.Run()