From a1e5882148b5d8fd06862bd2d18f925f4bd4bb82 Mon Sep 17 00:00:00 2001 From: Mahan Zendedel DH Date: Sun, 8 Dec 2024 10:39:19 +0400 Subject: [PATCH] fix: add conditional postgres test (#4) * fix: add conditional postgres test * fix: multi instance bug --- .github/workflows/pr-validation.yml | 2 ++ backend/postgres/REAEDME.md | 3 +++ tests/backend_test.go | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 backend/postgres/REAEDME.md diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 905264c..c927193 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -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 diff --git a/backend/postgres/REAEDME.md b/backend/postgres/REAEDME.md new file mode 100644 index 0000000..7028284 --- /dev/null +++ b/backend/postgres/REAEDME.md @@ -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`. diff --git a/tests/backend_test.go b/tests/backend_test.go index 0a40008..ff9c22b 100644 --- a/tests/backend_test.go +++ b/tests/backend_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/microsoft/durabletask-go/backend/postgres" + "os" "reflect" "runtime" "testing" @@ -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,