From d3c64e09fcab529c3c825ac971c3311eaefa6470 Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 11 Mar 2024 16:04:13 -0700 Subject: [PATCH 1/2] refactor common/persistence/pinot tests --- .../pinot_visibility_metric_clients_test.go | 790 ++++++++++-------- .../pinot/pinot_visibility_store_test.go | 43 +- 2 files changed, 478 insertions(+), 355 deletions(-) diff --git a/common/persistence/pinot/pinot_visibility_metric_clients_test.go b/common/persistence/pinot/pinot_visibility_metric_clients_test.go index 81cd078d504..985873c7945 100644 --- a/common/persistence/pinot/pinot_visibility_metric_clients_test.go +++ b/common/persistence/pinot/pinot_visibility_metric_clients_test.go @@ -25,6 +25,7 @@ package pinotvisibility import ( "context" "fmt" + "github.com/uber/cadence/common/log" "testing" "github.com/golang/mock/gomock" @@ -69,15 +70,33 @@ func TestMetricClientRecordWorkflowExecutionStarted(t *testing.T) { } tests := map[string]struct { - request *p.RecordWorkflowExecutionStartedRequest - expectedError error + request *p.RecordWorkflowExecutionStartedRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(&types.BadRequestError{}).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: &types.BadRequestError{}, }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -92,7 +111,7 @@ func TestMetricClientRecordWorkflowExecutionStarted(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -105,22 +124,11 @@ func TestMetricClientRecordWorkflowExecutionStarted(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(&types.BadRequestError{}).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.RecordWorkflowExecutionStarted(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.RecordWorkflowExecutionStarted(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.RecordWorkflowExecutionStarted(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -146,15 +154,33 @@ func TestMetricClientRecordWorkflowExecutionClosed(t *testing.T) { } tests := map[string]struct { - request *p.RecordWorkflowExecutionClosedRequest - expectedError error + request *p.RecordWorkflowExecutionClosedRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(&types.ServiceBusyError{}).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: &types.ServiceBusyError{}, }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -169,7 +195,7 @@ func TestMetricClientRecordWorkflowExecutionClosed(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -182,22 +208,11 @@ func TestMetricClientRecordWorkflowExecutionClosed(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(&types.ServiceBusyError{}).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.RecordWorkflowExecutionClosed(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.RecordWorkflowExecutionClosed(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.RecordWorkflowExecutionClosed(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -213,15 +228,33 @@ func TestMetricClientRecordWorkflowExecutionUninitialized(t *testing.T) { } tests := map[string]struct { - request *p.RecordWorkflowExecutionUninitializedRequest - expectedError error + request *p.RecordWorkflowExecutionUninitializedRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(fmt.Errorf("error")).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -236,7 +269,7 @@ func TestMetricClientRecordWorkflowExecutionUninitialized(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -249,22 +282,11 @@ func TestMetricClientRecordWorkflowExecutionUninitialized(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(fmt.Errorf("error")).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.RecordWorkflowExecutionUninitialized(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.RecordWorkflowExecutionUninitialized(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.RecordWorkflowExecutionUninitialized(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -280,15 +302,33 @@ func TestMetricClientUpsertWorkflowExecution(t *testing.T) { } tests := map[string]struct { - request *p.UpsertWorkflowExecutionRequest - expectedError error + request *p.UpsertWorkflowExecutionRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(fmt.Errorf("error")).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -303,7 +343,7 @@ func TestMetricClientUpsertWorkflowExecution(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -316,22 +356,11 @@ func TestMetricClientUpsertWorkflowExecution(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(fmt.Errorf("error")).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.UpsertWorkflowExecution(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.UpsertWorkflowExecution(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.UpsertWorkflowExecution(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -339,8 +368,7 @@ func TestMetricClientUpsertWorkflowExecution(t *testing.T) { func TestMetricClientListOpenWorkflowExecutions(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", } request := &p.ListWorkflowExecutionsRequest{ @@ -348,15 +376,31 @@ func TestMetricClientListOpenWorkflowExecutions(t *testing.T) { } tests := map[string]struct { - request *p.ListWorkflowExecutionsRequest - expectedError error + request *p.ListWorkflowExecutionsRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -371,7 +415,7 @@ func TestMetricClientListOpenWorkflowExecutions(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -384,19 +428,11 @@ func TestMetricClientListOpenWorkflowExecutions(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListOpenWorkflowExecutions(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListOpenWorkflowExecutions(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListOpenWorkflowExecutions(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -404,8 +440,7 @@ func TestMetricClientListOpenWorkflowExecutions(t *testing.T) { func TestMetricClientListClosedWorkflowExecutions(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainId", } request := &p.ListWorkflowExecutionsRequest{ @@ -413,15 +448,31 @@ func TestMetricClientListClosedWorkflowExecutions(t *testing.T) { } tests := map[string]struct { - request *p.ListWorkflowExecutionsRequest - expectedError error + request *p.ListWorkflowExecutionsRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -436,7 +487,7 @@ func TestMetricClientListClosedWorkflowExecutions(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -449,19 +500,11 @@ func TestMetricClientListClosedWorkflowExecutions(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListClosedWorkflowExecutions(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListClosedWorkflowExecutions(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListClosedWorkflowExecutions(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -470,8 +513,7 @@ func TestMetricClientListOpenWorkflowExecutionsByType(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsByTypeRequest{ ListWorkflowExecutionsRequest: p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", }, WorkflowTypeName: "", } @@ -479,15 +521,31 @@ func TestMetricClientListOpenWorkflowExecutionsByType(t *testing.T) { request := &p.ListWorkflowExecutionsByTypeRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByTypeRequest - expectedError error + request *p.ListWorkflowExecutionsByTypeRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -502,7 +560,7 @@ func TestMetricClientListOpenWorkflowExecutionsByType(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -515,19 +573,11 @@ func TestMetricClientListOpenWorkflowExecutionsByType(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListOpenWorkflowExecutionsByType(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListOpenWorkflowExecutionsByType(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListOpenWorkflowExecutionsByType(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -536,8 +586,7 @@ func TestMetricClientListClosedWorkflowExecutionsByType(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsByTypeRequest{ ListWorkflowExecutionsRequest: p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", }, WorkflowTypeName: "", } @@ -545,15 +594,31 @@ func TestMetricClientListClosedWorkflowExecutionsByType(t *testing.T) { request := &p.ListWorkflowExecutionsByTypeRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByTypeRequest - expectedError error + request *p.ListWorkflowExecutionsByTypeRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -568,7 +633,7 @@ func TestMetricClientListClosedWorkflowExecutionsByType(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -581,19 +646,11 @@ func TestMetricClientListClosedWorkflowExecutionsByType(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListClosedWorkflowExecutionsByType(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListClosedWorkflowExecutionsByType(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListClosedWorkflowExecutionsByType(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -602,23 +659,38 @@ func TestMetricClientListOpenWorkflowExecutionsByWorkflowID(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsByWorkflowIDRequest{ ListWorkflowExecutionsRequest: p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", }, } request := &p.ListWorkflowExecutionsByWorkflowIDRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByWorkflowIDRequest - expectedError error + request *p.ListWorkflowExecutionsByWorkflowIDRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -633,7 +705,7 @@ func TestMetricClientListOpenWorkflowExecutionsByWorkflowID(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -646,19 +718,11 @@ func TestMetricClientListOpenWorkflowExecutionsByWorkflowID(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListOpenWorkflowExecutionsByWorkflowID(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListOpenWorkflowExecutionsByWorkflowID(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListOpenWorkflowExecutionsByWorkflowID(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -667,23 +731,38 @@ func TestMetricClientListClosedWorkflowExecutionsByWorkflowID(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListWorkflowExecutionsByWorkflowIDRequest{ ListWorkflowExecutionsRequest: p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", }, } request := &p.ListWorkflowExecutionsByWorkflowIDRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByWorkflowIDRequest - expectedError error + request *p.ListWorkflowExecutionsByWorkflowIDRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -698,7 +777,7 @@ func TestMetricClientListClosedWorkflowExecutionsByWorkflowID(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -711,17 +790,13 @@ func TestMetricClientListClosedWorkflowExecutionsByWorkflowID(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) + _, err := metricsClient.ListClosedWorkflowExecutionsByWorkflowID(context.Background(), test.request) if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListClosedWorkflowExecutionsByWorkflowID(context.Background(), test.request) - assert.Error(t, err) + assert.Equal(t, test.expectedError.Error(), err.Error()) } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListClosedWorkflowExecutionsByWorkflowID(context.Background(), test.request) assert.NoError(t, err) } }) @@ -732,23 +807,38 @@ func TestMetricClientListClosedWorkflowExecutionsByStatus(t *testing.T) { // test non-empty request fields match errorRequest := &p.ListClosedWorkflowExecutionsByStatusRequest{ ListWorkflowExecutionsRequest: p.ListWorkflowExecutionsRequest{ - Domain: DomainID, - NextPageToken: []byte("error"), + Domain: "badDomainID", }, } request := &p.ListClosedWorkflowExecutionsByStatusRequest{} tests := map[string]struct { - request *p.ListClosedWorkflowExecutionsByStatusRequest - expectedError error + request *p.ListClosedWorkflowExecutionsByStatusRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -763,7 +853,7 @@ func TestMetricClientListClosedWorkflowExecutionsByStatus(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -776,19 +866,11 @@ func TestMetricClientListClosedWorkflowExecutionsByStatus(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListClosedWorkflowExecutionsByStatus(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListClosedWorkflowExecutionsByStatus(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListClosedWorkflowExecutionsByStatus(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -800,15 +882,37 @@ func TestMetricClientGetClosedWorkflowExecution(t *testing.T) { request := &p.GetClosedWorkflowExecutionRequest{} tests := map[string]struct { - request *p.GetClosedWorkflowExecutionRequest - expectedError error + request *p.GetClosedWorkflowExecutionRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, - expectedError: fmt.Errorf("error"), + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, + expectedError: fmt.Errorf("Pinot GetClosedWorkflowExecution failed, error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(&pnt.SearchResponse{ + Executions: []*p.InternalVisibilityWorkflowExecutionInfo{ + { + DomainID: DomainID, + }, + }, + }, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -823,7 +927,7 @@ func TestMetricClientGetClosedWorkflowExecution(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -836,30 +940,13 @@ func TestMetricClientGetClosedWorkflowExecution(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) + _, err := metricsClient.GetClosedWorkflowExecution(context.Background(), test.request) if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(&pnt.SearchResponse{ - Executions: []*p.InternalVisibilityWorkflowExecutionInfo{ - { - DomainID: DomainID, - }, - }, - }, fmt.Errorf("error")).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.GetClosedWorkflowExecution(context.Background(), test.request) - assert.Error(t, err) + assert.Equal(t, test.expectedError.Error(), err.Error()) } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(&pnt.SearchResponse{ - Executions: []*p.InternalVisibilityWorkflowExecutionInfo{ - { - DomainID: DomainID, - }, - }, - }, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.GetClosedWorkflowExecution(context.Background(), test.request) assert.NoError(t, err) } }) @@ -867,21 +954,35 @@ func TestMetricClientGetClosedWorkflowExecution(t *testing.T) { } func TestMetricClientListWorkflowExecutions(t *testing.T) { - errorRequest := &p.ListWorkflowExecutionsByQueryRequest{ - NextPageToken: []byte("error"), - } + errorRequest := &p.ListWorkflowExecutionsByQueryRequest{} request := &p.ListWorkflowExecutionsByQueryRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByQueryRequest - expectedError error + request *p.ListWorkflowExecutionsByQueryRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -896,7 +997,7 @@ func TestMetricClientListWorkflowExecutions(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -909,39 +1010,45 @@ func TestMetricClientListWorkflowExecutions(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ListWorkflowExecutions(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ListWorkflowExecutions(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ListWorkflowExecutions(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } func TestMetricClientScanWorkflowExecutions(t *testing.T) { - errorRequest := &p.ListWorkflowExecutionsByQueryRequest{ - NextPageToken: []byte("error"), - } + errorRequest := &p.ListWorkflowExecutionsByQueryRequest{} request := &p.ListWorkflowExecutionsByQueryRequest{} tests := map[string]struct { - request *p.ListWorkflowExecutionsByQueryRequest - expectedError error + request *p.ListWorkflowExecutionsByQueryRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -956,7 +1063,7 @@ func TestMetricClientScanWorkflowExecutions(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -969,19 +1076,11 @@ func TestMetricClientScanWorkflowExecutions(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.ScanWorkflowExecutions(context.Background(), test.request) - assert.Error(t, err) - } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().Search(gomock.Any()).Return(nil, nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.ScanWorkflowExecutions(context.Background(), test.request) - assert.NoError(t, err) - } + _, err := metricsClient.ScanWorkflowExecutions(context.Background(), test.request) + assert.Equal(t, test.expectedError, err) }) } } @@ -991,15 +1090,31 @@ func TestMetricClientCountWorkflowExecutions(t *testing.T) { request := &p.CountWorkflowExecutionsRequest{} tests := map[string]struct { - request *p.CountWorkflowExecutionsRequest - expectedError error + request *p.CountWorkflowExecutionsRequest + pinotClientMockAffordance func(mockPinotClient *pnt.MockGenericClient) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, - expectedError: fmt.Errorf("error"), + request: errorRequest, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().CountByQuery(gomock.Any()).Return(int64(0), fmt.Errorf("error")).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, + expectedError: fmt.Errorf("CountClosedWorkflowExecutions failed, error"), }, "Case2: normal case": { - request: request, + request: request, + pinotClientMockAffordance: func(mockPinotClient *pnt.MockGenericClient) { + mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) + mockPinotClient.EXPECT().CountByQuery(gomock.Any()).Return(int64(1), nil).Times(1) + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -1014,7 +1129,7 @@ func TestMetricClientCountWorkflowExecutions(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -1027,18 +1142,13 @@ func TestMetricClientCountWorkflowExecutions(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.pinotClientMockAffordance(mockPinotClient) + test.scopeMockAffordance(mockScope) + _, err := metricsClient.CountWorkflowExecutions(context.Background(), test.request) if test.expectedError != nil { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().CountByQuery(gomock.Any()).Return(int64(0), fmt.Errorf("error")).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - _, err := metricsClient.CountWorkflowExecutions(context.Background(), test.request) - assert.Error(t, err) + assert.Equal(t, test.expectedError.Error(), err.Error()) } else { - mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) - mockPinotClient.EXPECT().CountByQuery(gomock.Any()).Return(int64(1), nil).Times(1) - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - _, err := metricsClient.CountWorkflowExecutions(context.Background(), test.request) assert.NoError(t, err) } }) @@ -1052,15 +1162,33 @@ func TestMetricClientDeleteWorkflowExecution(t *testing.T) { request := &p.VisibilityDeleteWorkflowExecutionRequest{} tests := map[string]struct { - request *p.VisibilityDeleteWorkflowExecutionRequest - expectedError error + request *p.VisibilityDeleteWorkflowExecutionRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(fmt.Errorf("error")).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -1075,7 +1203,7 @@ func TestMetricClientDeleteWorkflowExecution(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -1088,22 +1216,11 @@ func TestMetricClientDeleteWorkflowExecution(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(fmt.Errorf("error")).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.DeleteWorkflowExecution(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.DeleteWorkflowExecution(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.DeleteWorkflowExecution(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -1115,15 +1232,33 @@ func TestMetricClientDeleteUninitializedWorkflowExecution(t *testing.T) { request := &p.VisibilityDeleteWorkflowExecutionRequest{} tests := map[string]struct { - request *p.VisibilityDeleteWorkflowExecutionRequest - expectedError error + request *p.VisibilityDeleteWorkflowExecutionRequest + producerMockAffordance func(mockProducer *mocks.KafkaProducer) + scopeMockAffordance func(mockScope *metricsClientMocks.Scope) + expectedError error }{ "Case1: error case": { - request: errorRequest, + request: errorRequest, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(fmt.Errorf("error")).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) + }, expectedError: fmt.Errorf("error"), }, "Case2: normal case": { - request: request, + request: request, + producerMockAffordance: func(mockProducer *mocks.KafkaProducer) { + mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { + return true + })).Return(nil).Once() + }, + scopeMockAffordance: func(mockScope *metricsClientMocks.Scope) { + mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() + }, expectedError: nil, }, } @@ -1138,7 +1273,7 @@ func TestMetricClientDeleteUninitializedWorkflowExecution(t *testing.T) { mockScope := &metricsClientMocks.Scope{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -1151,22 +1286,11 @@ func TestMetricClientDeleteUninitializedWorkflowExecution(t *testing.T) { // mock behaviors mockMetricClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope).Once() mockScope.On("StartTimer", mock.Anything, mock.Anything).Return(testStopwatch).Once() + test.producerMockAffordance(mockProducer) + test.scopeMockAffordance(mockScope) - if test.expectedError != nil { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(fmt.Errorf("error")).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Times(3) - err := metricsClient.DeleteUninitializedWorkflowExecution(context.Background(), test.request) - assert.Equal(t, err, test.expectedError) - } else { - mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { - return true - })).Return(nil).Once() - mockScope.On("IncCounter", mock.Anything, mock.Anything, mock.Anything).Return().Once() - err := metricsClient.DeleteUninitializedWorkflowExecution(context.Background(), test.request) - assert.NoError(t, err) - } + err := metricsClient.DeleteUninitializedWorkflowExecution(context.Background(), test.request) + assert.Equal(t, err, test.expectedError) }) } } @@ -1179,7 +1303,7 @@ func TestMetricClientClose(t *testing.T) { mockMetricClient := &metricsClientMocks.Client{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), @@ -1203,7 +1327,7 @@ func TestMetricClientGetName(t *testing.T) { mockMetricClient := &metricsClientMocks.Client{} // create metricClient - logger := testlogger.New(t) + logger := log.NewNoop() mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), diff --git a/common/persistence/pinot/pinot_visibility_store_test.go b/common/persistence/pinot/pinot_visibility_store_test.go index 147acc0feb7..3aced82094f 100644 --- a/common/persistence/pinot/pinot_visibility_store_test.go +++ b/common/persistence/pinot/pinot_visibility_store_test.go @@ -38,7 +38,6 @@ import ( "github.com/uber/cadence/common/definition" "github.com/uber/cadence/common/dynamicconfig" "github.com/uber/cadence/common/log" - "github.com/uber/cadence/common/log/testlogger" "github.com/uber/cadence/common/mocks" p "github.com/uber/cadence/common/persistence" pnt "github.com/uber/cadence/common/pinot" @@ -115,7 +114,7 @@ func TestRecordWorkflowExecutionStarted(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { @@ -170,7 +169,7 @@ func TestRecordWorkflowExecutionClosed(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { @@ -212,7 +211,7 @@ func TestRecordWorkflowExecutionUninitialized(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { @@ -263,7 +262,7 @@ func TestUpsertWorkflowExecution(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { @@ -304,7 +303,7 @@ func TestDeleteWorkflowExecution(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockProducer.On("Publish", mock.Anything, mock.MatchedBy(func(input *indexer.PinotMessage) bool { @@ -346,7 +345,7 @@ func TestDeleteUninitializedWorkflowExecution(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) mockPinotClient.EXPECT().GetTableName().Return(testTableName).Times(1) @@ -398,7 +397,7 @@ func TestListOpenWorkflowExecutions(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -452,7 +451,7 @@ func TestListClosedWorkflowExecutions(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -507,7 +506,7 @@ func TestListOpenWorkflowExecutionsByType(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -561,7 +560,7 @@ func TestListClosedWorkflowExecutionsByType(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -614,7 +613,7 @@ func TestListOpenWorkflowExecutionsByWorkflowID(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -667,7 +666,7 @@ func TestListClosedWorkflowExecutionsByWorkflowID(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -720,7 +719,7 @@ func TestListClosedWorkflowExecutionsByStatus(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -767,7 +766,7 @@ func TestGetClosedWorkflowExecution(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -828,7 +827,7 @@ func TestListWorkflowExecutions(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -878,7 +877,7 @@ func TestScanWorkflowExecutions(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -926,7 +925,7 @@ func TestCountWorkflowExecutions(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) if test.expectedError != nil { @@ -953,7 +952,7 @@ func TestGetName(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) assert.NotEmpty(t, visibilityStore.GetName()) } @@ -1018,7 +1017,7 @@ AND WorkflowID = 'wfid' mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) res := visibilityStore.getCountWorkflowExecutionsQuery(testTableName, test.request) @@ -1262,7 +1261,7 @@ LIMIT 0, 0 mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) output, err := visibilityStore.getListWorkflowExecutionsByQueryQuery(testTableName, test.input) @@ -1821,7 +1820,7 @@ func TestClose(t *testing.T) { mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{ ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()), ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3), - }, mockProducer, testlogger.New(t)) + }, mockProducer, log.NewNoop()) visibilityStore := mgr.(*pinotVisibilityStore) assert.NotPanics(t, func() { From 34a163ee5452ddc162e4f5574038449f1438ff71 Mon Sep 17 00:00:00 2001 From: Bowen Xiao Date: Mon, 11 Mar 2024 16:07:36 -0700 Subject: [PATCH 2/2] clean up the fmt --- .../persistence/pinot/pinot_visibility_metric_clients_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/persistence/pinot/pinot_visibility_metric_clients_test.go b/common/persistence/pinot/pinot_visibility_metric_clients_test.go index 985873c7945..d70e8c9e545 100644 --- a/common/persistence/pinot/pinot_visibility_metric_clients_test.go +++ b/common/persistence/pinot/pinot_visibility_metric_clients_test.go @@ -25,7 +25,6 @@ package pinotvisibility import ( "context" "fmt" - "github.com/uber/cadence/common/log" "testing" "github.com/golang/mock/gomock" @@ -35,6 +34,7 @@ import ( "github.com/uber/cadence/.gen/go/indexer" "github.com/uber/cadence/common/definition" "github.com/uber/cadence/common/dynamicconfig" + "github.com/uber/cadence/common/log" "github.com/uber/cadence/common/log/testlogger" "github.com/uber/cadence/common/metrics" metricsClientMocks "github.com/uber/cadence/common/metrics/mocks"