0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-26 02:08:31 +00:00
alerta_alerta/tests/test_metrics.py
Nick Satterly 49ec257e76
Add attributes field to heartbeat for use in hb alerts (#1128)
* Add attributes field to heartbeat for use in hb alerts

* Whitespace fix for pre-commit hook to pass
2020-01-25 13:03:35 +01:00

36 lines
1.2 KiB
Python

import time
import unittest
from alerta.app import create_app, db
from alerta.models.metrics import Gauge, Timer
class MetricsTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app()
def tearDown(self):
db.destroy()
def test_metrics(self):
with self.app.test_request_context():
self.app.preprocess_request()
test_gauge = Gauge(group='test', name='gauge', title='Test gauge',
description='total time to process timed events')
test_gauge.set(500)
gauge = [g for g in Gauge.find_all() if g.title == 'Test gauge'][0]
self.assertGreaterEqual(gauge.value, 500)
test_timer = Timer(group='test', name='timer', title='Test timer',
description='total time to process timed events')
recv_started = test_timer.start_timer()
time.sleep(1)
test_timer.stop_timer(recv_started)
timer = [t for t in Timer.find_all() if t.title == 'Test timer'][0]
self.assertGreaterEqual(timer.count, 1)
self.assertGreaterEqual(timer.total_time, 999)