embeddedkafka / embedded-kafka

A library that provides an in-memory Kafka instance to run your tests against.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout when wrapping an it clause in a withRunningKafka but not the other way around

cosminci opened this issue · comments

Hi,

Trying a simple test like:

    withRunningKafka {
      it("should pass") {
        publishStringMessageToKafka("topic", "message")
        consumeFirstStringMessageFrom("topic") shouldBe "message"
      }
    }

results in 10 seconds of

21:09:47.512 [kafka-producer-network-thread | producer-1] WARN  o.a.k.c.NetworkClient - [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:6001) could not be established. Broker may not be available.
21:09:47.512 [kafka-producer-network-thread | producer-1] WARN  o.a.k.c.NetworkClient - [Producer clientId=producer-1] Bootstrap broker localhost:6001 (id: -1 rack: null) disconnected

Followed by the test failing

net.manub.embeddedkafka.KafkaUnavailableException was thrown.
Caused by: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Topic topic not present in metadata after 10000 ms.
Caused by: org.apache.kafka.common.errors.TimeoutException: Topic topic not present in metadata after 10000 ms.

The issue manifests when withRunningKafka is wrapping the it clause and not the other way around i.e.

withRunningKafka {
      it("should pass") { ... }

doesn't work, while

it("should work") {
      withRunningKafka { ... }

works

Is this the expected behavior?

Hi @cosminci, the withRunningKafka closure must be used inside a test scenario definition to ensure proper server startup and shutdown.
Defining a test like yours leads to this behavior (println added by me):

entered withRunningKafka
exiting withRunningKafka
[info] ExternalClosureSpec:
entered it should work
[info] - should work *** FAILED ***
[info]   net.manub.embeddedkafka.KafkaUnavailableException:
...

Got it, thanks! Closing this as it's the expected behavior.