SrinivasanTarget / python_flask_app

Sample Python Flask Application
0 stars 0 forks source link

Kafka e2e tests pass erroneously #1

Open mamachanko opened 3 years ago

mamachanko commented 3 years ago

Hi @SrinivasanTarget,

test_e2e_kafka passes erroneously since the assertion is not run. The consumer returns no messages.

diff --git a/test/test_e2e_kafka.py b/test/test_e2e_kafka.py
index 645702c..ab27b61 100644
--- a/test/test_e2e_kafka.py
+++ b/test/test_e2e_kafka.py
@@ -2,6 +2,7 @@ from kafka import KafkaProducer
 from kafka import KafkaConsumer
 from test.kafka import KafkaContainer

+
 def test_e2e_kafka():
     with KafkaContainer() as kafka:
         producer = KafkaProducer(bootstrap_servers=[kafka.get_bootstrap_servers()])
@@ -12,6 +13,6 @@ def test_e2e_kafka():
                         group_id='my_group',
                         bootstrap_servers=[kafka.get_bootstrap_servers()],
                         consumer_timeout_ms=9000)
-        for msg in consumer:
-            print(msg)
-            assert msg.value == 'Im Srinivasan Sekar'
\ No newline at end of file
+
+        assert [msg for msg in consumer.poll()] == ["Im Srinivasan Sekar"]
+        
\ No newline at end of file

I've come here for the sample Kafka container implementation via https://github.com/testcontainers/testcontainers-python/issues/121. I think it if we could fix that it might serve as a great example until testcontainers has its own Kafka container.

SrinivasanTarget commented 3 years ago

@mamachanko thanks for checking this out. Will try to fix and update you.

ash1425 commented 3 years ago

I have tried using different approach, please check latest commit if it looks ok? https://github.com/ash1425/testcontainers-python/blob/kafka-support/tests/test_kafka.py#L26-L34

mamachanko commented 3 years ago

Thanks @ash1425