mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 18:26:15 +01:00
d5fb987d53
* Test Kafka * black format python * fix imports * add kafka and zk deps for testing * Include ZK and Kafka for all tests * fix signature for kafka helper * Connect to localhost for kafka * update kafka host for all test runs * Wrong env var for kafka * consolidate env vars for github actions * set the advertised hostname from the broker to localhost * add env var to docker-compose for kafka broker advert host * resort to what we do locally with /etc/hosts * Remove configs for kafka that won't be used
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from django.test import TestCase
|
|
|
|
from ee.kafka_client.client import _KafkaProducer, build_kafka_consumer
|
|
|
|
|
|
class KafkaClientTestCase(TestCase):
|
|
def setUp(self):
|
|
self.topic = "test_topic"
|
|
self.payload = {"foo": "bar"}
|
|
|
|
def test_kafka_interface(self):
|
|
producer = _KafkaProducer(test=True)
|
|
consumer = build_kafka_consumer(topic=self.topic, test=True)
|
|
|
|
producer.produce(topic=self.topic, data="any")
|
|
producer.close()
|
|
msg = next(consumer)
|
|
self.assertEqual(msg, "message 1 from test_topic topic")
|
|
|
|
def test_kafka_produce(self):
|
|
producer = _KafkaProducer(test=False)
|
|
producer.produce(topic=self.topic, data=self.payload)
|
|
producer.close()
|
|
|
|
def test_kafka_produce_and_consume(self):
|
|
producer = _KafkaProducer(test=False)
|
|
consumer = build_kafka_consumer(topic=self.topic, auto_offset_reset="earliest", test=False)
|
|
producer.produce(topic=self.topic, data=self.payload)
|
|
payload = next(consumer)
|
|
self.assertEqual(payload.value, self.payload)
|