diff --git a/Makefile b/Makefile index 3ecd5698832..35c5219f253 100644 --- a/Makefile +++ b/Makefile @@ -59,10 +59,14 @@ endef TEST_TIMEOUT := 20m +# TODO: INTEG_TEST should be functional tests INTEG_TEST_ROOT := ./host INTEG_TEST_XDC_ROOT := ./host/xdc INTEG_TEST_NDC_ROOT := ./host/ndc +PERSISTENCE_INTEGRATION_TEST_ROOT := ./common/persistence/tests +DB_TOOL_INTEGRATION_TEST_ROOT := ./tools/tests + PROTO_ROOT := proto PROTO_FILES = $(shell find ./$(PROTO_ROOT)/internal -name "*.proto") PROTO_DIRS = $(sort $(dir $(PROTO_FILES))) @@ -75,7 +79,7 @@ ALL_SCRIPTS := $(shell find . -name "*.sh") # TODO (jeremy): Replace below with build tags and `go test ./...` for targets TEST_DIRS := $(sort $(dir $(filter %_test.go,$(ALL_SRC)))) INTEG_TEST_DIRS := $(filter $(INTEG_TEST_ROOT)/ $(INTEG_TEST_NDC_ROOT)/,$(TEST_DIRS)) -UNIT_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)% $(INTEG_TEST_XDC_ROOT)% $(INTEG_TEST_NDC_ROOT)%,$(TEST_DIRS)) +UNIT_TEST_DIRS := $(filter-out $(INTEG_TEST_ROOT)% $(INTEG_TEST_XDC_ROOT)% $(INTEG_TEST_NDC_ROOT)% $(PERSISTENCE_INTEGRATION_TEST_ROOT)% $(DB_TOOL_INTEGRATION_TEST_ROOT)%,$(TEST_DIRS)) # go.opentelemetry.io/otel/sdk/metric@v0.31.0 - there are breaking changes in v0.32.0. # github.com/urfave/cli/v2@v2.4.0 - needs to accept comma in values before unlocking https://github.com/urfave/cli/pull/1241. @@ -87,6 +91,8 @@ PINNED_DEPENDENCIES := \ # Code coverage output files. COVER_ROOT := ./.coverage UNIT_COVER_PROFILE := $(COVER_ROOT)/unit_coverprofile.out +INTEGRATION_COVER_PROFILE := $(COVER_ROOT)/integration_coverprofile.out +DB_TOOL_COVER_PROFILE := $(COVER_ROOT)/db_tool_coverprofile.out INTEG_COVER_PROFILE := $(COVER_ROOT)/integ_$(PERSISTENCE_DRIVER)_coverprofile.out INTEG_XDC_COVER_PROFILE := $(COVER_ROOT)/integ_xdc_$(PERSISTENCE_DRIVER)_coverprofile.out INTEG_NDC_COVER_PROFILE := $(COVER_ROOT)/integ_ndc_$(PERSISTENCE_DRIVER)_coverprofile.out @@ -254,32 +260,34 @@ build-tests: @printf $(COLOR) "Build tests..." @go test -exec="true" -count=0 -tags=esintegration $(TEST_DIRS) -unit-test: +unit-test: clean-test-results @printf $(COLOR) "Run unit tests..." - $(foreach UNIT_TEST_DIR,$(UNIT_TEST_DIRS),\ - @go test $(UNIT_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log \ - $(NEWLINE)) + @go test $(UNIT_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log + @! grep -q "^--- FAIL" test.log + +db-integration-test: clean-test-results + @printf $(COLOR) "Run integration tests..." + @go test $(PERSISTENCE_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log + @go test $(DB_TOOL_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log @! grep -q "^--- FAIL" test.log +# TODO: rename it to functional-test integration-test: clean-test-results @printf $(COLOR) "Run integration tests..." - $(foreach INTEG_TEST_DIR,$(INTEG_TEST_DIRS),\ - @go test $(INTEG_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log \ - $(NEWLINE)) + @go test $(INTEG_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race | tee -a test.log # Need to run xdc tests with race detector off because of ringpop bug causing data race issue. @go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) | tee -a test.log @! grep -q "^--- FAIL" test.log +# TODO: rename it to functional-test integration-with-fault-injection-test: clean-test-results @printf $(COLOR) "Run integration tests with fault injection..." - $(foreach INTEG_TEST_DIR,$(INTEG_TEST_DIRS),\ - @go test $(INTEG_TEST_DIR) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race -PersistenceFaultInjectionRate=0.005 | tee -a test.log \ - $(NEWLINE)) + @go test $(INTEG_TEST_DIRS) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -race -PersistenceFaultInjectionRate=0.005 | tee -a test.log # Need to run xdc tests with race detector off because of ringpop bug causing data race issue. @go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -PersistenceFaultInjectionRate=0.005 | tee -a test.log @! grep -q "^--- FAIL" test.log -test: unit-test integration-test integration-with-fault-injection-test +test: unit-test db-integration-test integration-test integration-with-fault-injection-test ##### Coverage ##### $(COVER_ROOT): @@ -288,20 +296,24 @@ $(COVER_ROOT): unit-test-coverage: $(COVER_ROOT) @printf $(COLOR) "Run unit tests with coverage..." @echo "mode: atomic" > $(UNIT_COVER_PROFILE) - $(foreach UNIT_TEST_DIR,$(patsubst ./%/,%,$(UNIT_TEST_DIRS)),\ - @mkdir -p $(COVER_ROOT)/$(UNIT_TEST_DIR); \ - go test ./$(UNIT_TEST_DIR) -timeout=$(TEST_TIMEOUT) -race -coverprofile=$(COVER_ROOT)/$(UNIT_TEST_DIR)/coverprofile.out || exit 1; \ - grep -v -e "^mode: \w\+" $(COVER_ROOT)/$(UNIT_TEST_DIR)/coverprofile.out >> $(UNIT_COVER_PROFILE) || true \ - $(NEWLINE)) + @go test ./$(UNIT_TEST_DIRS) -timeout=$(TEST_TIMEOUT) -race -coverprofile=$(UNIT_COVER_PROFILE) || exit 1; + +db-integration-test-coverage: $(COVER_ROOT) + @printf $(COLOR) "Run integration tests with coverage..." + @go test $(PERSISTENCE_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -coverpkg="./common/..." -coverprofile=$(INTEGRATION_COVER_PROFILE) + @go test $(DB_TOOL_INTEGRATION_TEST_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -coverpkg="./tools/..." -coverprofile=$(DB_TOOL_COVER_PROFILE) +# TODO: rename it to functional-test integration-test-coverage: $(COVER_ROOT) @printf $(COLOR) "Run integration tests with coverage with $(PERSISTENCE_DRIVER) driver..." @go test $(INTEG_TEST_ROOT) -timeout=$(TEST_TIMEOUT) -race $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_COVER_PROFILE) +# TODO: rename it to functional-test integration-test-xdc-coverage: $(COVER_ROOT) @printf $(COLOR) "Run integration test for cross DC with coverage with $(PERSISTENCE_DRIVER) driver..." @go test $(INTEG_TEST_XDC_ROOT) -timeout=$(TEST_TIMEOUT) $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_XDC_COVER_PROFILE) +# TODO: rename it to functional-test integration-test-ndc-coverage: $(COVER_ROOT) @printf $(COLOR) "Run integration test for NDC with coverage with $(PERSISTENCE_DRIVER) driver..." @go test $(INTEG_TEST_NDC_ROOT) -timeout=$(TEST_TIMEOUT) -race $(TEST_TAG) -persistenceType=$(PERSISTENCE_TYPE) -persistenceDriver=$(PERSISTENCE_DRIVER) $(INTEG_TEST_COVERPKG) -coverprofile=$(INTEG_NDC_COVER_PROFILE) diff --git a/common/persistence/persistence-tests/cassandra_test.go b/common/persistence/persistence-tests/cassandra_test.go deleted file mode 100644 index 0488d05b76b..00000000000 --- a/common/persistence/persistence-tests/cassandra_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" -) - -func TestCassandraHistoryV2Persistence(t *testing.T) { - s := new(HistoryV2PersistenceSuite) - s.TestBase = NewTestBaseWithCassandra(&TestBaseOptions{}) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestCassandraMetadataPersistenceV2(t *testing.T) { - s := new(MetadataPersistenceSuiteV2) - s.TestBase = NewTestBaseWithCassandra(&TestBaseOptions{}) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestCassandraQueuePersistence(t *testing.T) { - s := new(QueuePersistenceSuite) - s.TestBase = NewTestBaseWithCassandra(&TestBaseOptions{}) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestCassandraClusterMetadataPersistence(t *testing.T) { - s := new(ClusterMetadataManagerSuite) - s.TestBase = NewTestBaseWithCassandra(&TestBaseOptions{}) - s.TestBase.Setup(nil) - suite.Run(t, s) -} diff --git a/common/persistence/persistence-tests/mysql_test.go b/common/persistence/persistence-tests/mysql_test.go deleted file mode 100644 index 7c67bb8b7fe..00000000000 --- a/common/persistence/persistence-tests/mysql_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" -) - -func TestMySQLHistoryV2PersistenceSuite(t *testing.T) { - s := new(HistoryV2PersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetMySQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestMySQLMetadataPersistenceSuiteV2(t *testing.T) { - s := new(MetadataPersistenceSuiteV2) - s.TestBase = NewTestBaseWithSQL(GetMySQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestMySQLQueuePersistence(t *testing.T) { - s := new(QueuePersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetMySQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestMySQLClusterMetadataPersistence(t *testing.T) { - s := new(ClusterMetadataManagerSuite) - s.TestBase = NewTestBaseWithSQL(GetMySQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} diff --git a/common/persistence/persistence-tests/postgres_test.go b/common/persistence/persistence-tests/postgres_test.go deleted file mode 100644 index 98435072156..00000000000 --- a/common/persistence/persistence-tests/postgres_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" -) - -func TestPostgreSQLHistoryV2PersistenceSuite(t *testing.T) { - s := new(HistoryV2PersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetPostgreSQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestPostgreSQLMetadataPersistenceSuiteV2(t *testing.T) { - s := new(MetadataPersistenceSuiteV2) - s.TestBase = NewTestBaseWithSQL(GetPostgreSQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestPostgreSQLClusterMetadataPersistence(t *testing.T) { - s := new(ClusterMetadataManagerSuite) - s.TestBase = NewTestBaseWithSQL(GetPostgreSQLTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -// TODO flaky test in buildkite -// https://go.temporal.io/server/issues/2877 -/* -FAIL: TestPostgreSQLQueuePersistence/TestNamespaceReplicationQueue (0.26s) - queuePersistenceTest.go:102: - Error Trace: queuePersistenceTest.go:102 - Error: Not equal: - expected: 99 - actual : 98 - Test: TestPostgreSQLQueuePersistence/TestNamespaceReplicationQueue -*/ -//func TestPostgreSQLQueuePersistence(t *testing.T) { -// s := new(QueuePersistenceSuite) -// s.TestBase = NewTestBaseWithSQL(GetPostgreSQLTestClusterOption()) -// s.TestBase.Setup() -// suite.Run(t, s) -//} diff --git a/common/persistence/persistence-tests/sqlite_test.go b/common/persistence/persistence-tests/sqlite_test.go deleted file mode 100644 index cb74ec6300e..00000000000 --- a/common/persistence/persistence-tests/sqlite_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" -) - -func TestSQLiteHistoryV2PersistenceSuite(t *testing.T) { - s := new(HistoryV2PersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteMemoryTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteMetadataPersistenceSuiteV2(t *testing.T) { - s := new(MetadataPersistenceSuiteV2) - s.TestBase = NewTestBaseWithSQL(GetSQLiteMemoryTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteClusterMetadataPersistence(t *testing.T) { - s := new(ClusterMetadataManagerSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteMemoryTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteQueuePersistence(t *testing.T) { - s := new(QueuePersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteMemoryTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryV2PersistenceSuite(t *testing.T) { - s := new(HistoryV2PersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteFileTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteFileMetadataPersistenceSuiteV2(t *testing.T) { - s := new(MetadataPersistenceSuiteV2) - s.TestBase = NewTestBaseWithSQL(GetSQLiteFileTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteFileClusterMetadataPersistence(t *testing.T) { - s := new(ClusterMetadataManagerSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteFileTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} - -func TestSQLiteFileQueuePersistence(t *testing.T) { - s := new(QueuePersistenceSuite) - s.TestBase = NewTestBaseWithSQL(GetSQLiteFileTestClusterOption()) - s.TestBase.Setup(nil) - suite.Run(t, s) -} diff --git a/common/persistence/sql/sqlplugin/tests/context_test.go b/common/persistence/sql/sqlplugin/tests/context.go similarity index 100% rename from common/persistence/sql/sqlplugin/tests/context_test.go rename to common/persistence/sql/sqlplugin/tests/context.go diff --git a/common/persistence/sql/sqlplugin/tests/history_current_execution_test.go b/common/persistence/sql/sqlplugin/tests/history_current_execution.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_current_execution_test.go rename to common/persistence/sql/sqlplugin/tests/history_current_execution.go index 779d2ec603a..cba9b6ea7d2 100644 --- a/common/persistence/sql/sqlplugin/tests/history_current_execution_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_current_execution.go @@ -69,7 +69,7 @@ var ( } ) -func newHistoryCurrentExecutionSuite( +func NewHistoryCurrentExecutionSuite( t *testing.T, store sqlplugin.HistoryExecution, ) *historyCurrentExecutionSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_test.go b/common/persistence/sql/sqlplugin/tests/history_execution.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution.go index c21e1e91c3f..8960cacfa49 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution.go @@ -57,7 +57,7 @@ var ( testHistoryExecutionStateData = []byte("random history execution state data") ) -func newHistoryExecutionSuite( +func NewHistoryExecutionSuite( t *testing.T, store sqlplugin.HistoryExecution, ) *historyExecutionSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_activity_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_activity.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_activity_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_activity.go index 92618771169..84f0926bd24 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_activity_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_activity.go @@ -53,7 +53,7 @@ var ( testHistoryExecutionActivityData = []byte("random history execution activity data") ) -func newHistoryExecutionActivitySuite( +func NewHistoryExecutionActivitySuite( t *testing.T, store sqlplugin.HistoryExecutionActivity, ) *historyExecutionActivitySuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_buffer_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_buffer.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_buffer_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_buffer.go index cd9f84b8b93..493e6ac6bcd 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_buffer_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_buffer.go @@ -53,7 +53,7 @@ var ( testHistoryExecutionBufferData = []byte("random history execution buffer data") ) -func newHistoryExecutionBufferSuite( +func NewHistoryExecutionBufferSuite( t *testing.T, store sqlplugin.HistoryExecutionBuffer, ) *historyExecutionBufferSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_child_workflow_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_child_workflow.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_child_workflow_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_child_workflow.go index 6d191b6031d..818d3521654 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_child_workflow_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_child_workflow.go @@ -53,7 +53,7 @@ var ( testHistoryExecutionChildWorkflowData = []byte("random history execution child workflow data") ) -func newHistoryExecutionChildWorkflowSuite( +func NewHistoryExecutionChildWorkflowSuite( t *testing.T, store sqlplugin.HistoryExecutionChildWorkflow, ) *historyExecutionChildWorkflowSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_request_cancel_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_request_cancel.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_request_cancel_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_request_cancel.go index 4cb2d6d3d9a..056a0c3166b 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_request_cancel_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_request_cancel.go @@ -53,7 +53,7 @@ var ( testHistoryExecutionRequestCancelData = []byte("random history execution request cancel data") ) -func newHistoryExecutionRequestCancelSuite( +func NewHistoryExecutionRequestCancelSuite( t *testing.T, store sqlplugin.HistoryExecutionRequestCancel, ) *historyExecutionRequestCancelSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_signal_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_signal.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_signal_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_signal.go index 21d3d82331f..5e6d390aa49 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_signal_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_signal.go @@ -53,7 +53,7 @@ var ( testHistoryExecutionSignalData = []byte("random history execution signal data") ) -func newHistoryExecutionSignalSuite( +func NewHistoryExecutionSignalSuite( t *testing.T, store sqlplugin.HistoryExecutionSignal, ) *historyExecutionSignalSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_signal_requested_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_signal_requested.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_signal_requested_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_signal_requested.go index 5f694f8fedd..09d966aabed 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_signal_requested_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_signal_requested.go @@ -49,7 +49,7 @@ const ( testHistoryExecutionSignalID = "random signal ID" ) -func newHistoryExecutionSignalRequestSuite( +func NewHistoryExecutionSignalRequestSuite( t *testing.T, store sqlplugin.HistoryExecutionSignalRequest, ) *historyExecutionSignalRequestSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_execution_timer_test.go b/common/persistence/sql/sqlplugin/tests/history_execution_timer.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_execution_timer_test.go rename to common/persistence/sql/sqlplugin/tests/history_execution_timer.go index 315986c956c..f3da003f677 100644 --- a/common/persistence/sql/sqlplugin/tests/history_execution_timer_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_execution_timer.go @@ -54,7 +54,7 @@ var ( testHistoryExecutionTimerData = []byte("random history execution timer data") ) -func newHistoryExecutionTimerSuite( +func NewHistoryExecutionTimerSuite( t *testing.T, store sqlplugin.HistoryExecutionTimer, ) *historyExecutionTimerSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_node_test.go b/common/persistence/sql/sqlplugin/tests/history_node.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_node_test.go rename to common/persistence/sql/sqlplugin/tests/history_node.go index 31aa51acfbd..f46f4594677 100644 --- a/common/persistence/sql/sqlplugin/tests/history_node_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_node.go @@ -56,7 +56,7 @@ var ( testHistoryNodeData = []byte("random history node data") ) -func newHistoryNodeSuite( +func NewHistoryNodeSuite( t *testing.T, store sqlplugin.HistoryNode, ) *historyNodeSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_replication_task_test.go b/common/persistence/sql/sqlplugin/tests/history_replication_task.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_replication_task_test.go rename to common/persistence/sql/sqlplugin/tests/history_replication_task.go index 1bee671e35a..41de5070e1d 100644 --- a/common/persistence/sql/sqlplugin/tests/history_replication_task_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_replication_task.go @@ -52,7 +52,7 @@ var ( testHistoryReplicationTaskData = []byte("random history replication task data") ) -func newHistoryReplicationTaskSuite( +func NewHistoryReplicationTaskSuite( t *testing.T, store sqlplugin.HistoryReplicationTask, ) *historyHistoryReplicationTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_replication_task_dlq_test.go b/common/persistence/sql/sqlplugin/tests/history_replication_task_dlq.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_replication_task_dlq_test.go rename to common/persistence/sql/sqlplugin/tests/history_replication_task_dlq.go index 44ec3be850a..bb10bed2b22 100644 --- a/common/persistence/sql/sqlplugin/tests/history_replication_task_dlq_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_replication_task_dlq.go @@ -54,7 +54,7 @@ var ( testHistoryReplicationTaskDLQData = []byte("random history replication task data") ) -func newHistoryReplicationDLQTaskSuite( +func NewHistoryReplicationDLQTaskSuite( t *testing.T, store sqlplugin.HistoryReplicationDLQTask, ) *historyHistoryReplicationDLQTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_shard_test.go b/common/persistence/sql/sqlplugin/tests/history_shard.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_shard_test.go rename to common/persistence/sql/sqlplugin/tests/history_shard.go index a6089845071..e6880696df9 100644 --- a/common/persistence/sql/sqlplugin/tests/history_shard_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_shard.go @@ -52,7 +52,7 @@ var ( testHistoryShardData = []byte("random history shard data") ) -func newHistoryShardSuite( +func NewHistoryShardSuite( t *testing.T, store sqlplugin.HistoryShard, ) *historyShardSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_timer_task_test.go b/common/persistence/sql/sqlplugin/tests/history_timer_task.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_timer_task_test.go rename to common/persistence/sql/sqlplugin/tests/history_timer_task.go index c53f66a07aa..9f5831feae3 100644 --- a/common/persistence/sql/sqlplugin/tests/history_timer_task_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_timer_task.go @@ -53,7 +53,7 @@ var ( testHistoryTimerTaskData = []byte("random history timer task data") ) -func newHistoryTimerTaskSuite( +func NewHistoryTimerTaskSuite( t *testing.T, store sqlplugin.HistoryTimerTask, ) *historyHistoryTimerTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_transfer_task_test.go b/common/persistence/sql/sqlplugin/tests/history_transfer_task.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_transfer_task_test.go rename to common/persistence/sql/sqlplugin/tests/history_transfer_task.go index fa201dc4dea..b082d3c7ca5 100644 --- a/common/persistence/sql/sqlplugin/tests/history_transfer_task_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_transfer_task.go @@ -53,7 +53,7 @@ var ( testHistoryTransferTaskData = []byte("random history transfer task data") ) -func newHistoryTransferTaskSuite( +func NewHistoryTransferTaskSuite( t *testing.T, store sqlplugin.HistoryTransferTask, ) *historyHistoryTransferTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_tree_test.go b/common/persistence/sql/sqlplugin/tests/history_tree.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_tree_test.go rename to common/persistence/sql/sqlplugin/tests/history_tree.go index d1f8c94ed53..b402669930c 100644 --- a/common/persistence/sql/sqlplugin/tests/history_tree_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_tree.go @@ -53,7 +53,7 @@ var ( testHistoryTreeData = []byte("random history tree data") ) -func newHistoryTreeSuite( +func NewHistoryTreeSuite( t *testing.T, store sqlplugin.HistoryTree, ) *historyTreeSuite { diff --git a/common/persistence/sql/sqlplugin/tests/history_visibility_task_test.go b/common/persistence/sql/sqlplugin/tests/history_visibility_task.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/history_visibility_task_test.go rename to common/persistence/sql/sqlplugin/tests/history_visibility_task.go index 47c4b08bae6..487c64250af 100644 --- a/common/persistence/sql/sqlplugin/tests/history_visibility_task_test.go +++ b/common/persistence/sql/sqlplugin/tests/history_visibility_task.go @@ -53,7 +53,7 @@ var ( testHistoryVisibilityTaskData = []byte("random history visibility task data") ) -func newHistoryVisibilityTaskSuite( +func NewHistoryVisibilityTaskSuite( t *testing.T, store sqlplugin.HistoryVisibilityTask, ) *historyHistoryVisibilityTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/matching_task_test.go b/common/persistence/sql/sqlplugin/tests/matching_task.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/matching_task_test.go rename to common/persistence/sql/sqlplugin/tests/matching_task.go index ba4f5de5adc..2364993a2c2 100644 --- a/common/persistence/sql/sqlplugin/tests/matching_task_test.go +++ b/common/persistence/sql/sqlplugin/tests/matching_task.go @@ -53,7 +53,7 @@ type ( } ) -func newMatchingTaskSuite( +func NewMatchingTaskSuite( t *testing.T, store sqlplugin.MatchingTask, ) *matchingTaskSuite { diff --git a/common/persistence/sql/sqlplugin/tests/matching_task_queue_test.go b/common/persistence/sql/sqlplugin/tests/matching_task_queue.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/matching_task_queue_test.go rename to common/persistence/sql/sqlplugin/tests/matching_task_queue.go index 702075213dc..cfc42cd80d2 100644 --- a/common/persistence/sql/sqlplugin/tests/matching_task_queue_test.go +++ b/common/persistence/sql/sqlplugin/tests/matching_task_queue.go @@ -57,7 +57,7 @@ type ( // TODO SelectFromTaskQueues with RangeHashGreaterThanEqualTo / RangeHashLessThanEqualTo / TaskQueueIDGreaterThan looks weird // need to go over the logic in matching engine -func newMatchingTaskQueueSuite( +func NewMatchingTaskQueueSuite( t *testing.T, store sqlplugin.MatchingTaskQueue, ) *matchingTaskQueueSuite { diff --git a/common/persistence/sql/sqlplugin/tests/mysql_test.go b/common/persistence/sql/sqlplugin/tests/mysql_test.go deleted file mode 100644 index 0fdf77ea787..00000000000 --- a/common/persistence/sql/sqlplugin/tests/mysql_test.go +++ /dev/null @@ -1,539 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package tests - -import ( - "fmt" - "net" - "path/filepath" - "strconv" - "testing" - - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/persistence/sql" - "go.temporal.io/server/common/persistence/sql/sqlplugin" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" - "go.temporal.io/server/environment" - - _ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" -) - -// TODO merge the initialization with existing persistence setup -const ( - testMySQLUser = "temporal" - testMySQLPassword = "temporal" - testMySQLConnectionProtocol = "tcp" - testMySQLDatabaseNamePrefix = "test_" - testMySQLDatabaseNameSuffix = "temporal_persistence" - - // TODO hard code this dir for now - // need to merge persistence test config / initialization in one place - testMySQLExecutionSchema = "../../../../../schema/mysql/v57/temporal/schema.sql" - testMySQLVisibilitySchema = "../../../../../schema/mysql/v57/visibility/schema.sql" -) - -func TestMySQLNamespaceSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newNamespaceSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLQueueMessageSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newQueueMessageSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLQueueMetadataSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newQueueMetadataSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLMatchingTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newMatchingTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLMatchingTaskQueueSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newMatchingTaskQueueSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryShardSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryShardSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryNodeSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryNodeSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryTreeSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryTreeSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryCurrentExecutionSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryCurrentExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryTransferTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryTransferTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryTimerTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryTimerTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryReplicationTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryReplicationTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryVisibilityTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryVisibilityTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryReplicationDLQTaskSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryReplicationDLQTaskSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionBufferSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionBufferSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionActivitySuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionActivitySuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionChildWorkflowSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionChildWorkflowSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionTimerSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionTimerSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionRequestCancelSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionRequestCancelSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionSignalSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionSignalSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLHistoryExecutionSignalRequestSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newHistoryExecutionSignalRequestSuite(t, store) - suite.Run(t, s) -} - -func TestMySQLVisibilitySuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownMySQLDatabase(cfg) - }() - - s := newVisibilitySuite(t, store) - suite.Run(t, s) -} - -// NewMySQLConfig returns a new MySQL config for test -func NewMySQLConfig() *config.SQL { - return &config.SQL{ - User: testMySQLUser, - Password: testMySQLPassword, - ConnectAddr: net.JoinHostPort( - environment.GetMySQLAddress(), - strconv.Itoa(environment.GetMySQLPort()), - ), - ConnectProtocol: testMySQLConnectionProtocol, - PluginName: "mysql", - DatabaseName: testMySQLDatabaseNamePrefix + shuffle.String(testMySQLDatabaseNameSuffix), - } -} - -func SetupMySQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.CreateDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL database: %v", err)) - } -} - -func SetupMySQLSchema(cfg *config.SQL) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - schemaPath, err := filepath.Abs(testMySQLExecutionSchema) - if err != nil { - panic(err) - } - - statements, err := p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } - - schemaPath, err = filepath.Abs(testMySQLVisibilitySchema) - if err != nil { - panic(err) - } - - statements, err = p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } -} - -func TearDownMySQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.DropDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to drop MySQL database: %v", err)) - } -} diff --git a/common/persistence/sql/sqlplugin/tests/namespace_test.go b/common/persistence/sql/sqlplugin/tests/namespace.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/namespace_test.go rename to common/persistence/sql/sqlplugin/tests/namespace.go index 0e882e428a4..8a1ffc9db7d 100644 --- a/common/persistence/sql/sqlplugin/tests/namespace_test.go +++ b/common/persistence/sql/sqlplugin/tests/namespace.go @@ -55,7 +55,7 @@ type ( } ) -func newNamespaceSuite( +func NewNamespaceSuite( t *testing.T, store sqlplugin.Namespace, ) *namespaceSuite { diff --git a/common/persistence/sql/sqlplugin/tests/postgresql_test.go b/common/persistence/sql/sqlplugin/tests/postgresql_test.go deleted file mode 100644 index 441244d9fff..00000000000 --- a/common/persistence/sql/sqlplugin/tests/postgresql_test.go +++ /dev/null @@ -1,539 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package tests - -import ( - "fmt" - "net" - "path/filepath" - "strconv" - "testing" - - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/persistence/sql" - "go.temporal.io/server/common/persistence/sql/sqlplugin" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" - "go.temporal.io/server/environment" - - _ "go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql" -) - -// TODO merge the initialization with existing persistence setup -const ( - testPostgreSQLUser = "temporal" - testPostgreSQLPassword = "temporal" - testPostgreSQLConnectionProtocol = "tcp" - testPostgreSQLDatabaseNamePrefix = "test_" - testPostgreSQLDatabaseNameSuffix = "temporal_persistence" - - // TODO hard code this dir for now - // need to merge persistence test config / initialization in one place - testPostgreSQLExecutionSchema = "../../../../../schema/postgresql/v96/temporal/schema.sql" - testPostgreSQLVisibilitySchema = "../../../../../schema/postgresql/v96/visibility/schema.sql" -) - -func TestPostgreSQLNamespaceSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create PostgreSQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newNamespaceSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLQueueMessageSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create PostgreSQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newQueueMessageSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLQueueMetadataSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create PostgreSQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newQueueMetadataSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLMatchingTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create PostgreSQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newMatchingTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLMatchingTaskQueueSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create PostgreSQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newMatchingTaskQueueSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryShardSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryShardSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryNodeSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryNodeSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryTreeSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryTreeSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryCurrentExecutionSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryCurrentExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryTransferTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryTransferTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryTimerTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryTimerTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryReplicationTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryReplicationTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryVisibilityTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryVisibilityTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryReplicationDLQTaskSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryReplicationDLQTaskSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionBufferSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionBufferSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionActivitySuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionActivitySuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionChildWorkflowSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionChildWorkflowSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionTimerSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionTimerSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionRequestCancelSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionRequestCancelSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionSignalSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionSignalSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLHistoryExecutionSignalRequestSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newHistoryExecutionSignalRequestSuite(t, store) - suite.Run(t, s) -} - -func TestPostgreSQLVisibilitySuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create MySQL DB: %v", err) - } - defer func() { - _ = store.Close() - TearDownPostgreSQLDatabase(cfg) - }() - - s := newVisibilitySuite(t, store) - suite.Run(t, s) -} - -// NewPostgreSQLConfig returns a new MySQL config for test -func NewPostgreSQLConfig() *config.SQL { - return &config.SQL{ - User: testPostgreSQLUser, - Password: testPostgreSQLPassword, - ConnectAddr: net.JoinHostPort( - environment.GetPostgreSQLAddress(), - strconv.Itoa(environment.GetPostgreSQLPort()), - ), - ConnectProtocol: testPostgreSQLConnectionProtocol, - PluginName: "postgres", - DatabaseName: testPostgreSQLDatabaseNamePrefix + shuffle.String(testPostgreSQLDatabaseNameSuffix), - } -} - -func SetupPostgreSQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.CreateDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL database: %v", err)) - } -} - -func SetupPostgreSQLSchema(cfg *config.SQL) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - schemaPath, err := filepath.Abs(testPostgreSQLExecutionSchema) - if err != nil { - panic(err) - } - - statements, err := p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } - - schemaPath, err = filepath.Abs(testPostgreSQLVisibilitySchema) - if err != nil { - panic(err) - } - - statements, err = p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } -} - -func TearDownPostgreSQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.DropDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to drop PostgreSQL database: %v", err)) - } -} diff --git a/common/persistence/sql/sqlplugin/tests/queue_message_test.go b/common/persistence/sql/sqlplugin/tests/queue_message.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/queue_message_test.go rename to common/persistence/sql/sqlplugin/tests/queue_message.go index c75f947c246..1895f492a01 100644 --- a/common/persistence/sql/sqlplugin/tests/queue_message_test.go +++ b/common/persistence/sql/sqlplugin/tests/queue_message.go @@ -53,7 +53,7 @@ type ( } ) -func newQueueMessageSuite( +func NewQueueMessageSuite( t *testing.T, store sqlplugin.QueueMessage, ) *queueMessageSuite { diff --git a/common/persistence/sql/sqlplugin/tests/queue_metadata_test.go b/common/persistence/sql/sqlplugin/tests/queue_metadata.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/queue_metadata_test.go rename to common/persistence/sql/sqlplugin/tests/queue_metadata.go index 0b480be932c..e961b079c5d 100644 --- a/common/persistence/sql/sqlplugin/tests/queue_metadata_test.go +++ b/common/persistence/sql/sqlplugin/tests/queue_metadata.go @@ -53,7 +53,7 @@ type ( } ) -func newQueueMetadataSuite( +func NewQueueMetadataSuite( t *testing.T, store sqlplugin.QueueMetadata, ) *queueMetadataSuite { diff --git a/common/persistence/sql/sqlplugin/tests/sqlite_test.go b/common/persistence/sql/sqlplugin/tests/sqlite_test.go deleted file mode 100644 index 88040c6fc7c..00000000000 --- a/common/persistence/sql/sqlplugin/tests/sqlite_test.go +++ /dev/null @@ -1,733 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package tests - -import ( - "fmt" - "os" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - "go.temporal.io/server/common/persistence/sql" - "go.temporal.io/server/common/persistence/sql/sqlplugin" - "go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" -) - -// TODO merge the initialization with existing persistence setup -const ( - testSQLiteDatabaseNamePrefix = "test_" - testSQLiteDatabaseNameSuffix = "temporal_persistence" - testSQLiteSchemaDir = "../../../../../schema/sqlite/v3" // specify if mode is not "memory" -) - -func TestSQLiteNamespaceSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newNamespaceSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteQueueMessageSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newQueueMessageSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteQueueMetadataSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newQueueMetadataSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteMatchingTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newMatchingTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteMatchingTaskQueueSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newMatchingTaskQueueSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryShardSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryShardSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryNodeSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryNodeSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryTreeSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryTreeSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryCurrentExecutionSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryCurrentExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryTransferTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryTransferTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryTimerTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryTimerTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryReplicationTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryReplicationTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryVisibilityTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryVisibilityTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryReplicationDLQTaskSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryReplicationDLQTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionBufferSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionBufferSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionActivitySuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionActivitySuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionChildWorkflowSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionChildWorkflowSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionTimerSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionTimerSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionRequestCancelSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionRequestCancelSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionSignalSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionSignalSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteHistoryExecutionSignalRequestSuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newHistoryExecutionSignalRequestSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteVisibilitySuite(t *testing.T) { - cfg := newSQLiteMemoryConfig() - store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer func() { - _ = store.Close() - }() - - s := newVisibilitySuite(t, store) - suite.Run(t, s) -} - -// newSQLiteMemoryConfig returns a new SQLite config for test -func newSQLiteMemoryConfig() *config.SQL { - return &config.SQL{ - User: "", - Password: "", - ConnectAddr: "", - ConnectProtocol: "", - ConnectAttributes: map[string]string{ - "mode": "memory", - "cache": "private", - }, - PluginName: sqlite.PluginName, - DatabaseName: "default", - } -} - -// newSQLiteFileConfig returns a new SQLite config for test -func newSQLiteFileConfig() *config.SQL { - return &config.SQL{ - User: "", - Password: "", - ConnectAddr: "", - ConnectProtocol: "", - ConnectAttributes: map[string]string{ - "cache": "private", - "setup": "true", - "journal_mode": "WAL", - "synchronous": "2", - }, - PluginName: sqlite.PluginName, - DatabaseName: testSQLiteDatabaseNamePrefix + shuffle.String(testSQLiteDatabaseNameSuffix), - } -} - -func setupSQLiteDatabase(cfg *config.SQL, t *testing.T) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) - assert.NoError(t, err) - defer func() { _ = db.Close() }() - - err = db.CreateDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to create SQLite database: %v", err)) - } -} - -func TestSQLiteFileNamespaceSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newNamespaceSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileQueueMessageSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newQueueMessageSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileQueueMetadataSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newQueueMetadataSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileMatchingTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newMatchingTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileMatchingTaskQueueSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newMatchingTaskQueueSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryShardSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryShardSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryNodeSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryNodeSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryTreeSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryTreeSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryCurrentExecutionSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryCurrentExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryTransferTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryTransferTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryTimerTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryTimerTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryReplicationTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryReplicationTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryVisibilityTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryVisibilityTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryReplicationDLQTaskSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryReplicationDLQTaskSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionBufferSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionBufferSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionActivitySuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionActivitySuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionChildWorkflowSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionChildWorkflowSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionTimerSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionTimerSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionRequestCancelSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionRequestCancelSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionSignalSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionSignalSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileHistoryExecutionSignalRequestSuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newHistoryExecutionSignalRequestSuite(t, store) - suite.Run(t, s) -} - -func TestSQLiteFileVisibilitySuite(t *testing.T) { - cfg := newSQLiteFileConfig() - setupSQLiteDatabase(cfg, t) - store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) - if err != nil { - t.Fatalf("unable to create SQLite DB: %v", err) - } - defer testCleanUp(store, cfg, t) - - s := newVisibilitySuite(t, store) - suite.Run(t, s) -} - -func testCleanUp(d sqlplugin.DB, c *config.SQL, t *testing.T) { - err := d.Close() - if err != nil { - t.Fatal(err) - } - err = os.Remove(c.DatabaseName) - if err != nil { - t.Fatal(err) - } - err = os.Remove(c.DatabaseName + "-wal") - if err != nil { - t.Fatal(err) - } - err = os.Remove(c.DatabaseName + "-shm") - if err != nil { - t.Fatal(err) - } -} diff --git a/common/persistence/sql/sqlplugin/tests/visibility_test.go b/common/persistence/sql/sqlplugin/tests/visibility.go similarity index 99% rename from common/persistence/sql/sqlplugin/tests/visibility_test.go rename to common/persistence/sql/sqlplugin/tests/visibility.go index edc22f470e2..39fd48f2b77 100644 --- a/common/persistence/sql/sqlplugin/tests/visibility_test.go +++ b/common/persistence/sql/sqlplugin/tests/visibility.go @@ -69,7 +69,7 @@ var testVisibilityCloseStatus = []enumspb.WorkflowExecutionStatus{ enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT, } -func newVisibilitySuite( +func NewVisibilitySuite( t *testing.T, store sqlplugin.Visibility, ) *visibilitySuite { diff --git a/common/persistence/tests/cassandra_test.go b/common/persistence/tests/cassandra_test.go index 977c1c892c5..b073430f542 100644 --- a/common/persistence/tests/cassandra_test.go +++ b/common/persistence/tests/cassandra_test.go @@ -29,6 +29,7 @@ import ( "github.com/stretchr/testify/suite" + persistencetests "go.temporal.io/server/common/persistence/persistence-tests" "go.temporal.io/server/common/persistence/serialization" _ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" ) @@ -135,3 +136,40 @@ func TestCassandraTaskQueueTaskSuite(t *testing.T) { s := NewTaskQueueTaskSuite(t, taskQueueStore, testData.Logger) suite.Run(t, s) } + +func TestCassandraVisibilityPersistence(t *testing.T) { + s := &VisibilityPersistenceSuite{ + TestBase: persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}), + } + suite.Run(t, s) +} + +// TODO: Merge persistence-tests into the tests directory. + +func TestCassandraHistoryV2Persistence(t *testing.T) { + s := new(persistencetests.HistoryV2PersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestCassandraMetadataPersistenceV2(t *testing.T) { + s := new(persistencetests.MetadataPersistenceSuiteV2) + s.TestBase = persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestCassandraQueuePersistence(t *testing.T) { + s := new(persistencetests.QueuePersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestCassandraClusterMetadataPersistence(t *testing.T) { + s := new(persistencetests.ClusterMetadataManagerSuite) + s.TestBase = persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}) + s.TestBase.Setup(nil) + suite.Run(t, s) +} diff --git a/common/persistence/tests/mysql_test.go b/common/persistence/tests/mysql_test.go index cfcf40aa5b4..985c19e9abc 100644 --- a/common/persistence/tests/mysql_test.go +++ b/common/persistence/tests/mysql_test.go @@ -29,8 +29,13 @@ import ( "github.com/stretchr/testify/suite" + persistencetests "go.temporal.io/server/common/persistence/persistence-tests" "go.temporal.io/server/common/persistence/serialization" + "go.temporal.io/server/common/persistence/sql" + "go.temporal.io/server/common/persistence/sql/sqlplugin" _ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" + sqltests "go.temporal.io/server/common/persistence/sql/sqlplugin/tests" + "go.temporal.io/server/common/resolver" ) func TestMySQLShardStoreSuite(t *testing.T) { @@ -139,3 +144,433 @@ func TestMySQLTaskQueueTaskSuite(t *testing.T) { s := NewTaskQueueTaskSuite(t, taskQueueStore, testData.Logger) suite.Run(t, s) } + +func TestMySQLVisibilityPersistenceSuite(t *testing.T) { + s := &VisibilityPersistenceSuite{ + TestBase: persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()), + } + suite.Run(t, s) +} + +// TODO: Merge persistence-tests into the tests directory. + +func TestMySQLHistoryV2PersistenceSuite(t *testing.T) { + s := new(persistencetests.HistoryV2PersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestMySQLMetadataPersistenceSuiteV2(t *testing.T) { + s := new(persistencetests.MetadataPersistenceSuiteV2) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestMySQLQueuePersistence(t *testing.T) { + s := new(persistencetests.QueuePersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestMySQLClusterMetadataPersistence(t *testing.T) { + s := new(persistencetests.ClusterMetadataManagerSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +// SQL Store tests + +func TestMySQLNamespaceSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewNamespaceSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLQueueMessageSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewQueueMessageSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLQueueMetadataSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewQueueMetadataSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLMatchingTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewMatchingTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLMatchingTaskQueueSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewMatchingTaskQueueSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryShardSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryShardSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryNodeSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryNodeSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryTreeSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTreeSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryCurrentExecutionSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryCurrentExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryTransferTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTransferTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryTimerTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTimerTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryReplicationTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryReplicationTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryVisibilityTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryVisibilityTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryReplicationDLQTaskSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryReplicationDLQTaskSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionBufferSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionBufferSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionActivitySuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionActivitySuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionChildWorkflowSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionChildWorkflowSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionTimerSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionTimerSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionRequestCancelSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionRequestCancelSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionSignalSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSignalSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLHistoryExecutionSignalRequestSuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSignalRequestSuite(t, store) + suite.Run(t, s) +} + +func TestMySQLVisibilitySuite(t *testing.T) { + cfg := NewMySQLConfig() + SetupMySQLDatabase(cfg) + SetupMySQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownMySQLDatabase(cfg) + }() + + s := sqltests.NewVisibilitySuite(t, store) + suite.Run(t, s) +} diff --git a/common/persistence/tests/postgresql_test.go b/common/persistence/tests/postgresql_test.go index 73a1fd1b2ba..b8db7461204 100644 --- a/common/persistence/tests/postgresql_test.go +++ b/common/persistence/tests/postgresql_test.go @@ -29,8 +29,13 @@ import ( "github.com/stretchr/testify/suite" + persistencetests "go.temporal.io/server/common/persistence/persistence-tests" "go.temporal.io/server/common/persistence/serialization" + "go.temporal.io/server/common/persistence/sql" + "go.temporal.io/server/common/persistence/sql/sqlplugin" _ "go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql" + sqltests "go.temporal.io/server/common/persistence/sql/sqlplugin/tests" + "go.temporal.io/server/common/resolver" ) func TestPostgreSQLShardStoreSuite(t *testing.T) { @@ -135,3 +140,444 @@ func TestPostgreSQLTaskQueueTaskSuite(t *testing.T) { s := NewTaskQueueTaskSuite(t, taskQueueStore, testData.Logger) suite.Run(t, s) } + +func TestPostgreSQLVisibilityPersistenceSuite(t *testing.T) { + s := &VisibilityPersistenceSuite{ + TestBase: persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()), + } + suite.Run(t, s) +} + +// TODO: Merge persistence-tests into the tests directory. + +func TestPostgreSQLHistoryV2PersistenceSuite(t *testing.T) { + s := new(persistencetests.HistoryV2PersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestPostgreSQLMetadataPersistenceSuiteV2(t *testing.T) { + s := new(persistencetests.MetadataPersistenceSuiteV2) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestPostgreSQLClusterMetadataPersistence(t *testing.T) { + s := new(persistencetests.ClusterMetadataManagerSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +// TODO flaky test in buildkite +// https://go.temporal.io/server/issues/2877 +/* +FAIL: TestPostgreSQLQueuePersistence/TestNamespaceReplicationQueue (0.26s) + queuePersistenceTest.go:102: + Error Trace: queuePersistenceTest.go:102 + Error: Not equal: + expected: 99 + actual : 98 + Test: TestPostgreSQLQueuePersistence/TestNamespaceReplicationQueue +*/ +//func TestPostgreSQLQueuePersistence(t *testing.T) { +// s := new(persistencetests.QueuePersistenceSuite) +// s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()) +// s.TestBase.Setup() +// suite.Run(t, s) +//} + +// SQL store tests + +func TestPostgreSQLNamespaceSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create PostgreSQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewNamespaceSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLQueueMessageSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create PostgreSQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewQueueMessageSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLQueueMetadataSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create PostgreSQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewQueueMetadataSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLMatchingTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create PostgreSQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewMatchingTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLMatchingTaskQueueSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create PostgreSQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewMatchingTaskQueueSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryShardSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryShardSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryNodeSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryNodeSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryTreeSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTreeSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryCurrentExecutionSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryCurrentExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryTransferTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTransferTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryTimerTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryTimerTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryReplicationTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryReplicationTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryVisibilityTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryVisibilityTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryReplicationDLQTaskSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryReplicationDLQTaskSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionBufferSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionBufferSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionActivitySuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionActivitySuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionChildWorkflowSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionChildWorkflowSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionTimerSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionTimerSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionRequestCancelSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionRequestCancelSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionSignalSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSignalSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLHistoryExecutionSignalRequestSuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewHistoryExecutionSignalRequestSuite(t, store) + suite.Run(t, s) +} + +func TestPostgreSQLVisibilitySuite(t *testing.T) { + cfg := NewPostgreSQLConfig() + SetupPostgreSQLDatabase(cfg) + SetupPostgreSQLSchema(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create MySQL DB: %v", err) + } + defer func() { + _ = store.Close() + TearDownPostgreSQLDatabase(cfg) + }() + + s := sqltests.NewVisibilitySuite(t, store) + suite.Run(t, s) +} diff --git a/common/persistence/tests/sqlite_test.go b/common/persistence/tests/sqlite_test.go index 5745c81ac5a..e4563fa816c 100644 --- a/common/persistence/tests/sqlite_test.go +++ b/common/persistence/tests/sqlite_test.go @@ -42,6 +42,7 @@ import ( "go.temporal.io/server/common/persistence/sql" "go.temporal.io/server/common/persistence/sql/sqlplugin" _ "go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite" + sqltests "go.temporal.io/server/common/persistence/sql/sqlplugin/tests" "go.temporal.io/server/common/resolver" "go.temporal.io/server/environment" ) @@ -52,6 +53,61 @@ const ( testSQLiteSchemaDir = "../../../schema/sqlite/v3" // specify if mode is not "memory" ) +// NewSQLiteMemoryConfig returns a new SQLite config for test +func NewSQLiteMemoryConfig() *config.SQL { + return &config.SQL{ + User: "", + Password: "", + ConnectAddr: environment.Localhost, + ConnectProtocol: "tcp", + PluginName: "sqlite", + DatabaseName: "default", + ConnectAttributes: map[string]string{"mode": "memory", "cache": "private"}, + } +} + +// NewSQLiteMemoryConfig returns a new SQLite config for test +func NewSQLiteFileConfig() *config.SQL { + return &config.SQL{ + User: "", + Password: "", + ConnectAddr: environment.Localhost, + ConnectProtocol: "tcp", + PluginName: "sqlite", + DatabaseName: "test_" + persistencetests.GenerateRandomDBName(3), + ConnectAttributes: map[string]string{"cache": "private"}, + } +} + +func SetupSQLiteDatabase(cfg *config.SQL) { + db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) + if err != nil { + panic(fmt.Sprintf("unable to create SQLite admin DB: %v", err)) + } + defer func() { _ = db.Close() }() + + err = db.CreateDatabase(cfg.DatabaseName) + if err != nil { + panic(fmt.Sprintf("unable to create SQLite database: %v", err)) + } + + LoadSchema(db, path.Join(testSQLiteSchemaDir, "temporal", "schema.sql")) + LoadSchema(db, path.Join(testSQLiteSchemaDir, "visibility", "schema.sql")) +} + +func LoadSchema(db sqlplugin.AdminDB, schemaFile string) { + statements, err := persistence.LoadAndSplitQuery([]string{schemaFile}) + if err != nil { + panic(fmt.Sprintf("LoadSchema %+v", tag.Error(err))) + } + + for _, stmt := range statements { + if err = db.Exec(stmt); err != nil { + panic(fmt.Sprintf("LoadSchema %+v", tag.Error(err))) + } + } +} + func TestSQLiteExecutionMutableStateStoreSuite(t *testing.T) { cfg := NewSQLiteMemoryConfig() logger := log.NewNoopLogger() @@ -322,57 +378,683 @@ func TestSQLiteFileTaskQueueTaskSuite(t *testing.T) { suite.Run(t, s) } -// NewSQLiteMemoryConfig returns a new SQLite config for test -func NewSQLiteMemoryConfig() *config.SQL { - return &config.SQL{ - User: "", - Password: "", - ConnectAddr: environment.Localhost, - ConnectProtocol: "tcp", - PluginName: "sqlite", - DatabaseName: "default", - ConnectAttributes: map[string]string{"mode": "memory", "cache": "private"}, +// TODO: Merge persistence-tests into the tests directory. + +func TestSQLiteHistoryV2PersistenceSuite(t *testing.T) { + s := new(persistencetests.HistoryV2PersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteMemoryTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteMetadataPersistenceSuiteV2(t *testing.T) { + s := new(persistencetests.MetadataPersistenceSuiteV2) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteMemoryTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteClusterMetadataPersistence(t *testing.T) { + s := new(persistencetests.ClusterMetadataManagerSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteMemoryTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteQueuePersistence(t *testing.T) { + s := new(persistencetests.QueuePersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteMemoryTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryV2PersistenceSuite(t *testing.T) { + s := new(persistencetests.HistoryV2PersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteFileTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteFileMetadataPersistenceSuiteV2(t *testing.T) { + s := new(persistencetests.MetadataPersistenceSuiteV2) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteFileTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteFileClusterMetadataPersistence(t *testing.T) { + s := new(persistencetests.ClusterMetadataManagerSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteFileTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +func TestSQLiteFileQueuePersistence(t *testing.T) { + s := new(persistencetests.QueuePersistenceSuite) + s.TestBase = persistencetests.NewTestBaseWithSQL(persistencetests.GetSQLiteFileTestClusterOption()) + s.TestBase.Setup(nil) + suite.Run(t, s) +} + +// SQL store tests + +func TestSQLiteNamespaceSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewNamespaceSuite(t, store) + suite.Run(t, s) } -// NewSQLiteMemoryConfig returns a new SQLite config for test -func NewSQLiteFileConfig() *config.SQL { - return &config.SQL{ - User: "", - Password: "", - ConnectAddr: environment.Localhost, - ConnectProtocol: "tcp", - PluginName: "sqlite", - DatabaseName: "test_" + persistencetests.GenerateRandomDBName(3), - ConnectAttributes: map[string]string{"cache": "private"}, +func TestSQLiteQueueMessageSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewQueueMessageSuite(t, store) + suite.Run(t, s) } -func SetupSQLiteDatabase(cfg *config.SQL) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) +func TestSQLiteQueueMetadataSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) if err != nil { - panic(fmt.Sprintf("unable to create SQLite admin DB: %v", err)) + t.Fatalf("unable to create SQLite DB: %v", err) } - defer func() { _ = db.Close() }() + defer func() { + _ = store.Close() + }() - err = db.CreateDatabase(cfg.DatabaseName) + s := sqltests.NewQueueMetadataSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteMatchingTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) if err != nil { - panic(fmt.Sprintf("unable to create SQLite database: %v", err)) + t.Fatalf("unable to create SQLite DB: %v", err) } + defer func() { + _ = store.Close() + }() - LoadSchema(db, path.Join(testSQLiteSchemaDir, "temporal", "schema.sql")) - LoadSchema(db, path.Join(testSQLiteSchemaDir, "visibility", "schema.sql")) + s := sqltests.NewMatchingTaskSuite(t, store) + suite.Run(t, s) } -func LoadSchema(db sqlplugin.AdminDB, schemaFile string) { - statements, err := persistence.LoadAndSplitQuery([]string{schemaFile}) +func TestSQLiteMatchingTaskQueueSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) if err != nil { - panic(fmt.Sprintf("LoadSchema %+v", tag.Error(err))) + t.Fatalf("unable to create SQLite DB: %v", err) } + defer func() { + _ = store.Close() + }() - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(fmt.Sprintf("LoadSchema %+v", tag.Error(err))) - } + s := sqltests.NewMatchingTaskQueueSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryShardSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryShardSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryNodeSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryNodeSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryTreeSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryTreeSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryCurrentExecutionSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryCurrentExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryTransferTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryTransferTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryTimerTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryTimerTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryReplicationTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryReplicationTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryVisibilityTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryVisibilityTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryReplicationDLQTaskSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryReplicationDLQTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionBufferSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionBufferSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionActivitySuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionActivitySuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionChildWorkflowSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionChildWorkflowSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionTimerSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionTimerSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionRequestCancelSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionRequestCancelSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionSignalSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionSignalSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteHistoryExecutionSignalRequestSuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewHistoryExecutionSignalRequestSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteVisibilitySuite(t *testing.T) { + cfg := NewSQLiteMemoryConfig() + store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer func() { + _ = store.Close() + }() + + s := sqltests.NewVisibilitySuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileNamespaceSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewNamespaceSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileQueueMessageSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewQueueMessageSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileQueueMetadataSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewQueueMetadataSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileMatchingTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewMatchingTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileMatchingTaskQueueSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewMatchingTaskQueueSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryShardSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryShardSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryNodeSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryNodeSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryTreeSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryTreeSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryCurrentExecutionSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryCurrentExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryTransferTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryTransferTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryTimerTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryTimerTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryReplicationTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryReplicationTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryVisibilityTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryVisibilityTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryReplicationDLQTaskSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryReplicationDLQTaskSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionBufferSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionBufferSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionActivitySuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionActivitySuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionChildWorkflowSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionChildWorkflowSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionTimerSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionTimerSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionRequestCancelSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionRequestCancelSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionSignalSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionSignalSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileHistoryExecutionSignalRequestSuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindMain, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewHistoryExecutionSignalRequestSuite(t, store) + suite.Run(t, s) +} + +func TestSQLiteFileVisibilitySuite(t *testing.T) { + cfg := NewSQLiteFileConfig() + SetupSQLiteDatabase(cfg) + store, err := sql.NewSQLDB(sqlplugin.DbKindVisibility, cfg, resolver.NewNoopResolver()) + if err != nil { + t.Fatalf("unable to create SQLite DB: %v", err) + } + defer os.Remove(cfg.DatabaseName) + + s := sqltests.NewVisibilitySuite(t, store) + suite.Run(t, s) } diff --git a/common/persistence/visibility/persistence-tests/visibility_persistence_suite_test.go b/common/persistence/tests/visibility_persistence_suite_test.go similarity index 99% rename from common/persistence/visibility/persistence-tests/visibility_persistence_suite_test.go rename to common/persistence/tests/visibility_persistence_suite_test.go index dd955796f3c..0f8c9b4afe0 100644 --- a/common/persistence/visibility/persistence-tests/visibility_persistence_suite_test.go +++ b/common/persistence/tests/visibility_persistence_suite_test.go @@ -22,7 +22,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package persistencetests +package tests import ( "context" diff --git a/common/persistence/visibility/persistence-tests/cassandra_test.go b/common/persistence/visibility/persistence-tests/cassandra_test.go deleted file mode 100644 index c7bb7882479..00000000000 --- a/common/persistence/visibility/persistence-tests/cassandra_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - persistencetests "go.temporal.io/server/common/persistence/persistence-tests" -) - -func TestCassandraVisibilityPersistence(t *testing.T) { - s := &VisibilityPersistenceSuite{ - TestBase: persistencetests.NewTestBaseWithCassandra(&persistencetests.TestBaseOptions{}), - } - suite.Run(t, s) -} diff --git a/common/persistence/visibility/persistence-tests/mysql_test.go b/common/persistence/visibility/persistence-tests/mysql_test.go deleted file mode 100644 index 0cb57b37579..00000000000 --- a/common/persistence/visibility/persistence-tests/mysql_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package persistencetests - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - persistencetests "go.temporal.io/server/common/persistence/persistence-tests" -) - -func TestMySQLVisibilityPersistenceSuite(t *testing.T) { - s := &VisibilityPersistenceSuite{ - TestBase: persistencetests.NewTestBaseWithSQL(persistencetests.GetMySQLTestClusterOption()), - } - suite.Run(t, s) -} diff --git a/develop/buildkite/docker-compose.yml b/develop/buildkite/docker-compose.yml index a31af94f63a..468d0649cf0 100644 --- a/develop/buildkite/docker-compose.yml +++ b/develop/buildkite/docker-compose.yml @@ -58,7 +58,7 @@ services: - ../..:/temporal - /usr/bin/buildkite-agent:/usr/bin/buildkite-agent - unit-test: + db-integration-test: build: context: ../.. dockerfile: ./develop/buildkite/Dockerfile @@ -81,7 +81,7 @@ services: networks: services-network: aliases: - - unit-test + - db-integration-test integration-test-cassandra: build: diff --git a/develop/buildkite/pipeline.yml b/develop/buildkite/pipeline.yml index f008691a731..fa2654565a4 100644 --- a/develop/buildkite/pipeline.yml +++ b/develop/buildkite/pipeline.yml @@ -20,7 +20,19 @@ steps: - ".coverage/*.out" plugins: - docker-compose#v3.8.0: - run: unit-test + run: build + config: ./develop/buildkite/docker-compose.yml + + - label: ":golang: integration test" + agents: + queue: "default" + docker: "*" + command: "make db-integration-test-coverage" + artifact_paths: + - ".coverage/*.out" + plugins: + - docker-compose#v3.8.0: + run: db-integration-test config: ./develop/buildkite/docker-compose.yml - label: ":golang: integration test with cassandra" diff --git a/develop/buildkite/scripts/coverage-report.sh b/develop/buildkite/scripts/coverage-report.sh index 9476d6dbe56..7a795f9bc11 100755 --- a/develop/buildkite/scripts/coverage-report.sh +++ b/develop/buildkite/scripts/coverage-report.sh @@ -4,6 +4,8 @@ set -eu # Download cover profiles from all the test containers. buildkite-agent artifact download ".coverage/unit_coverprofile.out" . --step ":golang: unit test" --build "${BUILDKITE_BUILD_ID}" +buildkite-agent artifact download ".coverage/integration_coverprofile.out" . --step ":golang: integration test" --build "${BUILDKITE_BUILD_ID}" +buildkite-agent artifact download ".coverage/db_tool_coverprofile.out" . --step ":golang: integration test" --build "${BUILDKITE_BUILD_ID}" # ES8. buildkite-agent artifact download ".coverage/integ_cassandra_coverprofile.out" . --step ":golang: integration test with cassandra (ES8)" --build "${BUILDKITE_BUILD_ID}" diff --git a/tests/integration/cassandra_test.go b/tests/integration/cassandra_test.go deleted file mode 100644 index b9e91f52106..00000000000 --- a/tests/integration/cassandra_test.go +++ /dev/null @@ -1,160 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package integration - -import ( - "fmt" - "path/filepath" - "testing" - - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - "go.temporal.io/server/common/log" - p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/persistence/cassandra" - "go.temporal.io/server/common/persistence/nosql/nosqlplugin/cassandra/gocql" - _ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" - "go.temporal.io/server/environment" -) - -// TODO merge the initialization with existing persistence setup -const ( - testCassandraUser = "temporal" - testCassandraPassword = "temporal" - testCassandraDatabaseNamePrefix = "test_" - testCassandraDatabaseNameSuffix = "temporal_persistence" - - // TODO hard code this dir for now - // need to merge persistence test config / initialization in one place - testCassandraExecutionSchema = "../../schema/cassandra/temporal/schema.cql" - testCassandraVisibilitySchema = "../../schema/cassandra/visibility/schema.cql" -) - -func TestCassandraSizeLimitSuite(t *testing.T) { - cfg := NewCassandraConfig() - SetupCassandraDatabase(cfg) - SetupCassandraSchema(cfg) - logger := log.NewNoopLogger() - defer func() { TearDownCassandraKeyspace(cfg) }() - - s := newSizeLimitSuite(t, logger) - suite.Run(t, s) -} - -// NewCassandraConfig returns a new Cassandra config for test -func NewCassandraConfig() *config.Cassandra { - return &config.Cassandra{ - User: testCassandraUser, - Password: testCassandraPassword, - Hosts: environment.GetCassandraAddress(), - Port: environment.GetCassandraPort(), - Keyspace: testCassandraDatabaseNamePrefix + shuffle.String(testCassandraDatabaseNameSuffix), - } -} - -func SetupCassandraDatabase(cfg *config.Cassandra) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.Keyspace = "system" - - session, err := gocql.NewSession(adminCfg, resolver.NewNoopResolver(), log.NewNoopLogger()) - if err != nil { - panic(fmt.Sprintf("unable to create Cassandra session: %v", err)) - } - defer session.Close() - - if err := cassandra.CreateCassandraKeyspace( - session, - cfg.Keyspace, - 1, - true, - log.NewNoopLogger(), - ); err != nil { - panic(fmt.Sprintf("unable to create Cassandra keyspace: %v", err)) - } -} - -func SetupCassandraSchema(cfg *config.Cassandra) { - session, err := gocql.NewSession(*cfg, resolver.NewNoopResolver(), log.NewNoopLogger()) - if err != nil { - panic(fmt.Sprintf("unable to create Cassandra session: %v", err)) - } - defer session.Close() - - schemaPath, err := filepath.Abs(testCassandraExecutionSchema) - if err != nil { - panic(err) - } - - statements, err := p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = session.Query(stmt).Exec(); err != nil { - panic(err) - } - } - - schemaPath, err = filepath.Abs(testCassandraVisibilitySchema) - if err != nil { - panic(err) - } - - statements, err = p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = session.Query(stmt).Exec(); err != nil { - panic(err) - } - } -} - -func TearDownCassandraKeyspace(cfg *config.Cassandra) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.Keyspace = "system" - - session, err := gocql.NewSession(adminCfg, resolver.NewNoopResolver(), log.NewNoopLogger()) - if err != nil { - panic(fmt.Sprintf("unable to create Cassandra session: %v", err)) - } - defer session.Close() - - if err := cassandra.DropCassandraKeyspace( - session, - cfg.Keyspace, - log.NewNoopLogger(), - ); err != nil { - panic(fmt.Sprintf("unable to drop Cassandra keyspace: %v", err)) - } -} diff --git a/tests/integration/mysql_test.go b/tests/integration/mysql_test.go deleted file mode 100644 index 6723413ba23..00000000000 --- a/tests/integration/mysql_test.go +++ /dev/null @@ -1,159 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package integration - -import ( - "fmt" - "net" - "path/filepath" - "strconv" - "testing" - - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - "go.temporal.io/server/common/log" - p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/persistence/sql" - "go.temporal.io/server/common/persistence/sql/sqlplugin" - _ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" - "go.temporal.io/server/environment" -) - -// TODO merge the initialization with existing persistence setup -const ( - testMySQLUser = "temporal" - testMySQLPassword = "temporal" - testMySQLConnectionProtocol = "tcp" - testMySQLDatabaseNamePrefix = "test_" - testMySQLDatabaseNameSuffix = "temporal_persistence" - - // TODO hard code this dir for now - // need to merge persistence test config / initialization in one place - testMySQLExecutionSchema = "../../schema/mysql/v57/temporal/schema.sql" - testMySQLVisibilitySchema = "../../schema/mysql/v57/visibility/schema.sql" -) - -func TestMySQLSizeLimitSuite(t *testing.T) { - cfg := NewMySQLConfig() - SetupMySQLDatabase(cfg) - SetupMySQLSchema(cfg) - logger := log.NewNoopLogger() - defer func() { TearDownMySQLDatabase(cfg) }() - - s := newSizeLimitSuite(t, logger) - suite.Run(t, s) -} - -// NewMySQLConfig returns a new MySQL config for test -func NewMySQLConfig() *config.SQL { - return &config.SQL{ - User: testMySQLUser, - Password: testMySQLPassword, - ConnectAddr: net.JoinHostPort( - environment.GetMySQLAddress(), - strconv.Itoa(environment.GetMySQLPort()), - ), - ConnectProtocol: testMySQLConnectionProtocol, - PluginName: "mysql", - DatabaseName: testMySQLDatabaseNamePrefix + shuffle.String(testMySQLDatabaseNameSuffix), - } -} - -func SetupMySQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.CreateDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL database: %v", err)) - } -} - -func SetupMySQLSchema(cfg *config.SQL) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - schemaPath, err := filepath.Abs(testMySQLExecutionSchema) - if err != nil { - panic(err) - } - - statements, err := p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } - - schemaPath, err = filepath.Abs(testMySQLVisibilitySchema) - if err != nil { - panic(err) - } - - statements, err = p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } -} - -func TearDownMySQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create MySQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.DropDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to drop MySQL database: %v", err)) - } -} diff --git a/tests/integration/postgresql_test.go b/tests/integration/postgresql_test.go deleted file mode 100644 index 0320732570d..00000000000 --- a/tests/integration/postgresql_test.go +++ /dev/null @@ -1,159 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package integration - -import ( - "fmt" - "net" - "path/filepath" - "strconv" - "testing" - - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/config" - "go.temporal.io/server/common/log" - p "go.temporal.io/server/common/persistence" - "go.temporal.io/server/common/persistence/sql" - "go.temporal.io/server/common/persistence/sql/sqlplugin" - _ "go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql" - "go.temporal.io/server/common/resolver" - "go.temporal.io/server/common/shuffle" - "go.temporal.io/server/environment" -) - -// TODO merge the initialization with existing persistence setup -const ( - testPostgreSQLUser = "temporal" - testPostgreSQLPassword = "temporal" - testPostgreSQLConnectionProtocol = "tcp" - testPostgreSQLDatabaseNamePrefix = "test_" - testPostgreSQLDatabaseNameSuffix = "temporal_persistence" - - // TODO hard code this dir for now - // need to merge persistence test config / initialization in one place - testPostgreSQLExecutionSchema = "../../schema/postgresql/v96/temporal/schema.sql" - testPostgreSQLVisibilitySchema = "../../schema/postgresql/v96/visibility/schema.sql" -) - -func TestPostgreSQLSizeLimitSuite(t *testing.T) { - cfg := NewPostgreSQLConfig() - SetupPostgreSQLDatabase(cfg) - SetupPostgreSQLSchema(cfg) - logger := log.NewNoopLogger() - defer func() { TearDownPostgreSQLDatabase(cfg) }() - - s := newSizeLimitSuite(t, logger) - suite.Run(t, s) -} - -// NewPostgreSQLConfig returns a new MySQL config for test -func NewPostgreSQLConfig() *config.SQL { - return &config.SQL{ - User: testPostgreSQLUser, - Password: testPostgreSQLPassword, - ConnectAddr: net.JoinHostPort( - environment.GetPostgreSQLAddress(), - strconv.Itoa(environment.GetPostgreSQLPort()), - ), - ConnectProtocol: testPostgreSQLConnectionProtocol, - PluginName: "postgres", - DatabaseName: testPostgreSQLDatabaseNamePrefix + shuffle.String(testPostgreSQLDatabaseNameSuffix), - } -} - -func SetupPostgreSQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.CreateDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL database: %v", err)) - } -} - -func SetupPostgreSQLSchema(cfg *config.SQL) { - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, cfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - schemaPath, err := filepath.Abs(testPostgreSQLExecutionSchema) - if err != nil { - panic(err) - } - - statements, err := p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } - - schemaPath, err = filepath.Abs(testPostgreSQLVisibilitySchema) - if err != nil { - panic(err) - } - - statements, err = p.LoadAndSplitQuery([]string{schemaPath}) - if err != nil { - panic(err) - } - - for _, stmt := range statements { - if err = db.Exec(stmt); err != nil { - panic(err) - } - } -} - -func TearDownPostgreSQLDatabase(cfg *config.SQL) { - adminCfg := *cfg - // NOTE need to connect with empty name to create new database - adminCfg.DatabaseName = "" - - db, err := sql.NewSQLAdminDB(sqlplugin.DbKindUnknown, &adminCfg, resolver.NewNoopResolver()) - if err != nil { - panic(fmt.Sprintf("unable to create PostgreSQL admin DB: %v", err)) - } - defer func() { _ = db.Close() }() - - err = db.DropDatabase(cfg.DatabaseName) - if err != nil { - panic(fmt.Sprintf("unable to drop PostgreSQL database: %v", err)) - } -} diff --git a/tests/integration/size_limit.go b/tests/integration/size_limit.go deleted file mode 100644 index 8cc268fd6a8..00000000000 --- a/tests/integration/size_limit.go +++ /dev/null @@ -1,67 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package integration - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "go.temporal.io/server/common/log" -) - -type ( - sizeLimitSuite struct { - *require.Assertions - suite.Suite - - logger log.Logger - } -) - -func (s *sizeLimitSuite) SetupSuite() { -} - -func (s *sizeLimitSuite) TearDownSuite() { -} - -func (s *sizeLimitSuite) SetupTest() { - s.Assertions = require.New(s.T()) -} - -func (s *sizeLimitSuite) TearDownTest() { - -} - -func newSizeLimitSuite( - t *testing.T, - logger log.Logger, -) *sizeLimitSuite { - return &sizeLimitSuite{ - Assertions: require.New(t), - logger: logger, - } -} diff --git a/tools/cassandra/cqlclient_test.go b/tools/cassandra/cqlclient_tests.go similarity index 96% rename from tools/cassandra/cqlclient_test.go rename to tools/cassandra/cqlclient_tests.go index c891ec1d813..8acd30a8329 100644 --- a/tools/cassandra/cqlclient_test.go +++ b/tools/cassandra/cqlclient_tests.go @@ -25,10 +25,7 @@ package cassandra import ( - "testing" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" @@ -44,10 +41,6 @@ type ( var _ test.DB = (*cqlClient)(nil) -func TestCQLClientTestSuite(t *testing.T) { - suite.Run(t, new(CQLClientTestSuite)) -} - func (s *CQLClientTestSuite) SetupTest() { s.Assertions = require.New(s.T()) // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil } diff --git a/tools/cassandra/setupTask_test.go b/tools/cassandra/setupTask_tests.go similarity index 94% rename from tools/cassandra/setupTask_test.go rename to tools/cassandra/setupTask_tests.go index 9a88d497964..5920d6107ab 100644 --- a/tools/cassandra/setupTask_test.go +++ b/tools/cassandra/setupTask_tests.go @@ -26,9 +26,6 @@ package cassandra import ( "os" - "testing" - - "github.com/stretchr/testify/suite" "go.temporal.io/server/common/log/tag" "go.temporal.io/server/environment" @@ -42,10 +39,6 @@ type ( } ) -func TestSetupSchemaTestSuite(t *testing.T) { - suite.Run(t, new(SetupSchemaTestSuite)) -} - func (s *SetupSchemaTestSuite) SetupSuite() { if err := os.Setenv("CASSANDRA_HOST", environment.GetCassandraAddress()); err != nil { s.Logger.Fatal("Failed to set CASSANDRA_HOST", tag.Error(err)) diff --git a/tools/cassandra/updateTask_test.go b/tools/cassandra/updateTask_tests.go similarity index 94% rename from tools/cassandra/updateTask_test.go rename to tools/cassandra/updateTask_tests.go index 175faf50801..f45ed336ed4 100644 --- a/tools/cassandra/updateTask_test.go +++ b/tools/cassandra/updateTask_tests.go @@ -25,10 +25,6 @@ package cassandra import ( - "testing" - - "github.com/stretchr/testify/suite" - "go.temporal.io/server/common/log/tag" "go.temporal.io/server/schema/cassandra" "go.temporal.io/server/tools/common/schema/test" @@ -38,10 +34,6 @@ type UpdateSchemaTestSuite struct { test.UpdateSchemaTestBase } -func TestUpdateSchemaTestSuite(t *testing.T) { - suite.Run(t, new(UpdateSchemaTestSuite)) -} - func (s *UpdateSchemaTestSuite) SetupSuite() { client, err := newTestCQLClient(systemKeyspace) if err != nil { diff --git a/tools/cassandra/version_test.go b/tools/cassandra/version_tests.go similarity index 97% rename from tools/cassandra/version_test.go rename to tools/cassandra/version_tests.go index d88c12b9f60..e5acd5882f9 100644 --- a/tools/cassandra/version_test.go +++ b/tools/cassandra/version_tests.go @@ -27,7 +27,6 @@ package cassandra import ( "path" "runtime" - "testing" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -49,10 +48,6 @@ type ( } ) -func TestVersionTestSuite(t *testing.T) { - suite.Run(t, new(VersionTestSuite)) -} - func (s *VersionTestSuite) SetupTest() { s.Assertions = require.New(s.T()) // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil } diff --git a/tools/sql/clitest/connTest.go b/tools/sql/clitest/conn_tests.go similarity index 100% rename from tools/sql/clitest/connTest.go rename to tools/sql/clitest/conn_tests.go diff --git a/tools/sql/clitest/handler_test.go b/tools/sql/clitest/handler_tests.go similarity index 100% rename from tools/sql/clitest/handler_test.go rename to tools/sql/clitest/handler_tests.go diff --git a/tools/sql/clitest/setuptaskTest.go b/tools/sql/clitest/setupTask_tests.go similarity index 100% rename from tools/sql/clitest/setuptaskTest.go rename to tools/sql/clitest/setupTask_tests.go diff --git a/tools/sql/clitest/updatetaskTest.go b/tools/sql/clitest/updateTask_tests.go similarity index 100% rename from tools/sql/clitest/updatetaskTest.go rename to tools/sql/clitest/updateTask_tests.go diff --git a/tools/sql/clitest/versionTest.go b/tools/sql/clitest/version_tests.go similarity index 100% rename from tools/sql/clitest/versionTest.go rename to tools/sql/clitest/version_tests.go diff --git a/common/persistence/visibility/persistence-tests/postgresql_test.go b/tools/tests/cql_cli_test.go similarity index 74% rename from common/persistence/visibility/persistence-tests/postgresql_test.go rename to tools/tests/cql_cli_test.go index d1e7e085554..13aa7ae7148 100644 --- a/common/persistence/visibility/persistence-tests/postgresql_test.go +++ b/tools/tests/cql_cli_test.go @@ -22,19 +22,28 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package persistencetests +package tests import ( "testing" "github.com/stretchr/testify/suite" - persistencetests "go.temporal.io/server/common/persistence/persistence-tests" + "go.temporal.io/server/tools/cassandra" ) -func TestPostgreSQLVisibilityPersistenceSuite(t *testing.T) { - s := &VisibilityPersistenceSuite{ - TestBase: persistencetests.NewTestBaseWithSQL(persistencetests.GetPostgreSQLTestClusterOption()), - } - suite.Run(t, s) +func TestCQLClientTestSuite(t *testing.T) { + suite.Run(t, new(cassandra.CQLClientTestSuite)) +} + +func TestSetupCQLSchemaTestSuite(t *testing.T) { + suite.Run(t, new(cassandra.SetupSchemaTestSuite)) +} + +func TestUpdateCQLSchemaTestSuite(t *testing.T) { + suite.Run(t, new(cassandra.UpdateSchemaTestSuite)) +} + +func TestVersionTestSuite(t *testing.T) { + suite.Run(t, new(cassandra.VersionTestSuite)) } diff --git a/tools/sql/clitest/mysql_cli_test.go b/tools/tests/mysql_cli_test.go similarity index 84% rename from tools/sql/clitest/mysql_cli_test.go rename to tools/tests/mysql_cli_test.go index 72b1ed398c2..9b21ab4a287 100644 --- a/tools/sql/clitest/mysql_cli_test.go +++ b/tools/tests/mysql_cli_test.go @@ -22,7 +22,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package clitest +package tests import ( "strconv" @@ -33,13 +33,16 @@ import ( "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" "go.temporal.io/server/environment" mysqlversion "go.temporal.io/server/schema/mysql" + "go.temporal.io/server/tools/sql/clitest" ) const ( - testMySQLExecutionSchemaFile = "../../../schema/mysql/v57/temporal/schema.sql" - testMySQLVisibilitySchemaFile = "../../../schema/mysql/v57/visibility/schema.sql" - testMySQLExecutionSchemaVersionDir = "../../../schema/mysql/v57/temporal/versioned" - testMySQLVisibilitySchemaVersionDir = "../../../schema/mysql/v57/visibility/versioned" + testUser = "temporal" + testPassword = "temporal" + testMySQLExecutionSchemaFile = "../../schema/mysql/v57/temporal/schema.sql" + testMySQLVisibilitySchemaFile = "../../schema/mysql/v57/visibility/schema.sql" + testMySQLExecutionSchemaVersionDir = "../../schema/mysql/v57/temporal/versioned" + testMySQLVisibilitySchemaVersionDir = "../../schema/mysql/v57/visibility/versioned" testMySQLQuery = ` -- test sql file content @@ -75,7 +78,7 @@ CREATE TABLE current_executions( ) func TestMySQLConnTestSuite(t *testing.T) { - suite.Run(t, NewSQLConnTestSuite( + suite.Run(t, clitest.NewSQLConnTestSuite( environment.GetMySQLAddress(), strconv.Itoa(environment.GetMySQLPort()), mysql.PluginName, @@ -84,7 +87,7 @@ func TestMySQLConnTestSuite(t *testing.T) { } func TestMySQLHandlerTestSuite(t *testing.T) { - suite.Run(t, NewHandlerTestSuite( + suite.Run(t, clitest.NewHandlerTestSuite( environment.GetMySQLAddress(), strconv.Itoa(environment.GetMySQLPort()), mysql.PluginName, @@ -96,7 +99,7 @@ func TestMySQLSetupSchemaTestSuite(t *testing.T) { t.Setenv("SQL_PORT", strconv.Itoa(environment.GetMySQLPort())) t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewSetupSchemaTestSuite( + suite.Run(t, clitest.NewSetupSchemaTestSuite( environment.GetMySQLAddress(), strconv.Itoa(environment.GetMySQLPort()), mysql.PluginName, @@ -109,7 +112,7 @@ func TestMySQLUpdateSchemaTestSuite(t *testing.T) { t.Setenv("SQL_PORT", strconv.Itoa(environment.GetMySQLPort())) t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewUpdateSchemaTestSuite( + suite.Run(t, clitest.NewUpdateSchemaTestSuite( environment.GetMySQLAddress(), strconv.Itoa(environment.GetMySQLPort()), mysql.PluginName, @@ -124,7 +127,7 @@ func TestMySQLUpdateSchemaTestSuite(t *testing.T) { func TestMySQLVersionTestSuite(t *testing.T) { t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewVersionTestSuite( + suite.Run(t, clitest.NewVersionTestSuite( environment.GetMySQLAddress(), strconv.Itoa(environment.GetMySQLPort()), mysql.PluginName, diff --git a/tools/sql/clitest/postgresql_cli_test.go b/tools/tests/postgresql_cli_test.go similarity index 85% rename from tools/sql/clitest/postgresql_cli_test.go rename to tools/tests/postgresql_cli_test.go index 1502d83d395..5cd590709ca 100644 --- a/tools/sql/clitest/postgresql_cli_test.go +++ b/tools/tests/postgresql_cli_test.go @@ -22,7 +22,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package clitest +package tests import ( "strconv" @@ -33,13 +33,14 @@ import ( "go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql" "go.temporal.io/server/environment" postgresqlversion "go.temporal.io/server/schema/postgresql" + "go.temporal.io/server/tools/sql/clitest" ) const ( - testPostgreSQLExecutionSchemaFile = "../../../schema/postgresql/v96/temporal/schema.sql" - testPostgreSQLVisibilitySchemaFile = "../../../schema/postgresql/v96/visibility/schema.sql" - testPostgreSQLExecutionSchemaVersionDir = "../../../schema/postgresql/v96/temporal/versioned" - testPostgreSQLVisibilitySchemaVersionDir = "../../../schema/postgresql/v96/visibility/versioned" + testPostgreSQLExecutionSchemaFile = "../../schema/postgresql/v96/temporal/schema.sql" + testPostgreSQLVisibilitySchemaFile = "../../schema/postgresql/v96/visibility/schema.sql" + testPostgreSQLExecutionSchemaVersionDir = "../../schema/postgresql/v96/temporal/versioned" + testPostgreSQLVisibilitySchemaVersionDir = "../../schema/postgresql/v96/visibility/versioned" testPostgreSQLQuery = ` -- test sql file content @@ -74,7 +75,7 @@ CREATE TABLE current_executions( ) func TestPostgreSQLConnTestSuite(t *testing.T) { - suite.Run(t, NewSQLConnTestSuite( + suite.Run(t, clitest.NewSQLConnTestSuite( environment.GetPostgreSQLAddress(), strconv.Itoa(environment.GetPostgreSQLPort()), postgresql.PluginName, testPostgreSQLQuery, @@ -82,7 +83,7 @@ func TestPostgreSQLConnTestSuite(t *testing.T) { } func TestPostgreSQLHandlerTestSuite(t *testing.T) { - suite.Run(t, NewHandlerTestSuite( + suite.Run(t, clitest.NewHandlerTestSuite( environment.GetPostgreSQLAddress(), strconv.Itoa(environment.GetPostgreSQLPort()), postgresql.PluginName, @@ -94,7 +95,7 @@ func TestPostgreSQLSetupSchemaTestSuite(t *testing.T) { t.Setenv("SQL_PORT", strconv.Itoa(environment.GetPostgreSQLPort())) t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewSetupSchemaTestSuite( + suite.Run(t, clitest.NewSetupSchemaTestSuite( environment.GetPostgreSQLAddress(), strconv.Itoa(environment.GetPostgreSQLPort()), postgresql.PluginName, @@ -107,7 +108,7 @@ func TestPostgreSQLUpdateSchemaTestSuite(t *testing.T) { t.Setenv("SQL_PORT", strconv.Itoa(environment.GetPostgreSQLPort())) t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewUpdateSchemaTestSuite( + suite.Run(t, clitest.NewUpdateSchemaTestSuite( environment.GetPostgreSQLAddress(), strconv.Itoa(environment.GetPostgreSQLPort()), postgresql.PluginName, @@ -122,7 +123,7 @@ func TestPostgreSQLUpdateSchemaTestSuite(t *testing.T) { func TestPostgreSQLVersionTestSuite(t *testing.T) { t.Setenv("SQL_USER", testUser) t.Setenv("SQL_PASSWORD", testPassword) - suite.Run(t, NewVersionTestSuite( + suite.Run(t, clitest.NewVersionTestSuite( environment.GetPostgreSQLAddress(), strconv.Itoa(environment.GetPostgreSQLPort()), postgresql.PluginName,