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 a test function and remove a test helper #2977

Merged
merged 4 commits into from Aug 22, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Aug 18, 2022

Summary

Best viewed by individual commit.

This PR:

  • refactors the TestRequireAccessKey test case to use a testCase struct, removing the need to cast the interface{} to a function
  • removes the prometheus.Registry arg from Server.GenerateRoutes. We call this in many tests, and it can receive the registry from a field on the server
  • remove data.InvalidateCache, which was used in tests, but we removed the caches in a previous commit, so we no longer need to invalidate them. In the future if we want to cache these references we can use the data.DB struct which is different for each test, so we shouldn't need to invalidate the cache.

Removing the need to cast the function.
We call this a lot in tests, and we can avoid passing in the registry each time by including it on
the struct.

The next commit will remove the argument from all the callers.
It now comes from a field on the method receiver.
The caches were removed in a previous commit.

httpErrorLog := log.New(logging.NewFilteredHTTPLogger(), "", 0)
metricsServer := &http.Server{
ReadHeaderTimeout: 30 * time.Second,
ReadTimeout: 60 * time.Second,
Addr: s.options.Addr.Metrics,
Handler: metrics.NewHandler(promRegistry),
Handler: metrics.NewHandler(s.metricsRegistry),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we should handle the possibility of this value being nil in the metrics functions. Feels like a likely nil pointer de-reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what scenario would we expect the metrics registry to be nil?

In production we set this to a value in server.New, so it can't ever be nil. I think for this to be nil it would have to be a programming error, which should panic.

@dnephin dnephin merged commit c88c3cf into main Aug 22, 2022
@dnephin dnephin deleted the dnephin/test-refactor-map branch August 22, 2022 18:11
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