You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 asinternal
.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 onMetricsSystem.bootstrap
must run in separate processes.The text was updated successfully, but these errors were encountered: