Skip to content

Commit

Permalink
Unify logging in tests (cadence-workflow#5487)
Browse files Browse the repository at this point in the history
* Unify logging in tests
  • Loading branch information
3vilhamster authored Dec 18, 2023
1 parent beb3460 commit deed4f0
Show file tree
Hide file tree
Showing 139 changed files with 577 additions and 525 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ cover_profile:
$Q echo "mode: atomic" > $(UNIT_COVER_FILE)

$Q echo Running special test cases without race detector:
$Q go test -v ./cmd/server/cadence/
$Q go test ./cmd/server/cadence/
$Q echo Running package tests:
$Q for dir in $(PKG_TEST_DIRS); do \
mkdir -p $(BUILD)/"$$dir"; \
Expand All @@ -579,7 +579,7 @@ cover_ndc_profile: bins

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

$(COVER_ROOT)/cover.out: $(UNIT_COVER_FILE) $(INTEG_COVER_FILE_CASS) $(INTEG_COVER_FILE_MYSQL) $(INTEG_COVER_FILE_POSTGRES) $(INTEG_NDC_COVER_FILE_CASS) $(INTEG_NDC_COVER_FILE_MYSQL) $(INTEG_NDC_COVER_FILE_POSTGRES)
Expand Down
8 changes: 3 additions & 5 deletions cmd/server/cadence/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ import (
"testing"
"time"

"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"

"github.com/uber/cadence/testflags"

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

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/config"
_ "github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra" // needed to load cassandra plugin
_ "github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra" // needed to load cassandra plugin
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql"
_ "github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public" // needed to load the default gocql client
"github.com/uber/cadence/common/service"
"github.com/uber/cadence/testflags"
"github.com/uber/cadence/tools/cassandra"
)

Expand Down
6 changes: 2 additions & 4 deletions common/archiver/filestore/historyArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/common/util"
)
Expand Down Expand Up @@ -89,9 +88,8 @@ func (s *historyArchiverSuite) TearDownSuite() {

func (s *historyArchiverSuite) SetupTest() {
s.Assertions = require.New(s.T())
zapLogger := zap.NewNop()
s.container = &archiver.HistoryBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(s.T()),
}
}

Expand Down
6 changes: 2 additions & 4 deletions common/archiver/filestore/visibilityArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/types"
"github.com/uber/cadence/common/util"
)
Expand Down Expand Up @@ -72,9 +71,8 @@ func (s *visibilityArchiverSuite) SetupSuite() {

func (s *visibilityArchiverSuite) SetupTest() {
s.Assertions = require.New(s.T())
zapLogger := zap.NewNop()
s.container = &archiver.VisibilityBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(s.T()),
}
s.controller = gomock.NewController(s.T())
}
Expand Down
6 changes: 2 additions & 4 deletions common/archiver/gcloud/historyArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber-go/tally"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/gcloud/connector"
"github.com/uber/cadence/common/archiver/gcloud/connector/mocks"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/types"
)
Expand All @@ -60,10 +59,9 @@ var (
)

func (h *historyArchiverSuite) SetupTest() {
zapLogger := zap.NewNop()
h.Assertions = require.New(h.T())
h.container = &archiver.HistoryBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(h.T()),
MetricsClient: metrics.NewClient(tally.NoopScope, metrics.History),
}
h.testArchivalURI, _ = archiver.NewURI("gs://my-bucket-cad/cadence_archival/development")
Expand Down
7 changes: 2 additions & 5 deletions common/archiver/gcloud/visibilityArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ import (
"time"

"github.com/golang/mock/gomock"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber-go/tally"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/gcloud/connector/mocks"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/types"
)
Expand All @@ -49,9 +47,8 @@ const (

func (s *visibilityArchiverSuite) SetupTest() {
s.Assertions = require.New(s.T())
zapLogger := zap.NewNop()
s.container = &archiver.VisibilityBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(s.T()),
MetricsClient: metrics.NewClient(tally.NoopScope, metrics.History),
}
s.expectedVisibilityRecords = []*visibilityRecord{
Expand Down
6 changes: 2 additions & 4 deletions common/archiver/s3store/historyArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber-go/tally"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/s3store/mocks"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/types"
)
Expand Down Expand Up @@ -97,9 +96,8 @@ func (s *historyArchiverSuite) TearDownSuite() {
func (s *historyArchiverSuite) SetupTest() {
scope := tally.NewTestScope("test", nil)
s.Assertions = require.New(s.T())
zapLogger := zap.NewNop()
s.container = &archiver.HistoryBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(s.T()),
MetricsClient: metrics.NewClient(scope, metrics.HistoryArchiverScope),
}
}
Expand Down
6 changes: 2 additions & 4 deletions common/archiver/s3store/visibilityArchiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber-go/tally"
"go.uber.org/zap"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/s3store/mocks"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/types"
)
Expand Down Expand Up @@ -123,9 +122,8 @@ func (s *visibilityArchiverSuite) SetupSuite() {
s.testArchivalURI, err = archiver.NewURI(testBucketURI)
s.Require().NoError(err)

zapLogger := zap.NewNop()
s.container = &archiver.VisibilityBootstrapContainer{
Logger: loggerimpl.NewLogger(zapLogger),
Logger: testlogger.New(s.T()),
MetricsClient: metrics.NewClient(scope, metrics.VisibilityArchiverScope),
}
s.setupVisibilityDirectory()
Expand Down
4 changes: 2 additions & 2 deletions common/archiver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/types"
)

Expand Down Expand Up @@ -139,6 +139,6 @@ func (s *UtilSuite) TestHistoryMutated() {
},
}
for _, tc := range testCases {
s.Equal(tc.isMutated, IsHistoryMutated(tc.request, tc.historyBatches, tc.isLast, loggerimpl.NewNopLogger()))
s.Equal(tc.isMutated, IsHistoryMutated(tc.request, tc.historyBatches, tc.isLast, testlogger.New(s.T())))
}
}
4 changes: 2 additions & 2 deletions common/authorization/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
)

type (
Expand All @@ -44,7 +44,7 @@ func TestFactorySuite(t *testing.T) {
}

func (s *factorySuite) SetupTest() {
s.logger = loggerimpl.NewLoggerForTest(s.Suite)
s.logger = testlogger.New(s.Suite.T())
}

func cfgNoop() config.Authorization {
Expand Down
7 changes: 4 additions & 3 deletions common/cache/domainCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"testing"
"time"

gomock "github.com/golang/mock/gomock"
"github.com/golang/mock/gomock"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -37,7 +37,7 @@ import (
"github.com/uber/cadence/common/clock"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/mocks"
"github.com/uber/cadence/common/persistence"
Expand Down Expand Up @@ -72,7 +72,8 @@ func (s *domainCacheSuite) TearDownSuite() {
func (s *domainCacheSuite) SetupTest() {
s.Assertions = require.New(s.T())

s.logger = loggerimpl.NewLoggerForTest(s.Suite)
s.logger = testlogger.New(s.Suite.T())

s.metadataMgr = &mocks.MetadataManager{}
metricsClient := metrics.NewClient(tally.NoopScope, metrics.History)
s.domainCache = NewDomainCache(s.metadataMgr, cluster.GetTestClusterMetadata(true), metricsClient, s.logger).(*domainCache)
Expand Down
5 changes: 3 additions & 2 deletions common/cluster/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/uber/cadence/common/config"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
)

Expand Down Expand Up @@ -94,7 +95,7 @@ func TestMetadataBehaviour(t *testing.T) {
},
useNewFailoverVersionOverride: func(domain string) bool { return false },
metrics: metrics.NewNoopMetricsClient().Scope(0),
log: loggerimpl.NewNopLogger(),
log: testlogger.New(t),
}
assert.Equal(t, td.expectedOut, m.GetNextFailoverVersion(td.failoverCluster, td.currentVersion, "a domain"), name)
})
Expand Down Expand Up @@ -132,7 +133,7 @@ func TestFailoverVersionLogicIsMonotonic(t *testing.T) {
},
useNewFailoverVersionOverride: func(domain string) bool { return someDomainMigrating == domain },
metrics: metrics.NewNoopMetricsClient().Scope(0),
log: loggerimpl.NewNopLogger(),
log: testlogger.New(t),
}

current := int64(0)
Expand Down
10 changes: 5 additions & 5 deletions common/config/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/uber-go/tally/m3"
"github.com/uber-go/tally/prometheus"

"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
)

Expand All @@ -54,7 +54,7 @@ func (s *MetricsSuite) TestStatsd() {

config := new(Metrics)
config.Statsd = statsd
scope := config.NewScope(loggerimpl.NewNopLogger(), "test")
scope := config.NewScope(testlogger.New(s.T()), "test")
s.NotNil(scope)
}

Expand All @@ -66,7 +66,7 @@ func (s *MetricsSuite) TestM3() {
}
config := new(Metrics)
config.M3 = m3
scope := config.NewScope(loggerimpl.NewNopLogger(), "test")
scope := config.NewScope(testlogger.New(s.T()), "test")
s.NotNil(scope)
}

Expand All @@ -78,12 +78,12 @@ func (s *MetricsSuite) TestPrometheus() {
}
config := new(Metrics)
config.Prometheus = prom
scope := config.NewScope(loggerimpl.NewNopLogger(), "test")
scope := config.NewScope(testlogger.New(s.T()), "test")
s.NotNil(scope)
}

func (s *MetricsSuite) TestNoop() {
config := &Metrics{}
scope := config.NewScope(loggerimpl.NewNopLogger(), "test")
scope := config.NewScope(testlogger.New(s.T()), "test")
s.Equal(tally.NoopScope.Tagged(map[string]string{metrics.CadenceServiceTagName: "test"}), scope)
}
4 changes: 2 additions & 2 deletions common/domain/dlqMessageHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/types"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func (s *dlqMessageHandlerSuite) SetupTest() {
s.mockReplicationTaskExecutor = NewMockReplicationTaskExecutor(s.controller)
s.mockReplicationQueue = NewMockReplicationQueue(s.controller)

logger := loggerimpl.NewLoggerForTest(s.Suite)
logger := testlogger.New(s.Suite.T())
s.dlqMessageHandler = NewDLQMessageHandler(
s.mockReplicationTaskExecutor,
s.mockReplicationQueue,
Expand Down
4 changes: 2 additions & 2 deletions common/domain/failover_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/uber/cadence/common/cache"
"github.com/uber/cadence/common/clock"
"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/testlogger"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/mocks"
"github.com/uber/cadence/common/persistence"
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *failoverWatcherSuite) SetupTest() {
NotificationVersion: 1,
}, nil)

logger := loggerimpl.NewNopLogger()
logger := testlogger.New(s.T())
scope := tally.NewTestScope("failover_test", nil)
metricsClient := metrics.NewClient(scope, metrics.Frontend)
s.watcher = NewFailoverWatcher(
Expand Down
7 changes: 3 additions & 4 deletions common/domain/handler_MasterCluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/config"
dc "github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/mocks"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin/cassandra/gocql/public"
Expand Down Expand Up @@ -72,7 +71,7 @@ func TestDomainHandlerGlobalDomainEnabledPrimaryClusterSuite(t *testing.T) {

s := new(domainHandlerGlobalDomainEnabledPrimaryClusterSuite)

s.TestBase = public.NewTestBaseWithPublicCassandra(&persistencetests.TestBaseOptions{
s.TestBase = public.NewTestBaseWithPublicCassandra(t, &persistencetests.TestBaseOptions{
ClusterMetadata: cluster.GetTestClusterMetadata(true),
})

Expand All @@ -86,7 +85,7 @@ func (s *domainHandlerGlobalDomainEnabledPrimaryClusterSuite) TearDownSuite() {
func (s *domainHandlerGlobalDomainEnabledPrimaryClusterSuite) SetupTest() {
s.Setup()

logger := loggerimpl.NewNopLogger()
logger := s.Logger
dcCollection := dc.NewCollection(dc.NewNopClient(), logger)
s.minRetentionDays = 1
s.maxBadBinaryCount = 10
Expand Down Expand Up @@ -880,7 +879,7 @@ func (s *domainHandlerGlobalDomainEnabledPrimaryClusterSuite) TestUpdateDomain_C
}
s.handler = NewHandler(
domainConfig,
loggerimpl.NewNopLogger(),
s.Logger,
s.domainManager,
s.ClusterMetadata,
s.mockDomainReplicator,
Expand Down
Loading

0 comments on commit deed4f0

Please sign in to comment.