Skip to content

Commit

Permalink
Refactor integration tests (cadence-workflow#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored Mar 30, 2021
1 parent e286ca0 commit dfc42d3
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 287 deletions.
64 changes: 42 additions & 22 deletions common/persistence/persistence-tests/persistenceTestBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ type (
PayloadSerializer p.PayloadSerializer
}

// TestBaseParams defines the input of TestBase
TestBaseParams struct {
DefaultTestCluster PersistenceTestCluster
VisibilityTestCluster PersistenceTestCluster
ClusterMetadata cluster.Metadata
}

// PersistenceTestCluster exposes management operations on a database
PersistenceTestCluster interface {
SetupTestDatabase()
Expand All @@ -106,13 +113,37 @@ const (
defaultScheduleToStartTimeout = 111
)

// NewTestBaseFromParams returns a customized test base from given input
func NewTestBaseFromParams(params TestBaseParams) TestBase {
logger, err := loggerimpl.NewDevelopment()
if err != nil {
panic(err)
}
return TestBase{
DefaultTestCluster: params.DefaultTestCluster,
VisibilityTestCluster: params.VisibilityTestCluster,
ClusterMetadata: params.ClusterMetadata,
PayloadSerializer: p.NewPayloadSerializer(),
Logger: logger,
}
}

// NewTestBaseWithCassandra returns a persistence test base backed by cassandra datastore
func NewTestBaseWithCassandra(options *TestBaseOptions) TestBase {
if options.DBName == "" {
options.DBName = "test_" + GenerateRandomDBName(10)
}
testCluster := cassandra.NewTestCluster(options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.SchemaDir)
return newTestBase(options, testCluster)
metadata := options.ClusterMetadata
if metadata == nil {
metadata = cluster.GetTestClusterMetadata(false, false)
}
params := TestBaseParams{
DefaultTestCluster: testCluster,
VisibilityTestCluster: testCluster,
ClusterMetadata: metadata,
}
return NewTestBaseFromParams(params)
}

// NewTestBaseWithSQL returns a new persistence test base backed by SQL
Expand All @@ -121,7 +152,16 @@ func NewTestBaseWithSQL(options *TestBaseOptions) TestBase {
options.DBName = "test_" + GenerateRandomDBName(10)
}
testCluster := sql.NewTestCluster(options.SQLDBPluginName, options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.SchemaDir)
return newTestBase(options, testCluster)
metadata := options.ClusterMetadata
if metadata == nil {
metadata = cluster.GetTestClusterMetadata(false, false)
}
params := TestBaseParams{
DefaultTestCluster: testCluster,
VisibilityTestCluster: testCluster,
ClusterMetadata: metadata,
}
return NewTestBaseFromParams(params)
}

// NewTestBase returns a persistence test base backed by either cassandra or sql
Expand All @@ -136,26 +176,6 @@ func NewTestBase(options *TestBaseOptions) TestBase {
}
}

func newTestBase(options *TestBaseOptions, testCluster PersistenceTestCluster) TestBase {
metadata := options.ClusterMetadata
if metadata == nil {
metadata = cluster.GetTestClusterMetadata(false, false)
}
options.ClusterMetadata = metadata
base := TestBase{
DefaultTestCluster: testCluster,
VisibilityTestCluster: testCluster,
ClusterMetadata: metadata,
PayloadSerializer: p.NewPayloadSerializer(),
}
logger, err := loggerimpl.NewDevelopment()
if err != nil {
panic(err)
}
base.Logger = logger
return base
}

// Config returns the persistence configuration for this test
func (s *TestBase) Config() config.Persistence {
cfg := s.DefaultTestCluster.Config()
Expand Down
16 changes: 8 additions & 8 deletions host/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/uber/cadence/service/matching"
)

func (s *integrationSuite) TestActivityHeartBeatWorkflow_Success() {
func (s *IntegrationSuite) TestActivityHeartBeatWorkflow_Success() {
id := "integration-heartbeat-test"
wt := "integration-heartbeat-test-type"
tl := "integration-heartbeat-test-tasklist"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (s *integrationSuite) TestActivityHeartBeatWorkflow_Success() {
}
}

func (s *integrationSuite) TestActivityHeartbeatDetailsDuringRetry() {
func (s *IntegrationSuite) TestActivityHeartbeatDetailsDuringRetry() {
id := "integration-heartbeat-details-retry-test"
wt := "integration-heartbeat-details-retry-type"
tl := "integration-heartbeat-details-retry-tasklist"
Expand Down Expand Up @@ -337,7 +337,7 @@ func (s *integrationSuite) TestActivityHeartbeatDetailsDuringRetry() {
s.Equal(3, activityExecutedCount)
}

func (s *integrationSuite) TestActivityRetry() {
func (s *IntegrationSuite) TestActivityRetry() {
id := "integration-activity-retry-test"
wt := "integration-activity-retry-type"
tl := "integration-activity-retry-tasklist"
Expand Down Expand Up @@ -552,7 +552,7 @@ func (s *integrationSuite) TestActivityRetry() {
s.True(activityExecutedCount == 2)
}

func (s *integrationSuite) TestActivityHeartBeatWorkflow_Timeout() {
func (s *IntegrationSuite) TestActivityHeartBeatWorkflow_Timeout() {
id := "integration-heartbeat-timeout-test"
wt := "integration-heartbeat-timeout-test-type"
tl := "integration-heartbeat-timeout-test-tasklist"
Expand Down Expand Up @@ -655,7 +655,7 @@ func (s *integrationSuite) TestActivityHeartBeatWorkflow_Timeout() {
s.True(workflowComplete)
}

func (s *integrationSuite) TestActivityTimeouts() {
func (s *IntegrationSuite) TestActivityTimeouts() {
id := "integration-activity-timeout-test"
wt := "integration-activity-timeout-test-type"
tl := "integration-activity-timeout-test-tasklist"
Expand Down Expand Up @@ -897,7 +897,7 @@ func (s *integrationSuite) TestActivityTimeouts() {
s.False(workflowFailed)
}

func (s *integrationSuite) TestActivityHeartbeatTimeouts() {
func (s *IntegrationSuite) TestActivityHeartbeatTimeouts() {
id := "integration-activity-heartbeat-timeout-test"
wt := "integration-activity-heartbeat-timeout-test-type"
tl := "integration-activity-heartbeat-timeout-test-tasklist"
Expand Down Expand Up @@ -1088,7 +1088,7 @@ func (s *integrationSuite) TestActivityHeartbeatTimeouts() {
}
}

func (s *integrationSuite) TestActivityCancellation() {
func (s *IntegrationSuite) TestActivityCancellation() {
id := "integration-activity-cancellation-test"
wt := "integration-activity-cancellation-test-type"
tl := "integration-activity-cancellation-test-tasklist"
Expand Down Expand Up @@ -1215,7 +1215,7 @@ func (s *integrationSuite) TestActivityCancellation() {
s.Logger.Info("Waiting for workflow to complete", tag.WorkflowRunID(we.RunID))
}

func (s *integrationSuite) TestActivityCancellationNotStarted() {
func (s *IntegrationSuite) TestActivityCancellationNotStarted() {
id := "integration-activity-notstarted-cancellation-test"
wt := "integration-activity-notstarted-cancellation-test-type"
tl := "integration-activity-notstarted-cancellation-test-tasklist"
Expand Down
18 changes: 9 additions & 9 deletions host/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
retryBackoffTime = 200 * time.Millisecond
)

func (s *integrationSuite) TestArchival_TimerQueueProcessor() {
func (s *IntegrationSuite) TestArchival_TimerQueueProcessor() {
s.True(s.testCluster.archiverBase.metadata.GetHistoryConfig().ClusterConfiguredForArchival())

domainID := s.getDomainID(s.archivalDomainName)
Expand All @@ -61,7 +61,7 @@ func (s *integrationSuite) TestArchival_TimerQueueProcessor() {
s.True(s.isMutableStateDeleted(domainID, execution))
}

func (s *integrationSuite) TestArchival_ContinueAsNew() {
func (s *IntegrationSuite) TestArchival_ContinueAsNew() {
s.True(s.testCluster.archiverBase.metadata.GetHistoryConfig().ClusterConfiguredForArchival())

domainID := s.getDomainID(s.archivalDomainName)
Expand All @@ -83,7 +83,7 @@ func (s *integrationSuite) TestArchival_ContinueAsNew() {
}
}

func (s *integrationSuite) TestArchival_ArchiverWorker() {
func (s *IntegrationSuite) TestArchival_ArchiverWorker() {
s.True(s.testCluster.archiverBase.metadata.GetHistoryConfig().ClusterConfiguredForArchival())

domainID := s.getDomainID(s.archivalDomainName)
Expand All @@ -102,7 +102,7 @@ func (s *integrationSuite) TestArchival_ArchiverWorker() {
s.True(s.isMutableStateDeleted(domainID, execution))
}

func (s *integrationSuite) TestVisibilityArchival() {
func (s *IntegrationSuite) TestVisibilityArchival() {
s.True(s.testCluster.archiverBase.metadata.GetVisibilityConfig().ClusterConfiguredForArchival())

domainID := s.getDomainID(s.archivalDomainName)
Expand Down Expand Up @@ -147,15 +147,15 @@ func (s *integrationSuite) TestVisibilityArchival() {
}
}

func (s *integrationSuite) getDomainID(domain string) string {
func (s *IntegrationSuite) getDomainID(domain string) string {
domainResp, err := s.engine.DescribeDomain(createContext(), &types.DescribeDomainRequest{
Name: common.StringPtr(s.archivalDomainName),
})
s.Nil(err)
return domainResp.DomainInfo.GetUUID()
}

func (s *integrationSuite) isHistoryArchived(domain string, execution *types.WorkflowExecution) bool {
func (s *IntegrationSuite) isHistoryArchived(domain string, execution *types.WorkflowExecution) bool {
request := &types.GetWorkflowExecutionHistoryRequest{
Domain: s.archivalDomainName,
Execution: execution,
Expand All @@ -171,7 +171,7 @@ func (s *integrationSuite) isHistoryArchived(domain string, execution *types.Wor
return false
}

func (s *integrationSuite) isHistoryDeleted(domainID string, execution *types.WorkflowExecution) bool {
func (s *IntegrationSuite) isHistoryDeleted(domainID string, execution *types.WorkflowExecution) bool {
shardID := common.WorkflowIDToHistoryShard(execution.WorkflowID, s.testClusterConfig.HistoryConfig.NumHistoryShards)
request := &persistence.GetHistoryTreeRequest{
TreeID: execution.GetRunID(),
Expand All @@ -190,7 +190,7 @@ func (s *integrationSuite) isHistoryDeleted(domainID string, execution *types.Wo
return false
}

func (s *integrationSuite) isMutableStateDeleted(domainID string, execution *types.WorkflowExecution) bool {
func (s *IntegrationSuite) isMutableStateDeleted(domainID string, execution *types.WorkflowExecution) bool {
request := &persistence.GetWorkflowExecutionRequest{
DomainID: domainID,
Execution: *execution,
Expand All @@ -209,7 +209,7 @@ func (s *integrationSuite) isMutableStateDeleted(domainID string, execution *typ
return false
}

func (s *integrationSuite) startAndFinishWorkflow(id, wt, tl, domain, domainID string, numActivities, numRuns int) []string {
func (s *IntegrationSuite) startAndFinishWorkflow(id, wt, tl, domain, domainID string, numActivities, numRuns int) []string {
identity := "worker1"
activityName := "activity_type1"
workflowType := &types.WorkflowType{
Expand Down
6 changes: 3 additions & 3 deletions host/cancelworkflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/uber/cadence/common/types"
)

func (s *integrationSuite) TestExternalRequestCancelWorkflowExecution() {
func (s *IntegrationSuite) TestExternalRequestCancelWorkflowExecution() {
id := "integration-request-cancel-workflow-test"
wt := "integration-request-cancel-workflow-test-type"
tl := "integration-request-cancel-workflow-test-tasklist"
Expand Down Expand Up @@ -170,7 +170,7 @@ GetHistoryLoop:
s.True(executionCancelled)
}

func (s *integrationSuite) TestRequestCancelWorkflowDecisionExecution() {
func (s *IntegrationSuite) TestRequestCancelWorkflowDecisionExecution() {
id := "integration-cancel-workflow-decision-test"
wt := "integration-cancel-workflow-decision-test-type"
tl := "integration-cancel-workflow-decision-test-tasklist"
Expand Down Expand Up @@ -404,7 +404,7 @@ GetHistoryLoop:
s.True(executionCancelled)
}

func (s *integrationSuite) TestRequestCancelWorkflowDecisionExecution_UnKnownTarget() {
func (s *IntegrationSuite) TestRequestCancelWorkflowDecisionExecution_UnKnownTarget() {
id := "integration-cancel-unknown-workflow-decision-test"
wt := "integration-cancel-unknown-workflow-decision-test-type"
tl := "integration-cancel-unknown-workflow-decision-test-tasklist"
Expand Down
36 changes: 25 additions & 11 deletions host/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() {
}

type (
clientIntegrationSuite struct {
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
Expand All @@ -72,11 +72,25 @@ type (

func TestClientIntegrationSuite(t *testing.T) {
flag.Parse()
suite.Run(t, new(clientIntegrationSuite))

clusterConfig, err := GetTestClusterConfig("testdata/clientintegrationtestcluster.yaml")
if err != nil {
panic(err)
}
testCluster := NewPersistenceTestCluster(clusterConfig)

s := new(ClientIntegrationSuite)
params := IntegrationBaseParams{
DefaultTestCluster: testCluster,
VisibilityTestCluster: testCluster,
TestClusterConfig: clusterConfig,
}
s.IntegrationBase = NewIntegrationBase(params)
suite.Run(t, s)
}

func (s *clientIntegrationSuite) SetupSuite() {
s.setupSuite("testdata/clientintegrationtestcluster.yaml")
func (s *ClientIntegrationSuite) SetupSuite() {
s.setupSuite()

var err error
s.wfService, err = s.buildServiceClient()
Expand All @@ -92,11 +106,11 @@ func (s *clientIntegrationSuite) SetupSuite() {
}
}

func (s *clientIntegrationSuite) TearDownSuite() {
func (s *ClientIntegrationSuite) TearDownSuite() {
s.tearDownSuite()
}

func (s *clientIntegrationSuite) buildServiceClient() (workflowserviceclient.Interface, error) {
func (s *ClientIntegrationSuite) buildServiceClient() (workflowserviceclient.Interface, error) {
cadenceClientName := "cadence-client"
cadenceFrontendService := common.FrontendServiceName
hostPort := "127.0.0.1:7104"
Expand Down Expand Up @@ -125,7 +139,7 @@ func (s *clientIntegrationSuite) buildServiceClient() (workflowserviceclient.Int
return workflowserviceclient.New(dispatcher.ClientConfig(cadenceFrontendService)), nil
}

func (s *clientIntegrationSuite) SetupTest() {
func (s *ClientIntegrationSuite) SetupTest() {
// Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
s.Assertions = require.New(s.T())
}
Expand Down Expand Up @@ -194,7 +208,7 @@ func testDataConverterWorkflow(ctx workflow.Context, tl string) (string, error)
return result + "," + result1, nil
}

func (s *clientIntegrationSuite) startWorkerWithDataConverter(tl string, dataConverter encoded.DataConverter) cworker.Worker {
func (s *ClientIntegrationSuite) startWorkerWithDataConverter(tl string, dataConverter encoded.DataConverter) cworker.Worker {
opts := cworker.Options{}
if dataConverter != nil {
opts.DataConverter = dataConverter
Expand All @@ -206,7 +220,7 @@ func (s *clientIntegrationSuite) startWorkerWithDataConverter(tl string, dataCon
return worker
}

func (s *clientIntegrationSuite) TestClientDataConverter() {
func (s *ClientIntegrationSuite) TestClientDataConverter() {
tl := "client-integration-data-converter-activity-tasklist"
dc := newTestDataConverter()
worker := s.startWorkerWithDataConverter(tl, dc)
Expand Down Expand Up @@ -238,7 +252,7 @@ func (s *clientIntegrationSuite) TestClientDataConverter() {
s.Equal(1, d.NumOfCallFromData)
}

func (s *clientIntegrationSuite) TestClientDataConverter_Failed() {
func (s *ClientIntegrationSuite) TestClientDataConverter_Failed() {
tl := "client-integration-data-converter-activity-failed-tasklist"
worker := s.startWorkerWithDataConverter(tl, nil) // mismatch of data converter
defer worker.Stop()
Expand Down Expand Up @@ -341,7 +355,7 @@ func testChildWorkflow(ctx workflow.Context, totalCount, runCount int) (string,
return "", workflow.NewContinueAsNewError(ctx, testChildWorkflow, totalCount, runCount)
}

func (s *clientIntegrationSuite) TestClientDataConverter_WithChild() {
func (s *ClientIntegrationSuite) TestClientDataConverter_WithChild() {
dc := newTestDataConverter()
worker := s.startWorkerWithDataConverter(childTaskList, dc)
defer worker.Stop()
Expand Down
Loading

0 comments on commit dfc42d3

Please sign in to comment.