Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for PinotVisibilityStore #5714

Merged
merged 18 commits into from
Mar 6, 2024

Conversation

bowenxia
Copy link
Contributor

@bowenxia bowenxia commented Mar 5, 2024

What changed?
Add unit test

Why?
increment the coverage to 85%+

How did you test it?

Potential risks

Release notes

Documentation Changes

@bowenxia bowenxia changed the title add unit tests for PinotVisibilityStore Add unit tests for PinotVisibilityStore Mar 5, 2024
@coveralls
Copy link

coveralls commented Mar 5, 2024

Pull Request Test Coverage Report for Build 018e152d-ca0e-4ec0-8d30-3c3b356a75a7

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 48 unchanged lines in 12 files lost coverage.
  • Overall coverage increased (+0.3%) to 63.751%

Files with Coverage Reduction New Missed Lines %
common/util.go 2 91.69%
service/history/task/transfer_active_task_executor.go 2 72.51%
service/history/task/transfer_standby_task_executor.go 2 87.42%
service/matching/db.go 2 73.23%
service/matching/taskListManager.go 2 80.2%
common/log/tag/tags.go 3 50.18%
common/persistence/nosql/nosqlplugin/cassandra/tasks.go 4 76.09%
service/history/task/fetcher.go 4 86.08%
common/persistence/nosql/nosql_task_store.go 5 61.95%
common/task/fifo_task_scheduler.go 5 82.47%
Totals Coverage Status
Change from base Build 018e1500-6a49-463a-9ea8-9d50743955ec: 0.3%
Covered Lines: 93459
Relevant Lines: 146599

💛 - Coveralls

// SOFTWARE.

// Code generated by MockGen. DO NOT EDIT.
// Source: interfaces.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you generate this? I don't see common/pinot/interfaces.go in the diff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/uber/cadence/blob/master/common/pinot/interfaces.go
I implemented it previously. Since ESVisibilityStore were using a generic es client, I used the same pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant interface.go doesn't have any change in the PR. We usually generate mocks by adding go:generate lines to the interface file. example: https://github.com/uber/cadence/blob/68706a6219d11a2113d9bc1d257997c85da0f433/client/admin/interface.go#L31

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of a go version issue. The previous branch was massed up, so I just copied and pasted the GenericClient_mock.go. I've added the comment back.

common/persistence/pinot/pinotVisibilityStore_test.go Outdated Show resolved Hide resolved
Comment on lines 67 to 79
mockPinotClient := pnt.NewMockGenericClient(ctrl)
mockProducer := &mocks.KafkaProducer{}
mgr := NewPinotVisibilityStore(mockPinotClient, &service.Config{
ValidSearchAttributes: dynamicconfig.GetMapPropertyFn(definition.GetDefaultIndexedKeys()),
ESIndexMaxResultWindow: dynamicconfig.GetIntPropertyFn(3),
}, mockProducer, testlogger.New(t))
visibilityStore := mgr.(*pinotVisibilityStore)

// test non-empty request fields match
request := &p.InternalRecordWorkflowExecutionStartedRequest{}
request.WorkflowID = "wid"
memoBytes := []byte(`test bytes`)
request.Memo = p.NewDataBlob(memoBytes, common.EncodingTypeThriftRW)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create all the mocks inside the test body (line 97) so they are isolated for each test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the mocks into test body, but left request here because this is the input of the test.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Merging #5714 (b19f3b0) into master (25044cf) will increase coverage by 0.32%.
The diff coverage is 100.00%.

Additional details and impacted files
Files Coverage Δ
...rsistence/pinot/pinot_visibility_metric_clients.go 0.00% <ø> (ø)
common/persistence/pinot/pinot_visibility_store.go 86.12% <100.00%> (ø)

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25044cf...b19f3b0. Read the comment docs.

)

func TestRecordWorkflowExecutionStarted(t *testing.T) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

expectedResp *p.InternalListWorkflowExecutionsResponse
expectedError error
}{
"Case1: normal case with nil response": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cover the error cases as well. maybe in follow up PR you can add more cases to the tests in this file.

@bowenxia bowenxia merged commit 9f4a87d into master Mar 6, 2024
21 checks passed
@bowenxia bowenxia deleted the xbowen_PinotVisibilityStore_test branch March 6, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants