diff --git a/common/persistence/nosql/nosqlPersistenceTest.go b/common/persistence/nosql/nosqlPersistenceTest.go index 03b165f87a4..4b4c90bd476 100644 --- a/common/persistence/nosql/nosqlPersistenceTest.go +++ b/common/persistence/nosql/nosqlPersistenceTest.go @@ -32,27 +32,35 @@ import ( // testCluster allows executing cassandra operations in testing. type testCluster struct { - keyspace string - cfg config.NoSQL + keyspace string + schemaBaseDir string + cfg config.NoSQL } var _ testcluster.PersistenceTestCluster = (*testCluster)(nil) // NewTestCluster returns a new cassandra test cluster -func NewTestCluster(pluginName, keyspace, username, password, host string, port int, protoVersion int) testcluster.PersistenceTestCluster { - var tc testCluster - tc.keyspace = keyspace - tc.cfg = config.NoSQL{ - PluginName: pluginName, - User: username, - Password: password, - Hosts: host, - Port: port, - MaxConns: 2, - Keyspace: keyspace, - ProtoVersion: protoVersion, +// if schemaBaseDir is empty, it will be auto-resolved based on os.Getwd() +// otherwise the specified value will be used (used by internal tests) +func NewTestCluster( + pluginName, keyspace, username, password, host string, + port, protoVersion int, + schemaBaseDir string, +) testcluster.PersistenceTestCluster { + return &testCluster{ + keyspace: keyspace, + schemaBaseDir: schemaBaseDir, + cfg: config.NoSQL{ + PluginName: pluginName, + User: username, + Password: password, + Hosts: host, + Port: port, + MaxConns: 2, + Keyspace: keyspace, + ProtoVersion: protoVersion, + }, } - return &tc } // Config returns the persistence config for connecting to this test cluster @@ -78,7 +86,7 @@ func (s *testCluster) SetupTestDatabase() { if err != nil { log.Fatal(err) } - err = adminDB.SetupTestDatabase() + err = adminDB.SetupTestDatabase(s.schemaBaseDir) if err != nil { log.Fatal(err) } diff --git a/common/persistence/nosql/nosqlplugin/cassandra/admin.go b/common/persistence/nosql/nosqlplugin/cassandra/admin.go index 05ed74865f5..9ff98bf2366 100644 --- a/common/persistence/nosql/nosqlplugin/cassandra/admin.go +++ b/common/persistence/nosql/nosqlplugin/cassandra/admin.go @@ -42,22 +42,24 @@ const ( var _ nosqlplugin.AdminDB = (*cdb)(nil) -func (db *cdb) SetupTestDatabase() error { +func (db *cdb) SetupTestDatabase(schemaBaseDir string) error { err := createCassandraKeyspace(db.session, db.cfg.Keyspace, 1, true) if err != nil { return err } - cadencePackageDir, err := getCadencePackageDir() - if err != nil { - log.Fatal(err) + if schemaBaseDir == "" { + cadencePackageDir, err := getCadencePackageDir() + if err != nil { + log.Fatal(err) + } + schemaBaseDir = cadencePackageDir + testSchemaDir } - schemaDir := cadencePackageDir + testSchemaDir - err = db.loadSchema([]string{"schema.cql"}, schemaDir) + err = db.loadSchema([]string{"schema.cql"}, schemaBaseDir) if err != nil { return err } - err = db.loadVisibilitySchema([]string{"schema.cql"}, schemaDir) + err = db.loadVisibilitySchema([]string{"schema.cql"}, schemaBaseDir) if err != nil { return err } @@ -65,8 +67,8 @@ func (db *cdb) SetupTestDatabase() error { } // loadSchema from PersistenceTestCluster interface -func (db *cdb) loadSchema(fileNames []string, schemaDir string) error { - workflowSchemaDir := schemaDir + "/cadence" +func (db *cdb) loadSchema(fileNames []string, schemaBaseDir string) error { + workflowSchemaDir := schemaBaseDir + "/cadence" err := loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, true, nil, db.cfg.ProtoVersion) if err != nil && !strings.Contains(err.Error(), "AlreadyExists") { // TODO: should we remove the second condition? @@ -76,8 +78,8 @@ func (db *cdb) loadSchema(fileNames []string, schemaDir string) error { } // loadVisibilitySchema from PersistenceTestCluster interface -func (db *cdb) loadVisibilitySchema(fileNames []string, schemaDir string) error { - workflowSchemaDir := schemaDir + "visibility" +func (db *cdb) loadVisibilitySchema(fileNames []string, schemaBaseDir string) error { + workflowSchemaDir := schemaBaseDir + "/visibility" err := loadCassandraSchema(workflowSchemaDir, fileNames, db.cfg.Hosts, db.cfg.Port, db.cfg.Keyspace, false, nil, db.cfg.ProtoVersion) if err != nil && !strings.Contains(err.Error(), "AlreadyExists") { // TODO: should we remove the second condition? diff --git a/common/persistence/nosql/nosqlplugin/dynamodb/admin.go b/common/persistence/nosql/nosqlplugin/dynamodb/admin.go index 391623c38e5..7a5a07b584c 100644 --- a/common/persistence/nosql/nosqlplugin/dynamodb/admin.go +++ b/common/persistence/nosql/nosqlplugin/dynamodb/admin.go @@ -27,7 +27,7 @@ import ( var _ nosqlplugin.AdminDB = (*ddb)(nil) -func (db *ddb) SetupTestDatabase() error { +func (db *ddb) SetupTestDatabase(schemaBaseDir string) error { panic("TODO") } diff --git a/common/persistence/nosql/nosqlplugin/interfaces.go b/common/persistence/nosql/nosqlplugin/interfaces.go index 2ba77980ee5..fae8eaf5fa0 100644 --- a/common/persistence/nosql/nosqlplugin/interfaces.go +++ b/common/persistence/nosql/nosqlplugin/interfaces.go @@ -38,7 +38,7 @@ type ( // AdminDB is for tooling and testing AdminDB interface { - SetupTestDatabase() error + SetupTestDatabase(schemaBaseDir string) error TeardownTestDatabase() error } diff --git a/common/persistence/nosql/nosqlplugin/interfaces_mock.go b/common/persistence/nosql/nosqlplugin/interfaces_mock.go index b192cc4648b..10d31fb7f40 100644 --- a/common/persistence/nosql/nosqlplugin/interfaces_mock.go +++ b/common/persistence/nosql/nosqlplugin/interfaces_mock.go @@ -113,17 +113,17 @@ func (m *MockAdminDB) EXPECT() *MockAdminDBMockRecorder { } // SetupTestDatabase mocks base method. -func (m *MockAdminDB) SetupTestDatabase() error { +func (m *MockAdminDB) SetupTestDatabase(schemaBaseDir string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetupTestDatabase") + ret := m.ctrl.Call(m, "SetupTestDatabase", schemaBaseDir) ret0, _ := ret[0].(error) return ret0 } // SetupTestDatabase indicates an expected call of SetupTestDatabase. -func (mr *MockAdminDBMockRecorder) SetupTestDatabase() *gomock.Call { +func (mr *MockAdminDBMockRecorder) SetupTestDatabase(schemaBaseDir string) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetupTestDatabase", reflect.TypeOf((*MockAdminDB)(nil).SetupTestDatabase)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetupTestDatabase", reflect.TypeOf((*MockAdminDB)(nil).SetupTestDatabase), schemaBaseDir) } // TeardownTestDatabase mocks base method. diff --git a/common/persistence/persistence-tests/persistenceTestBase.go b/common/persistence/persistence-tests/persistenceTestBase.go index 8555f42bee8..0b94bb655c1 100644 --- a/common/persistence/persistence-tests/persistenceTestBase.go +++ b/common/persistence/persistence-tests/persistenceTestBase.go @@ -127,7 +127,7 @@ func NewTestBaseWithNoSQL(options *TestBaseOptions) TestBase { if options.DBName == "" { options.DBName = "test_" + GenerateRandomDBName(10) } - testCluster := nosql.NewTestCluster(options.DBPluginName, options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.ProtoVersion) + testCluster := nosql.NewTestCluster(options.DBPluginName, options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.ProtoVersion, "") metadata := options.ClusterMetadata if metadata == nil { metadata = cluster.GetTestClusterMetadata(false, false) diff --git a/host/client_integration_test.go b/host/client_integration_test.go index a0a48c42160..aaf97425a3d 100644 --- a/host/client_integration_test.go +++ b/host/client_integration_test.go @@ -40,7 +40,7 @@ import ( "go.uber.org/cadence/activity" "go.uber.org/cadence/client" "go.uber.org/cadence/encoded" - cworker "go.uber.org/cadence/worker" + "go.uber.org/cadence/worker" "go.uber.org/cadence/workflow" "go.uber.org/yarpc" "go.uber.org/yarpc/transport/tchannel" @@ -57,19 +57,6 @@ func init() { workflow.Register(testChildWorkflow) } -type ( - ClientIntegrationSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - IntegrationBase - wfService workflowserviceclient.Interface - wfClient client.Client - worker cworker.Worker - taskList string - } -) - func TestClientIntegrationSuite(t *testing.T) { flag.Parse() @@ -100,7 +87,7 @@ func (s *ClientIntegrationSuite) SetupSuite() { s.wfClient = client.NewClient(s.wfService, s.domainName, nil) s.taskList = "client-integration-test-tasklist" - s.worker = cworker.New(s.wfService, s.domainName, s.taskList, cworker.Options{}) + s.worker = worker.New(s.wfService, s.domainName, s.taskList, worker.Options{}) if err := s.worker.Start(); err != nil { s.Logger.Fatal("Error when start worker", tag.Error(err)) } @@ -208,12 +195,12 @@ func testDataConverterWorkflow(ctx workflow.Context, tl string) (string, error) return result + "," + result1, nil } -func (s *ClientIntegrationSuite) startWorkerWithDataConverter(tl string, dataConverter encoded.DataConverter) cworker.Worker { - opts := cworker.Options{} +func (s *ClientIntegrationSuite) startWorkerWithDataConverter(tl string, dataConverter encoded.DataConverter) worker.Worker { + opts := worker.Options{} if dataConverter != nil { opts.DataConverter = dataConverter } - worker := cworker.New(s.wfService, s.domainName, tl, opts) + worker := worker.New(s.wfService, s.domainName, tl, opts) if err := worker.Start(); err != nil { s.Logger.Fatal("Error when start worker with data converter", tag.Error(err)) } diff --git a/host/integration_test.go b/host/integration_test.go index b2ac4923afe..1d792e3755c 100644 --- a/host/integration_test.go +++ b/host/integration_test.go @@ -46,15 +46,6 @@ import ( "github.com/uber/cadence/service/matching" ) -type ( - IntegrationSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - IntegrationBase - } -) - func TestIntegrationSuite(t *testing.T) { flag.Parse() diff --git a/host/ndc/integration_test.go b/host/ndc/integration_test.go index d8dea6632c9..32b53938ba7 100644 --- a/host/ndc/integration_test.go +++ b/host/ndc/integration_test.go @@ -39,48 +39,15 @@ import ( adminClient "github.com/uber/cadence/client/admin" "github.com/uber/cadence/common" "github.com/uber/cadence/common/cache" - "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/log/loggerimpl" "github.com/uber/cadence/common/log/tag" "github.com/uber/cadence/common/persistence" pt "github.com/uber/cadence/common/persistence/persistence-tests" - "github.com/uber/cadence/common/persistence/persistence-tests/testcluster" test "github.com/uber/cadence/common/testing" "github.com/uber/cadence/common/types" "github.com/uber/cadence/host" ) -type ( - NDCIntegrationTestSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - suite.Suite - active *host.TestCluster - generator test.Generator - serializer persistence.PayloadSerializer - logger log.Logger - - domainName string - domainID string - version int64 - versionIncrement int64 - mockAdminClient map[string]adminClient.Client - standByReplicationTasksChan chan *types.ReplicationTask - standByTaskID int64 - - clusterConfigs []*host.TestClusterConfig - defaultTestCluster testcluster.PersistenceTestCluster - visibilityTestCluster testcluster.PersistenceTestCluster - } - - NDCIntegrationTestSuiteParams struct { - ClusterConfigs []*host.TestClusterConfig - DefaultTestCluster testcluster.PersistenceTestCluster - VisibilityTestCluster testcluster.PersistenceTestCluster - } -) - var ( clusterName = []string{"active", "standby", "other"} clusterReplicationConfig = []*types.ClusterReplicationConfiguration{ @@ -109,14 +76,6 @@ func TestNDCIntegrationTestSuite(t *testing.T) { suite.Run(t, s) } -func NewNDCIntegrationTestSuite(params NDCIntegrationTestSuiteParams) *NDCIntegrationTestSuite { - return &NDCIntegrationTestSuite{ - clusterConfigs: params.ClusterConfigs, - defaultTestCluster: params.DefaultTestCluster, - visibilityTestCluster: params.VisibilityTestCluster, - } -} - func (s *NDCIntegrationTestSuite) SetupSuite() { zapLogger, err := zap.NewDevelopment() // cannot use s.Nil since it is not initialized diff --git a/host/ndc/test_suites.go b/host/ndc/test_suites.go new file mode 100644 index 00000000000..6529e40776c --- /dev/null +++ b/host/ndc/test_suites.go @@ -0,0 +1,76 @@ +// Copyright (c) 2021 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 ndc + +import ( + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/uber/cadence/client/admin" + "github.com/uber/cadence/common/log" + "github.com/uber/cadence/common/persistence" + "github.com/uber/cadence/common/persistence/persistence-tests/testcluster" + "github.com/uber/cadence/common/testing" + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/host" +) + +// NOTE: the following definitions can't be defined in *_test.go +// since they need to be exported and used by our internal tests + +type ( + NDCIntegrationTestSuite struct { + // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, + // not merely log an error + *require.Assertions + suite.Suite + active *host.TestCluster + generator testing.Generator + serializer persistence.PayloadSerializer + logger log.Logger + + domainName string + domainID string + version int64 + versionIncrement int64 + mockAdminClient map[string]admin.Client + standByReplicationTasksChan chan *types.ReplicationTask + standByTaskID int64 + + clusterConfigs []*host.TestClusterConfig + defaultTestCluster testcluster.PersistenceTestCluster + visibilityTestCluster testcluster.PersistenceTestCluster + } + + NDCIntegrationTestSuiteParams struct { + ClusterConfigs []*host.TestClusterConfig + DefaultTestCluster testcluster.PersistenceTestCluster + VisibilityTestCluster testcluster.PersistenceTestCluster + } +) + +func NewNDCIntegrationTestSuite(params NDCIntegrationTestSuiteParams) *NDCIntegrationTestSuite { + return &NDCIntegrationTestSuite{ + clusterConfigs: params.ClusterConfigs, + defaultTestCluster: params.DefaultTestCluster, + visibilityTestCluster: params.VisibilityTestCluster, + } +} diff --git a/host/size_limit_test.go b/host/size_limit_test.go index 44255283b15..8e18bf76fd0 100644 --- a/host/size_limit_test.go +++ b/host/size_limit_test.go @@ -37,13 +37,6 @@ import ( "github.com/uber/cadence/common/types" ) -type SizeLimitIntegrationSuite struct { - // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, - // not merely log an error - *require.Assertions - IntegrationBase -} - func TestSizeLimitIntegrationSuite(t *testing.T) { flag.Parse() diff --git a/host/test_suites.go b/host/test_suites.go new file mode 100644 index 00000000000..d245858ecd5 --- /dev/null +++ b/host/test_suites.go @@ -0,0 +1,59 @@ +// Copyright (c) 2021 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 host + +import ( + "go.uber.org/cadence/.gen/go/cadence/workflowserviceclient" + "go.uber.org/cadence/client" + "go.uber.org/cadence/worker" + + "github.com/stretchr/testify/require" +) + +// NOTE: the following definitions can't be defined in *_test.go +// since they need to be exported and used by our internal tests + +type ( + IntegrationSuite struct { + // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, + // not merely log an error + *require.Assertions + IntegrationBase + } + + SizeLimitIntegrationSuite struct { + // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, + // not merely log an error + *require.Assertions + IntegrationBase + } + + ClientIntegrationSuite struct { + // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, + // not merely log an error + *require.Assertions + IntegrationBase + wfService workflowserviceclient.Interface + wfClient client.Client + worker worker.Worker + taskList string + } +) diff --git a/host/testcluster.go b/host/testcluster.go index 8853fd397cf..49200c90d0d 100644 --- a/host/testcluster.go +++ b/host/testcluster.go @@ -205,7 +205,7 @@ func NewPersistenceTestCluster(clusterConfig *TestClusterConfig) testcluster.Per // TODO refactor to support other NoSQL ops := clusterConfig.Persistence ops.DBPluginName = "cassandra" - testCluster = nosql.NewTestCluster(ops.DBPluginName, ops.DBName, ops.DBUsername, ops.DBPassword, ops.DBHost, ops.DBPort, ops.ProtoVersion) + testCluster = nosql.NewTestCluster(ops.DBPluginName, ops.DBName, ops.DBUsername, ops.DBPassword, ops.DBHost, ops.DBPort, ops.ProtoVersion, "") } else if TestFlags.PersistenceType == config.StoreTypeSQL { var ops *persistencetests.TestBaseOptions if TestFlags.SQLPluginName == mysql.PluginName {