| 43 | void EmptyCollectionFunction(MetricCollectorGetter getter) {} |
| 44 | |
| 45 | TEST(CollectionRegistryTest, RegistrationUnregistration) { |
| 46 | auto* collection_registry = CollectionRegistry::Default(); |
| 47 | const MetricDef<MetricKind::kCumulative, int64, 0> metric_def0( |
| 48 | "/tensorflow/metric0", "An example metric with no labels."); |
| 49 | const MetricDef<MetricKind::kGauge, HistogramProto, 1> metric_def1( |
| 50 | "/tensorflow/metric1", "An example metric with one label.", "LabelName"); |
| 51 | |
| 52 | { |
| 53 | // Enclosed in a scope so that we unregister before the stack variables |
| 54 | // above are destroyed. |
| 55 | |
| 56 | std::unique_ptr<CollectionRegistry::RegistrationHandle> handle0 = |
| 57 | collection_registry->Register(&metric_def0, EmptyCollectionFunction); |
| 58 | std::unique_ptr<CollectionRegistry::RegistrationHandle> handle1 = |
| 59 | collection_registry->Register(&metric_def1, EmptyCollectionFunction); |
| 60 | |
| 61 | handle0.reset(); |
| 62 | |
| 63 | // Able to register again because it was unregistered earlier. |
| 64 | handle0 = |
| 65 | collection_registry->Register(&metric_def0, EmptyCollectionFunction); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | TEST(CollectionRegistryDeathTest, DuplicateRegistration) { |
| 70 | auto* collection_registry = CollectionRegistry::Default(); |
nothing calls this directly
no test coverage detected