|
1 | 1 | from __future__ import unicode_literals
|
2 | 2 |
|
3 | 3 | from concurrent.futures import ThreadPoolExecutor
|
| 4 | +import sys |
4 | 5 | import time
|
5 | 6 |
|
6 | 7 | import pytest
|
@@ -838,6 +839,33 @@ def test_target_info_restricted_registry(self):
|
838 | 839 | m.samples = [Sample('target_info', {'foo': 'bar'}, 1)]
|
839 | 840 | self.assertEqual([m], list(registry.restricted_registry(['target_info']).collect()))
|
840 | 841 |
|
| 842 | + @unittest.skipIf(sys.version_info < (3, 3), "Test requires Python 3.3+.") |
| 843 | + def test_restricted_registry_does_not_call_extra(self): |
| 844 | + from unittest.mock import MagicMock |
| 845 | + registry = CollectorRegistry() |
| 846 | + mock_collector = MagicMock() |
| 847 | + mock_collector.describe.return_value = [Metric('foo', 'help', 'summary')] |
| 848 | + registry.register(mock_collector) |
| 849 | + Summary('s', 'help', registry=registry).observe(7) |
| 850 | + |
| 851 | + m = Metric('s', 'help', 'summary') |
| 852 | + m.samples = [Sample('s_sum', {}, 7)] |
| 853 | + self.assertEqual([m], list(registry.restricted_registry(['s_sum']).collect())) |
| 854 | + mock_collector.collect.assert_not_called() |
| 855 | + |
| 856 | + def test_restricted_registry_does_not_yield_while_locked(self): |
| 857 | + registry = CollectorRegistry(target_info={'foo': 'bar'}) |
| 858 | + Summary('s', 'help', registry=registry).observe(7) |
| 859 | + |
| 860 | + m = Metric('s', 'help', 'summary') |
| 861 | + m.samples = [Sample('s_sum', {}, 7)] |
| 862 | + self.assertEqual([m], list(registry.restricted_registry(['s_sum']).collect())) |
| 863 | + |
| 864 | + m = Metric('target', 'Target metadata', 'info') |
| 865 | + m.samples = [Sample('target_info', {'foo': 'bar'}, 1)] |
| 866 | + for _ in registry.restricted_registry(['target_info', 's_sum']).collect(): |
| 867 | + self.assertFalse(registry._lock.locked()) |
| 868 | + |
841 | 869 |
|
842 | 870 | if __name__ == '__main__':
|
843 | 871 | unittest.main()
|
0 commit comments