test: add kafka production smoke
This commit is contained in:
62
tools/test_go_kafka_prod_smoke.py
Normal file
62
tools/test_go_kafka_prod_smoke.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import unittest
|
||||
|
||||
from tools import go_kafka_prod_smoke as smoke
|
||||
|
||||
|
||||
class GoKafkaProdSmokeTest(unittest.TestCase):
|
||||
def test_parse_topic_list_marks_required_topics_present(self):
|
||||
topics = smoke.parse_topic_list("""
|
||||
vehicle.raw.go.gb32960.v1
|
||||
vehicle.raw.go.jt808.v1
|
||||
vehicle.raw.go.yutong-mqtt.v1
|
||||
vehicle.event.go.unified.v1
|
||||
""")
|
||||
|
||||
checks = smoke.topic_checks(topics, smoke.DEFAULT_TOPICS)
|
||||
|
||||
self.assertTrue(all(check.status == "pass" for check in checks))
|
||||
|
||||
def test_topic_checks_fail_when_required_topic_missing(self):
|
||||
topics = {"vehicle.raw.go.gb32960.v1"}
|
||||
|
||||
checks = smoke.topic_checks(topics, ["vehicle.raw.go.gb32960.v1", "vehicle.event.go.unified.v1"])
|
||||
|
||||
by_name = {check.name: check for check in checks}
|
||||
self.assertEqual(by_name["topic.vehicle.event.go.unified.v1"].status, "fail")
|
||||
|
||||
def test_parse_consumer_group_describe_reads_lag_rows(self):
|
||||
rows = smoke.parse_consumer_group_describe("""
|
||||
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG
|
||||
go-realtime-api vehicle.event.go.unified.v1 0 15992 15992 0
|
||||
go-realtime-api vehicle.event.go.unified.v1 1 2036 2036 3
|
||||
""")
|
||||
|
||||
self.assertEqual(rows[0].group, "go-realtime-api")
|
||||
self.assertEqual(rows[1].topic, "vehicle.event.go.unified.v1")
|
||||
self.assertEqual(rows[1].lag, 3)
|
||||
|
||||
def test_lag_checks_fail_when_lag_exceeds_threshold(self):
|
||||
rows = [
|
||||
smoke.ConsumerLag("go-history-writer", "vehicle.raw.go.jt808.v1", 0, 100, 100, 0),
|
||||
smoke.ConsumerLag("go-history-writer", "vehicle.raw.go.jt808.v1", 1, 100, 110, 10),
|
||||
]
|
||||
|
||||
check = smoke.group_lag_check("go-history-writer", rows, max_lag=5)
|
||||
|
||||
self.assertEqual(check.status, "fail")
|
||||
self.assertIn("max_lag=10", check.message)
|
||||
|
||||
def test_lag_checks_pass_when_group_has_rows_and_lag_is_small(self):
|
||||
rows = [
|
||||
smoke.ConsumerLag("go-stat-writer", "vehicle.raw.go.gb32960.v1", 0, 100, 100, 0),
|
||||
smoke.ConsumerLag("go-stat-writer", "vehicle.raw.go.jt808.v1", 1, 100, 101, 1),
|
||||
]
|
||||
|
||||
check = smoke.group_lag_check("go-stat-writer", rows, max_lag=5)
|
||||
|
||||
self.assertEqual(check.status, "pass")
|
||||
self.assertIn("max_lag=1", check.message)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user