Skip to content

Commit

Permalink
fix: add conditional postgres test (#4)
Browse files Browse the repository at this point in the history
* fix: add conditional postgres test

* fix: multi instance bug
  • Loading branch information
Mahanmmi authored Dec 8, 2024
1 parent f632cfc commit a1e5882
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ jobs:
run: protoc --go_out=. --go-grpc_out=. -I ./submodules/durabletask-protobuf/protos orchestrator_service.proto

- name: Run integration tests
env:
POSTGRES_ENABLED: "true"
run: go test ./tests/... -coverpkg ./api,./task,./client,./backend/...,./internal/helpers
3 changes: 3 additions & 0 deletions backend/postgres/REAEDME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Postgres Backend
### Testing
By default, the postgres tests are skipped. To run the tests, set the environment variable `POSTGRES_ENABLED` to `true` before running the tests and have a postgres server running on `localhost:5432` with a database named `postgres` and a user `postgres` with password `postgres`.
18 changes: 14 additions & 4 deletions tests/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/microsoft/durabletask-go/backend/postgres"
"os"
"reflect"
"runtime"
"testing"
Expand All @@ -26,12 +27,21 @@ var (
sqliteFileOptions = sqlite.NewSqliteOptions("test.sqlite3")
)

var backends = []backend.Backend{
sqlite.NewSqliteBackend(sqliteFileOptions, logger),
sqlite.NewSqliteBackend(sqliteInMemoryOptions, logger),
postgres.NewPostgresBackend(nil, logger), // Requires a local Postgres instance running with host=localhost, port=5432, user=postgres, password=postgres, dbname=postgres.
func getRunnableBackends() []backend.Backend {
var runnableBackends []backend.Backend

runnableBackends = append(runnableBackends, sqlite.NewSqliteBackend(sqliteFileOptions, logger))
runnableBackends = append(runnableBackends, sqlite.NewSqliteBackend(sqliteInMemoryOptions, logger))

if os.Getenv("POSTGRES_ENABLED") == "true" {
runnableBackends = append(runnableBackends, postgres.NewPostgresBackend(nil, logger))
}

return runnableBackends
}

var backends = getRunnableBackends()

var completionStatusValues = []protos.OrchestrationStatus{
protos.OrchestrationStatus_ORCHESTRATION_STATUS_COMPLETED,
protos.OrchestrationStatus_ORCHESTRATION_STATUS_TERMINATED,
Expand Down

0 comments on commit a1e5882

Please sign in to comment.