58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
import unittest
|
|
|
|
from tools import go_systemd_prod_smoke as smoke
|
|
|
|
|
|
class GoSystemdProdSmokeTest(unittest.TestCase):
|
|
def test_service_checks_require_all_go_units_active(self):
|
|
output = """
|
|
lingniu-go-gateway.service active
|
|
lingniu-go-history-writer.service active
|
|
lingniu-go-stat-writer.service active
|
|
lingniu-go-realtime-api.service active
|
|
"""
|
|
|
|
checks = smoke.service_checks(output, smoke.DEFAULT_SERVICES)
|
|
|
|
self.assertTrue(all(check.status == "pass" for check in checks))
|
|
|
|
def test_service_checks_fail_when_unit_is_missing_or_inactive(self):
|
|
output = """
|
|
lingniu-go-gateway.service active
|
|
lingniu-go-history-writer.service failed
|
|
"""
|
|
|
|
checks = smoke.service_checks(output, smoke.DEFAULT_SERVICES)
|
|
by_name = {check.name: check for check in checks}
|
|
|
|
self.assertEqual(by_name["service.lingniu-go-history-writer.service"].status, "fail")
|
|
self.assertEqual(by_name["service.lingniu-go-stat-writer.service"].status, "fail")
|
|
|
|
def test_port_checks_require_expected_go_processes(self):
|
|
output = """
|
|
LISTEN 0 4096 *:32960 *:* users:(("gateway",pid=10,fd=3))
|
|
LISTEN 0 4096 *:808 *:* users:(("gateway",pid=10,fd=4))
|
|
LISTEN 0 4096 *:20210 *:* users:(("realtime-api",pid=11,fd=3))
|
|
"""
|
|
|
|
checks = smoke.port_checks(output, smoke.DEFAULT_PORTS)
|
|
|
|
self.assertTrue(all(check.status == "pass" for check in checks))
|
|
|
|
def test_port_checks_fail_when_java_owns_ingest_port(self):
|
|
output = """
|
|
LISTEN 0 4096 *:808 *:* users:(("java",pid=20,fd=4))
|
|
LISTEN 0 4096 *:32960 *:* users:(("gateway",pid=10,fd=3))
|
|
LISTEN 0 4096 *:20210 *:* users:(("realtime-api",pid=11,fd=3))
|
|
"""
|
|
|
|
checks = smoke.port_checks(output, smoke.DEFAULT_PORTS)
|
|
by_name = {check.name: check for check in checks}
|
|
|
|
self.assertEqual(by_name["port.808"].status, "fail")
|
|
self.assertIn("java", by_name["port.808"].message)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|