tests: Discover absence of zookeeper faster
It turns out that when no zookeeper server is available for tests python ./setup.py test spends almost half of it's running time looking for it. This change addresses that and makes unit tests run roughly two times faster on my zookeeperless machine: - client starting timeout reduced from default 15 seconds to 3 seconds, which should be more than enough to connect to localhost; - zookeeper availability is checked only once, on module import, and then saved for later re-use. Change-Id: I11932e7cca12436cde0bcf0a20cb2adb96fbb27a
This commit is contained in:
@@ -34,7 +34,8 @@ TEST_PATH_TPL = '/taskflow/persistence-test/%s'
|
||||
def _zookeeper_available():
|
||||
client = kazoo_utils.make_client(TEST_CONFIG)
|
||||
try:
|
||||
client.start()
|
||||
# NOTE(imelnikov): 3 seconds we should be enough for localhost
|
||||
client.start(timeout=3)
|
||||
zk_ver = client.server_version()
|
||||
if zk_ver >= impl_zookeeper.MIN_ZK_VERSION:
|
||||
return True
|
||||
@@ -43,14 +44,13 @@ def _zookeeper_available():
|
||||
except Exception:
|
||||
return False
|
||||
finally:
|
||||
try:
|
||||
client.stop()
|
||||
client.close()
|
||||
except Exception:
|
||||
pass
|
||||
kazoo_utils.finalize_client(client)
|
||||
|
||||
|
||||
@testtools.skipIf(not _zookeeper_available(), 'zookeeper is not available')
|
||||
_ZOOKEEPER_AVAILABLE = _zookeeper_available()
|
||||
|
||||
|
||||
@testtools.skipIf(not _ZOOKEEPER_AVAILABLE, 'zookeeper is not available')
|
||||
class ZkPersistenceTest(test.TestCase, base.PersistenceTestMixin):
|
||||
def _get_connection(self):
|
||||
return self.backend.get_connection()
|
||||
|
||||
Reference in New Issue
Block a user