Skip to content

Added tests to service/worker/scanner.go #6349

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

Merged

Conversation

fimanishi
Copy link
Member

@fimanishi fimanishi commented Oct 10, 2024

What changed?
Modified scanner.go to accept tests.
Added tests to scanner.go.
There was no mock for worker. Created an interface and auto generated the mocks.

Why?
Improve code coverage.

How did you test it?
Unit tests

Potential risks

Release notes

Documentation Changes

What changed?
Modified scanner.go to accept tests.
Added tests to scanner.go.

Why?
Improve code coverage.

How did you test it?
Unit tests

Potential risks

Release notes

Documentation Changes
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.57%. Comparing base (fd46d4c) to head (dce1a3f).
Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
service/worker/scanner/scanner.go 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
service/worker/scanner/scanner.go 78.99% <87.50%> (+73.86%) ⬆️

... and 40 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 fd46d4c...dce1a3f. Read the comment docs.

@@ -188,7 +193,7 @@ func (s *Scanner) startShardScanner(
config.ScannerWFTypeName,
shardscanner.NewShardScannerContext(s.context.resource, config),
)
go workercommon.StartWorkflowWithRetry(
Copy link
Member

Choose a reason for hiding this comment

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

func StartWorkflowWithRetry(...) error {
	// ...
	sdkClient := client.NewClient(

😱

well. a lot of this is unavoidable I guess. we can tackle that mess another time.

},
},
setupMocks: func() {
s.mockWorker.EXPECT().Start().Return(nil).Times(2)
Copy link
Member

@Groxx Groxx Oct 11, 2024

Choose a reason for hiding this comment

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

maybe worth a comment in code here:
it's a test-suite quirk that this is the same mockWorker started 2x. normally there would be two separate workers, each started once.

which seems fine for these tests (I don't really think it'd be worth asserting "makes two and starts both", that seems like it could be a lot of work for code that obviously does that), it's just misleading to look at.

(maybe it'd be worth trying to assert "constructor called 2x"? idk, I really think it's fine as-is, this isn't a very high-value check)

Comment on lines 281 to 284
setupMocks: func(options client.StartWorkflowOptions, workflowType string, args interface{}) {
s.mockClient.On("StartWorkflow", mock.Anything, options, workflowType).Return(nil, &shared.WorkflowExecutionAlreadyStartedError{})
},
},
Copy link
Member

@Groxx Groxx Oct 11, 2024

Choose a reason for hiding this comment

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

personally: since this is a bit of an exception (return err but expect no err), I like having an explicit

err: nil,

to show it was thought about and is nil on purpose.

(for the others above, where it's kinda obvious it shouldn't error: eh, it's one fewer line, I'd leave it out too)

Copy link
Member

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

Only very minor comments / tackle if you agree 👍

@fimanishi fimanishi merged commit 084464e into cadence-workflow:master Oct 14, 2024
20 checks passed
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.

2 participants