From 6d2b28a59e8d8ebc86f6021c0c66973efdad8c66 Mon Sep 17 00:00:00 2001 From: Omar Ghishan Date: Fri, 3 Jan 2014 15:52:37 -0800 Subject: [PATCH] Handle starting/stopping Kafka brokers that are already started/stopped in integration tests If some of the tests stop brokers then error out, the teardown method will try to close the same brokers and fail. This change allows it to continue. --- test/fixtures.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/fixtures.py b/test/fixtures.py index c771a58..17e6672 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -272,8 +272,13 @@ class KafkaFixture(object): self.tmp_dir = None self.child = None + self.running = False def open(self): + if self.running: + print("*** Kafka instance already running") + return + self.tmp_dir = tempfile.mkdtemp() print("*** Running local Kafka instance") print(" host = %s" % self.host) @@ -318,10 +323,16 @@ class KafkaFixture(object): self.child.start() self.child.wait_for(r"\[Kafka Server %d\], Started" % self.broker_id) print("*** Done!") + self.running = True def close(self): + if not self.running: + print("*** Kafka instance already stopped") + return + print("*** Stopping Kafka...") self.child.stop() self.child = None print("*** Done!") shutil.rmtree(self.tmp_dir) + self.running = False