2014-02-28 10:19:02 -07:00
|
|
|
import unittest
|
|
|
|
from tests.common import load_check
|
|
|
|
import time
|
|
|
|
|
2014-07-01 14:27:12 -07:00
|
|
|
|
2014-02-28 10:19:02 -07:00
|
|
|
class TestMySql(unittest.TestCase):
|
2014-07-01 14:27:12 -07:00
|
|
|
|
2014-02-28 10:19:02 -07:00
|
|
|
def setUp(self):
|
|
|
|
# This should run on pre-2.7 python so no skiptest
|
|
|
|
self.skip = False
|
|
|
|
try:
|
2016-04-07 12:35:12 +02:00
|
|
|
import pymysql
|
2014-02-28 10:19:02 -07:00
|
|
|
except ImportError:
|
|
|
|
self.skip = True
|
|
|
|
|
|
|
|
def testChecks(self):
|
|
|
|
if not self.skip:
|
2014-07-01 14:27:12 -07:00
|
|
|
agent_config = {'mysql_server': 'localhost',
|
|
|
|
'mysql_user': "datadog",
|
|
|
|
'mysql_pass': "phQOrbaXem0kP8JHri1qSMRS",
|
|
|
|
'version': '0.1',
|
|
|
|
'api_key': 'toto'}
|
2014-02-28 10:19:02 -07:00
|
|
|
|
2014-05-12 16:02:07 -06:00
|
|
|
# Initialize the check from checks_d
|
2014-05-06 09:55:15 -06:00
|
|
|
c = load_check('mysql', {'init_config': {}, 'instances': {}}, agent_config)
|
|
|
|
conf = c.parse_agent_config(agent_config)
|
|
|
|
self.check = load_check('mysql', conf, agent_config)
|
2014-02-28 10:19:02 -07:00
|
|
|
|
|
|
|
self.check.run()
|
|
|
|
metrics = self.check.get_metrics()
|
|
|
|
self.assertTrue(len(metrics) >= 8, metrics)
|
|
|
|
time.sleep(1)
|
|
|
|
self.check.run()
|
|
|
|
metrics = self.check.get_metrics()
|
|
|
|
self.assertTrue(len(metrics) >= 16, metrics)
|
2014-07-01 14:27:12 -07:00
|
|
|
|
2014-02-28 10:19:02 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|