Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e integration tests for Postgres and remove 2dc runs #3532

Merged
merged 15 commits into from
Sep 22, 2020
28 changes: 14 additions & 14 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,67 @@ steps:
run: integration-test-cassandra
config: docker/buildkite/docker-compose.yml

- label: ":golang: integration xdc test with cassandra"
- label: ":golang: integration ndc test with cassandra"
agents:
queue: "workers"
docker: "*"
command: "make cover_xdc_profile"
command: "make cover_ndc_profile"
artifact_paths:
- "build/coverage/*.out"
retry:
automatic:
limit: 1
plugins:
- docker-compose#v3.0.0:
run: integration-test-xdc-cassandra
run: integration-test-ndc-cassandra
config: docker/buildkite/docker-compose.yml

- label: ":golang: integration ndc test with cassandra"
- label: ":golang: integration test with mysql"
agents:
queue: "workers"
docker: "*"
command: "make cover_ndc_profile"
command: "make cover_integration_profile"
artifact_paths:
- "build/coverage/*.out"
retry:
automatic:
limit: 1
plugins:
- docker-compose#v3.0.0:
run: integration-test-xdc-cassandra
run: integration-test-mysql
config: docker/buildkite/docker-compose.yml

- label: ":golang: integration test with mysql"
- label: ":golang: integration ndc test with mysql"
agents:
queue: "workers"
docker: "*"
command: "make cover_integration_profile"
command: "make cover_ndc_profile"
artifact_paths:
- "build/coverage/*.out"
retry:
automatic:
limit: 1
plugins:
- docker-compose#v3.0.0:
run: integration-test-mysql
run: integration-test-ndc-mysql
config: docker/buildkite/docker-compose.yml

- label: ":golang: integration xdc test with mysql"
- label: ":golang: integration test with postgres"
agents:
queue: "workers"
docker: "*"
command: "make cover_xdc_profile"
command: "make cover_integration_profile"
artifact_paths:
- "build/coverage/*.out"
retry:
automatic:
limit: 1
plugins:
- docker-compose#v3.0.0:
run: integration-test-xdc-mysql
run: integration-test-postgres
config: docker/buildkite/docker-compose.yml

- label: ":golang: integration ndc test with mysql"
- label: ":golang: integration ndc test with postgres"
agents:
queue: "workers"
docker: "*"
Expand All @@ -103,7 +103,7 @@ steps:
limit: 1
plugins:
- docker-compose#v3.0.0:
run: integration-test-xdc-mysql
run: integration-test-ndc-postgres
config: docker/buildkite/docker-compose.yml

- wait
Expand Down
56 changes: 26 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ INTEG_TEST_NDC_DIR=hostndc
GO_BUILD_LDFLAGS_CMD := $(abspath ./scripts/go-build-ldflags.sh)
GO_BUILD_LDFLAGS := $(shell $(GO_BUILD_LDFLAGS_CMD) LDFLAG)

# TODO to be consistent, use nosql as PERSISTENCE_TYPE and cassandra PERSISTENCE_PLUGIN
# file names like integ_cassandra__cover should become integ_nosql_cassandra_cover
# for https://github.com/uber/cadence/issues/3514
ifndef PERSISTENCE_TYPE
override PERSISTENCE_TYPE = cassandra
endif
Expand Down Expand Up @@ -85,17 +88,18 @@ TEST_DIRS := $(filter-out $(INTEG_TEST_XDC_ROOT)%, $(sort $(dir $(filter %_test.
PKG_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)%,$(TEST_DIRS))

# Code coverage output files
COVER_ROOT := $(BUILD)/coverage
UNIT_COVER_FILE := $(COVER_ROOT)/unit_cover.out
INTEG_COVER_FILE := $(COVER_ROOT)/integ_$(PERSISTENCE_TYPE)_cover.out
INTEG_XDC_COVER_FILE := $(COVER_ROOT)/integ_xdc_$(PERSISTENCE_TYPE)_cover.out
INTEG_CASS_COVER_FILE := $(COVER_ROOT)/integ_cassandra_cover.out
INTEG_XDC_CASS_COVER_FILE := $(COVER_ROOT)/integ_xdc_cassandra_cover.out
INTEG_SQL_COVER_FILE := $(COVER_ROOT)/integ_sql_cover.out
INTEG_XDC_SQL_COVER_FILE := $(COVER_ROOT)/integ_xdc_sql_cover.out
INTEG_NDC_COVER_FILE := $(COVER_ROOT)/integ_ndc_$(PERSISTENCE_TYPE)_cover.out
INTEG_NDC_CASS_COVER_FILE := $(COVER_ROOT)/integ_ndc_cassandra_cover.out
INTEG_NDC_SQL_COVER_FILE := $(COVER_ROOT)/integ_ndc_sql_cover.out
COVER_ROOT := $(BUILD)/coverage
UNIT_COVER_FILE := $(COVER_ROOT)/unit_cover.out

INTEG_COVER_FILE := $(COVER_ROOT)/integ_$(PERSISTENCE_TYPE)_$(PERSISTENCE_PLUGIN)_cover.out
INTEG_COVER_FILE_CASS := $(COVER_ROOT)/integ_cassandra__cover.out
INTEG_COVER_FILE_MYSQL := $(COVER_ROOT)/integ_sql_mysql_cover.out
INTEG_COVER_FILE_POSTGRES := $(COVER_ROOT)/integ_sql_postgres_cover.out

INTEG_NDC_COVER_FILE := $(COVER_ROOT)/integ_ndc_$(PERSISTENCE_TYPE)_$(PERSISTENCE_PLUGIN)_cover.out
INTEG_NDC_COVER_FILE_CASS := $(COVER_ROOT)/integ_ndc_cassandra__cover.out
INTEG_NDC_COVER_FILE_MYSQL := $(COVER_ROOT)/integ_ndc_sql_mysql_cover.out
INTEG_NDC_COVER_FILE_POSTGRES := $(COVER_ROOT)/integ_ndc_sql_postgres_cover.out

# Need the following option to have integration tests
# count towards coverage. godoc below:
Expand Down Expand Up @@ -206,38 +210,30 @@ cover_integration_profile: clean bins_nothrift
@mkdir -p $(COVER_ROOT)
@echo "mode: atomic" > $(INTEG_COVER_FILE)

@echo Running integration test with $(PERSISTENCE_TYPE)
@echo Running integration test with $(PERSISTENCE_TYPE) $(PERSISTENCE_PLUGIN)
@mkdir -p $(BUILD)/$(INTEG_TEST_DIR)
@time go test $(INTEG_TEST_ROOT) $(TEST_ARG) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/$(INTEG_TEST_DIR)/coverage.out || exit 1;
@time go test $(INTEG_TEST_ROOT) $(TEST_ARG) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -sqlPluginName=$(PERSISTENCE_PLUGIN) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/$(INTEG_TEST_DIR)/coverage.out || exit 1;
@cat $(BUILD)/$(INTEG_TEST_DIR)/coverage.out | grep -v "^mode: \w\+" >> $(INTEG_COVER_FILE)

cover_xdc_profile: clean bins_nothrift
@mkdir -p $(BUILD)
@mkdir -p $(COVER_ROOT)
@echo "mode: atomic" > $(INTEG_XDC_COVER_FILE)

@echo Running integration test for cross dc with $(PERSISTENCE_TYPE)
@mkdir -p $(BUILD)/$(INTEG_TEST_XDC_DIR)
@time go test -v -timeout $(TEST_TIMEOUT) $(INTEG_TEST_XDC_ROOT) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/$(INTEG_TEST_XDC_DIR)/coverage.out || exit 1;
@cat $(BUILD)/$(INTEG_TEST_XDC_DIR)/coverage.out | grep -v "^mode: \w\+" | grep -v "mode: set" >> $(INTEG_XDC_COVER_FILE)

cover_ndc_profile: clean bins_nothrift
@mkdir -p $(BUILD)
@mkdir -p $(COVER_ROOT)
@echo "mode: atomic" > $(INTEG_NDC_COVER_FILE)

@echo Running integration test for 3+ dc with $(PERSISTENCE_TYPE)
@echo Running integration test for 3+ dc with $(PERSISTENCE_TYPE) $(PERSISTENCE_PLUGIN)
@mkdir -p $(BUILD)/$(INTEG_TEST_NDC_DIR)
@time go test -v -timeout $(TEST_TIMEOUT) $(INTEG_TEST_NDC_ROOT) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/$(INTEG_TEST_NDC_DIR)/coverage.out -count=$(TEST_RUN_COUNT) || exit 1;
@time go test -v -timeout $(TEST_TIMEOUT) $(INTEG_TEST_NDC_ROOT) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -sqlPluginName=$(PERSISTENCE_PLUGIN) $(GOCOVERPKG_ARG) -coverprofile=$(BUILD)/$(INTEG_TEST_NDC_DIR)/coverage.out -count=$(TEST_RUN_COUNT) || exit 1;
@cat $(BUILD)/$(INTEG_TEST_NDC_DIR)/coverage.out | grep -v "^mode: \w\+" | grep -v "mode: set" >> $(INTEG_NDC_COVER_FILE)

$(COVER_ROOT)/cover.out: $(UNIT_COVER_FILE) $(INTEG_CASS_COVER_FILE) $(INTEG_XDC_CASS_COVER_FILE) $(INTEG_SQL_COVER_FILE) $(INTEG_XDC_SQL_COVER_FILE)
$(COVER_ROOT)/cover.out: $(UNIT_COVER_FILE) $(INTEG_COVER_FILE_CASS) $(INTEG_COVER_FILE_MYSQL) $(INTEG_COVER_FILE_POSTGRES) $(INTEG_NDC_COVER_FILE_CASS) $(INTEG_NDC_COVER_FILE_MYSQL) $(INTEG_NDC_COVER_FILE_POSTGRES)
@echo "mode: atomic" > $(COVER_ROOT)/cover.out
cat $(UNIT_COVER_FILE) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_CASS_COVER_FILE) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_XDC_CASS_COVER_FILE) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_SQL_COVER_FILE) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_XDC_SQL_COVER_FILE) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_COVER_FILE_CASS) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_COVER_FILE_MYSQL) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_COVER_FILE_POSTGRES) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_NDC_COVER_FILE_CASS) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_NDC_COVER_FILE_MYSQL) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out
cat $(INTEG_NDC_COVER_FILE_POSTGRES) | grep -v "^mode: \w\+" | grep -vP ".gen|[Mm]ock[s]?" >> $(COVER_ROOT)/cover.out

cover: $(COVER_ROOT)/cover.out
go tool cover -html=$(COVER_ROOT)/cover.out;
Expand Down
37 changes: 37 additions & 0 deletions common/persistence/sql/sqlplugin/postgres/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"errors"
"fmt"
"net"
"os"
"runtime"

pt "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/environment"

"github.com/iancoleman/strcase"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -112,3 +117,35 @@ func registerTLSConfig(cfg *config.SQL) error {
}
return errTLSNotImplemented
}

const (
testSchemaDir = "schema/postgres"
)

// GetTestClusterOption return test options
func GetTestClusterOption() *pt.TestBaseOptions {
testUser := "postgres"
testPassword := "cadence"

if runtime.GOOS == "darwin" {
testUser = os.Getenv("USER")
testPassword = ""
}

if os.Getenv("POSTGRES_USER") != "" {
testUser = os.Getenv("POSTGRES_USER")
}

if os.Getenv("POSTGRES_PASSWORD") != "" {
testUser = os.Getenv("POSTGRES_PASSWORD")
}

return &pt.TestBaseOptions{
SQLDBPluginName: PluginName,
DBUsername: testUser,
DBPassword: testPassword,
DBHost: environment.GetPostgresAddress(),
DBPort: environment.GetPostgresPort(),
SchemaDir: testSchemaDir,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,92 +21,58 @@
package postgres

import (
"os"
"runtime"
"testing"

"github.com/stretchr/testify/suite"

pt "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/environment"
)

const (
testSchemaDir = "schema/postgres"
)

func getTestClusterOption() *pt.TestBaseOptions {
testUser := "postgres"
testPassword := "cadence"

if runtime.GOOS == "darwin" {
testUser = os.Getenv("USER")
testPassword = ""
}

if os.Getenv("POSTGRES_USER") != "" {
testUser = os.Getenv("POSTGRES_USER")
}

if os.Getenv("POSTGRES_PASSWORD") != "" {
testUser = os.Getenv("POSTGRES_PASSWORD")
}

return &pt.TestBaseOptions{
SQLDBPluginName: PluginName,
DBUsername: testUser,
DBPassword: testPassword,
DBHost: environment.GetPostgresAddress(),
DBPort: environment.GetPostgresPort(),
SchemaDir: testSchemaDir,
}
}

func TestSQLHistoryV2PersistenceSuite(t *testing.T) {
s := new(pt.HistoryV2PersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLMatchingPersistenceSuite(t *testing.T) {
s := new(pt.MatchingPersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLMetadataPersistenceSuiteV2(t *testing.T) {
s := new(pt.MetadataPersistenceSuiteV2)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLShardPersistenceSuite(t *testing.T) {
s := new(pt.ShardPersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLExecutionManagerSuite(t *testing.T) {
s := new(pt.ExecutionManagerSuite)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLExecutionManagerWithEventsV2(t *testing.T) {
s := new(pt.ExecutionManagerSuiteForEventsV2)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLVisibilityPersistenceSuite(t *testing.T) {
s := new(pt.VisibilityPersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}
Expand All @@ -124,7 +90,7 @@ FAIL: TestSQLQueuePersistence/TestDomainReplicationQueue (0.26s)
*/
//func TestSQLQueuePersistence(t *testing.T) {
// s := new(pt.QueuePersistenceSuite)
// s.TestBase = pt.NewTestBaseWithSQL(getTestClusterOption())
// s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
// s.TestBase.Setup()
// suite.Run(t, s)
//}
4 changes: 2 additions & 2 deletions docker/buildkite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ docker-compose -f docker/buildkite/docker-compose-local.yml build integration-te

cross DC integration tests:
```bash
docker-compose -f docker/buildkite/docker-compose-local.yml build integration-test-xdc-cassandra
docker-compose -f docker/buildkite/docker-compose-local.yml build integration-test-ndc-cassandra
```

Run the integration tests:
Expand All @@ -40,7 +40,7 @@ docker-compose -f docker/buildkite/docker-compose-local.yml run integration-test

cross DC integration tests:
```bash
docker-compose -f docker/buildkite/docker-compose-local.yml run integration-test-xdc-cassandra
docker-compose -f docker/buildkite/docker-compose-local.yml run integration-test-ndc-cassandra
```

Note that BuildKite will run basically the same commands.
Expand Down
Loading