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

Re-initializing swift-metrics in tests #60

Open
cpriebe opened this issue Feb 10, 2020 · 0 comments
Open

Re-initializing swift-metrics in tests #60

cpriebe opened this issue Feb 10, 2020 · 0 comments
Labels
kind/enhancement Improvements to existing feature.

Comments

@cpriebe
Copy link
Contributor

cpriebe commented Feb 10, 2020

Expected behavior

Right now, there is no way to re-initialize the global swift-metrics configuration. MetricsSystems.bootstrap fails if called for a second time. I understand that this is deliberate.

However, this can be a problem when writing tests for an application that uses swift-metrics. Consider three types of tests: (i) Tests that don't care about the metrics backend and run fine with the no-op metrics handler; (ii) tests that make sure that certain metrics are submitted to the metrics backend for which it would be helpful to register a custom test backend; and (iii) (integration) tests which test that the application sets up the application backend properly or that rely on the correct backend.

swift-metrics itself relies on the MetricsSystem.bootstrapInternal function for its own tests to re-initialize the metrics system but as the name suggest that is declared as internal.

The current workaround is to use bootstrapInternal via @testable import CoreMetrics. Is this the intended way of testing code with swift-metrics dependencies? Is there/Could there be a better alternative?

Note that in case (iii), there currently doesn't seem to be a way at all to have multiple tests that call the application code that ends up calling MetricsSystem.bootstrap, e.g. when the backend configuration depends on application arguments. Should these type of tests be treated as integration tests that should run in their own process?

Actual behavior

Tests that require to re-initialize the metrics system can only do so by relying on the internal MetricsSystem.bootstrapInternal function. Multiple tests that call application code relying on MetricsSystem.bootstrap must run in separate processes.

@tomerd tomerd added discussion kind/enhancement Improvements to existing feature. labels Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

3 participants