Skip to content

Commit

Permalink
Make test now passes locally (uber#4915)
Browse files Browse the repository at this point in the history
Add test flags (controlled by environment variables) that are used to skip tests that have external
dependencies. Tests call RequiresX() functions to mark that they depend on X to run.

When tests cannot run because they require a dependency, they will be skipped and print out a message describing how to run that test (after starting your dependency.)

In order to run tests marked with a dependency, you use the following environment variables: CASSANDRA, MYSQL, MONGODB, POSTGRES. So for example, to run tests that depend on Cassandra:
CASSANDRA=1 make test
  • Loading branch information
ZackLK authored Sep 2, 2022
1 parent d8624b2 commit ae1e0a0
Show file tree
Hide file tree
Showing 28 changed files with 197 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ INTEG_TEST_XDC_ROOT=./host/xdc
INTEG_TEST_XDC_DIR=hostxdc
INTEG_TEST_NDC_ROOT=./host/ndc
INTEG_TEST_NDC_DIR=hostndc
OPT_OUT_TEST=./bench/% ./canary/%
OPT_OUT_TEST=

TEST_TIMEOUT ?= 20m
TEST_ARG ?= -race $(if $(verbose),-v) -timeout $(TEST_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion canary/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *workflowTestSuite) TestSanityWorkflow() {

func (s *workflowTestSuite) TestLocalActivityWorkflow() {
s.env.OnActivity(getConditionData).Return(int32(20), nil).Once()
s.env.ExecuteWorkflow(localActivityWorkfow)
s.env.ExecuteWorkflow(localActivityWorkfow, time.Now().UnixNano())
s.True(s.env.IsWorkflowCompleted())
s.NoError(s.env.GetWorkflowError())

Expand Down
3 changes: 3 additions & 0 deletions cmd/server/cadence/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"testing"
"time"

"github.com/uber/cadence/testflags"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

Expand All @@ -46,6 +48,7 @@ type ServerSuite struct {
}

func TestServerSuite(t *testing.T) {
testflags.RequireCassandra(t)
suite.Run(t, new(ServerSuite))
}

Expand Down
2 changes: 2 additions & 0 deletions common/domain/handler_MasterCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/testflags"
)

type (
Expand All @@ -64,6 +65,7 @@ type (
)

func TestDomainHandlerGlobalDomainEnabledPrimaryClusterSuite(t *testing.T) {
testflags.RequireCassandra(t)
s := new(domainHandlerGlobalDomainEnabledPrimaryClusterSuite)
suite.Run(t, s)
}
Expand Down
2 changes: 2 additions & 0 deletions common/domain/handler_NotMasterCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/testflags"
)

type (
Expand All @@ -64,6 +65,7 @@ type (
)

func TestDomainHandlerGlobalDomainEnabledNotPrimaryClusterSuite(t *testing.T) {
testflags.RequireCassandra(t)
s := new(domainHandlerGlobalDomainEnabledNotPrimaryClusterSuite)
suite.Run(t, s)
}
Expand Down
2 changes: 2 additions & 0 deletions common/domain/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/testflags"
)

type (
Expand All @@ -67,6 +68,7 @@ type (
var nowInt64 = time.Now().UnixNano()

func TestDomainHandlerCommonSuite(t *testing.T) {
testflags.RequireCassandra(t)
s := new(domainHandlerCommonSuite)
suite.Run(t, s)
}
Expand Down
2 changes: 2 additions & 0 deletions common/domain/replicationTaskExecutor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/testflags"
)

type (
Expand All @@ -46,6 +47,7 @@ type (
)

func TestDomainReplicationTaskExecutorSuite(t *testing.T) {
testflags.RequireCassandra(t)
s := new(domainReplicationTaskExecutorSuite)
suite.Run(t, s)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,75 @@ import (

"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/testflags"
)

func TestCassandraHistoryPersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.HistoryV2PersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraMatchingPersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.MatchingPersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraDomainPersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.MetadataPersistenceSuiteV2)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraShardPersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.ShardPersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraVisibilityPersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.DBVisibilityPersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraExecutionManager(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.ExecutionManagerSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestCassandraExecutionManagerWithEventsV2(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.ExecutionManagerSuiteForEventsV2)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestQueuePersistence(t *testing.T) {
func TestCassandraQueuePersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.QueuePersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
suite.Run(t, s)
}

func TestConfigStorePersistence(t *testing.T) {
func TestCassandraConfigStorePersistence(t *testing.T) {
testflags.RequireCassandra(t)
s := new(persistencetests.ConfigStorePersistenceSuite)
s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{})
s.TestBase.Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ package tests
import (
"testing"

"github.com/uber/cadence/testflags"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

Expand All @@ -41,6 +43,7 @@ type (
var _ test.DB = (*cassandra.CqlClient)(nil)

func TestCQLClientTestSuite(t *testing.T) {
testflags.RequireCassandra(t)
suite.Run(t, new(CQLClientTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"os"
"testing"

"github.com/uber/cadence/testflags"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"

Expand All @@ -40,6 +42,7 @@ type (
)

func TestSetupSchemaTestSuite(t *testing.T) {
testflags.RequireCassandra(t)
suite.Run(t, new(SetupSchemaTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/suite"

"github.com/uber/cadence/schema/cassandra"
"github.com/uber/cadence/testflags"
cassandra2 "github.com/uber/cadence/tools/cassandra"
"github.com/uber/cadence/tools/common/schema/test"
)
Expand All @@ -37,6 +38,7 @@ type UpdateSchemaTestSuite struct {
}

func TestUpdateSchemaTestSuite(t *testing.T) {
testflags.RequireCassandra(t)
suite.Run(t, new(UpdateSchemaTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"testing"
"time"

"github.com/uber/cadence/testflags"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -48,6 +50,7 @@ type (
)

func TestVersionTestSuite(t *testing.T) {
testflags.RequireCassandra(t)
suite.Run(t, new(VersionTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// This is to make sure adding new noop method when adding new nosql interfaces
// Remove it when any other tests are implemented.
func TestNoopStruct(t *testing.T) {
func TestDynamoDBNoopStruct(t *testing.T) {
_, _ = dynamodb.NewDynamoDB(config.NoSQL{}, nil)
}

Expand All @@ -54,7 +54,7 @@ func TestDynamoDBDomainPersistence(t *testing.T) {
//suite.Run(t, s)
}

func TestQueuePersistence(t *testing.T) {
func TestDynamoDBQueuePersistence(t *testing.T) {
//s := new(persistencetests.QueuePersistenceSuite)
//s.TestBase = public.NewTestBaseWithDynamoDB(&persistencetests.TestBaseOptions{})
//s.TestBase.Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import (
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/mongodb"
persistencetests "github.com/uber/cadence/common/persistence/persistence-tests"
"github.com/uber/cadence/environment"
"github.com/uber/cadence/testflags"
)

func TestConfigStorePersistence(t *testing.T) {
func TestMongoDBConfigStorePersistence(t *testing.T) {
testflags.RequireMongoDB(t)
s := new(persistencetests.ConfigStorePersistenceSuite)
s.TestBase = NewTestBaseWithMongo()
s.TestBase.Setup()
Expand Down Expand Up @@ -63,39 +65,39 @@ func TestConfigStorePersistence(t *testing.T) {
// }

// TODO uncomment the test once MessageQueueCRUD is implemented
// func TestQueuePersistence(t *testing.T) {
// func TestMongoDBQueuePersistence(t *testing.T) {
// s := new(persistencetests.QueuePersistenceSuite)
// s.TestBase = NewTestBaseWithMongo()
// s.TestBase.Setup()
// suite.Run(t, s)
// }

// TODO uncomment the test once ShardCRUD is implemented
// func TestCassandraShardPersistence(t *testing.T) {
// func TestMongoDBShardPersistence(t *testing.T) {
// s := new(persistencetests.ShardPersistenceSuite)
// s.TestBase = NewTestBaseWithMongo()
// s.TestBase.Setup()
// suite.Run(t, s)
// }

// TODO uncomment the test once VisibilityCRUD is implemented
// func TestCassandraVisibilityPersistence(t *testing.T) {
// func TestMongoDBVisibilityPersistence(t *testing.T) {
// s := new(persistencetests.DBVisibilityPersistenceSuite)
// s.TestBase = NewTestBaseWithMongo()
// s.TestBase.Setup()
// suite.Run(t, s)
// }

// TODO uncomment the test once WorkflowCRUD is implemented
// func TestCassandraExecutionManager(t *testing.T) {
// func TestMongoDBExecutionManager(t *testing.T) {
// s := new(persistencetests.ExecutionManagerSuite)
// s.TestBase = NewTestBaseWithMongo()
// s.TestBase.Setup()
// suite.Run(t, s)
// }

// TODO uncomment the test once WorkflowCRUD is implemented
// func TestCassandraExecutionManagerWithEventsV2(t *testing.T) {
// func TestMongoDBExecutionManagerWithEventsV2(t *testing.T) {
// s := new(persistencetests.ExecutionManagerSuiteForEventsV2)
// s.TestBase = NewTestBaseWithMongo()
// s.TestBase.Setup()
Expand Down
25 changes: 17 additions & 8 deletions common/persistence/sql/sqlplugin/mysql/mysql_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,67 @@ import (
"github.com/stretchr/testify/suite"

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

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

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

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

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

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

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

func TestSQLVisibilityPersistenceSuite(t *testing.T) {
func TestMySQLVisibilityPersistenceSuite(t *testing.T) {
testflags.RequireMySQL(t)
s := new(pt.DBVisibilityPersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
suite.Run(t, s)
}

func TestSQLQueuePersistence(t *testing.T) {
func TestMySQLQueuePersistence(t *testing.T) {
testflags.RequireMySQL(t)
s := new(pt.QueuePersistenceSuite)
s.TestBase = pt.NewTestBaseWithSQL(GetTestClusterOption())
s.TestBase.Setup()
Expand Down
Loading

0 comments on commit ae1e0a0

Please sign in to comment.