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

Refactor QueryService tests #3060

Merged

Conversation

albertteoh
Copy link
Contributor

Signed-off-by: albertteoh albert.teoh@logz.io

Which problem is this PR solving?

Short description of the changes

  • Refactor QueryService tests for easier maintenance and reduce required changes when introducing metrics reader to query service:
    • Return a testMocks struct rather than return multiple mock objects.
    • Only use what's required, instead of multiple blank identifiers for unwanted mocks.
    • Introduce functional options on a single test bootstrapping function instead of mostly duplicated functions for specific combinations of parameters.

Signed-off-by: albertteoh <albert.teoh@logz.io>
archiveSpanWriter *spanstoremocks.Writer
}

type QueryServiceOptionApplier func(*testMocks, *QueryServiceOptions)
Copy link
Member

Choose a reason for hiding this comment

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

usually these types are named simply XyzOption

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, I'm planning to do the same thing for QueryServiceOptions in the next PR, as I think MetricsQuery reader belongs in this struct.

Can you think of a good name for the Option? QueryServiceOptionsOption seems a little too stutter-y and I'm a little short on other ideas on names. :P

@codecov
Copy link

codecov bot commented Jun 6, 2021

Codecov Report

Merging #3060 (f4dff2a) into master (013ecf2) will increase coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3060      +/-   ##
==========================================
+ Coverage   95.97%   96.03%   +0.06%     
==========================================
  Files         229      229              
  Lines        9956     9956              
==========================================
+ Hits         9555     9561       +6     
+ Misses        330      326       -4     
+ Partials       71       69       -2     
Impacted Files Coverage Δ
pkg/config/tlscfg/cert_watcher.go 92.20% <0.00%> (-2.60%) ⬇️
plugin/storage/badger/spanstore/reader.go 96.08% <0.00%> (+0.71%) ⬆️
...lugin/sampling/strategystore/adaptive/processor.go 100.00% <0.00%> (+0.92%) ⬆️
cmd/collector/app/server/zipkin.go 76.92% <0.00%> (+15.38%) ⬆️

Continue to review full report at Codecov.

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

}

func initializeTestService() (*QueryService, *spanstoremocks.Reader, *depsmocks.Reader) {
func initializeTestService(optionAppliers ...QueryServiceOptionApplier) (*QueryService, *testMocks) {
Copy link
Member

Choose a reason for hiding this comment

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

since you're already introducing a new struct testMocks, you might instead return a single testQueryService struct which contains both the *QS and the mocks at top level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

glad you mentioned this as this was also what I wanted to do initially, just thought there may have been a preference to separate the "thing under test" from the mocks.

Copy link
Member

Choose a reason for hiding this comment

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

tqsOption - these are private types, no need to be especially creative

Signed-off-by: albertteoh <albert.teoh@logz.io>
@albertteoh albertteoh marked this pull request as ready for review June 6, 2021 01:06
@albertteoh albertteoh requested a review from a team as a code owner June 6, 2021 01:06
@albertteoh albertteoh enabled auto-merge (squash) June 6, 2021 01:20
@albertteoh albertteoh merged commit 7f9924b into jaegertracing:master Jun 6, 2021
@albertteoh albertteoh deleted the 2954-refactor-querysvc-tests branch June 6, 2021 01:36
@albertteoh
Copy link
Contributor Author

Thanks Yuri!

@jpkrohling jpkrohling added this to the Release 1.24.0 milestone Jun 22, 2021
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.

None yet

3 participants