def test_resource_watcher_min_mem(self): config = {"loop_rate": 0.1, "min_mem": 100000.1} self.assertRaises(NotImplementedError, run_plugin, ResourceWatcher, config) # Test that service is deprecated config["service"] = "test" found = False with warnings.catch_warnings(record=True) as ws: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) numws = len(ws) for w in ws: if not found: found = "ResourceWatcher" in str(w.message) if not found: raise AssertionError("ResourceWatcher not found") self._check_statsd(_statsd, "_resource_watcher.test.under_memory") # Test that watcher is ok and not deprecated config["watcher"] = config["service"] del config["service"] with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) assert len(w) == numws - 1
def test_resource_watcher_min_mem(self): config = {'loop_rate': 0.1, 'min_mem': 100000.1} self.assertRaises(NotImplementedError, run_plugin, ResourceWatcher, config) # Test that service is deprecated config['service'] = 'test' found = False with warnings.catch_warnings(record=True) as ws: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) numws = len(ws) for w in ws: if not found: found = 'ResourceWatcher' in str(w.message) if not found: raise AssertionError('ResourceWatcher not found') self._check_statsd(_statsd, '_resource_watcher.test.under_memory') # Test that watcher is ok and not deprecated config['watcher'] = config['service'] del config['service'] with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) assert len(w) == numws - 1
def test_resource_watcher(self): config = {'loop_rate': 0.2, 'max_mem': 0.1} self.assertRaises(NotImplementedError, run_plugin, ResourceWatcher, config) config['service'] = 'test' _statsd = run_plugin(ResourceWatcher, config) res = _statsd.increments.items() self.assertEqual(res, [('_resource_watcher.test.over_memory', 1)])
def test_full_stats(self): config = {'loop_rate': 0.2} _statsd = run_plugin(FullStats, config, 1000) # we should have a bunch of stats events here self.assertTrue(len(_statsd.gauges) >= 5) last_batch = [name for name, value in _statsd.gauges[-5:]] last_batch.sort() wanted = ['_stats.test.cpu_max', '_stats.test.cpu_sum', '_stats.test.mem_max', '_stats.test.mem_sum', '_stats.test.watchers_num'] self.assertEqual(last_batch, wanted)
def test_full_stats(self): config = {'loop_rate': 0.2} _statsd = run_plugin(FullStats, config, 1000) # we should have a bunch of stats events here self.assertTrue(len(_statsd.gauges) >= 5) last_batch = [name for name, value in _statsd.gauges[-5:]] last_batch.sort() wanted = [ '_stats.test.cpu_max', '_stats.test.cpu_sum', '_stats.test.mem_max', '_stats.test.mem_sum', '_stats.test.watchers_num' ] self.assertEqual(last_batch, wanted)
def test_resource_watcher(self): config = {'loop_rate': 0.2, 'max_mem': 0.1} self.assertRaises(NotImplementedError, run_plugin, ResourceWatcher, config) # Test that service is deprecated config['service'] = 'test' found = False with warnings.catch_warnings(record=True) as ws: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) numws = len(ws) for w in ws: if not found: found = 'ResourceWatcher' in str(w.message) if not found: raise AssertionError('ResourceWatcher not found') res = _statsd.increments.items() self.assertEqual(len(res), 1) self.assertEqual(res[0][0], '_resource_watcher.test.over_memory') self.assertTrue(res[0][1] > 0) # Test that watcher is ok and not deprecated config['watcher'] = config['service'] del config['service'] with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") _statsd = run_plugin(ResourceWatcher, config) assert len(w) == numws - 1