From 756d2652326e3f0db9f51f9ffc66362a63d6e1d5 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 26 May 2016 15:23:44 +0200 Subject: [PATCH] Expose timeout capabilities and use them for tests Change-Id: I5b6ee43e6a6b91859dacedb9791da74e247cd12b --- tooz/coordination.py | 7 +++++++ tooz/drivers/file.py | 1 + tooz/drivers/ipc.py | 1 + tooz/drivers/mysql.py | 1 + tooz/drivers/pgsql.py | 1 + tooz/drivers/zake.py | 1 + tooz/drivers/zookeeper.py | 1 + tooz/tests/test_coordination.py | 11 +++++------ 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tooz/coordination.py b/tooz/coordination.py index 480fbde..4307684 100644 --- a/tooz/coordination.py +++ b/tooz/coordination.py @@ -50,6 +50,13 @@ class Characteristics(enum.Enum): """Coordinator components when used by multiple **hosts** work the same as if those components were only used by a single thread.""" + NON_TIMEOUT_BASED = 'NON_TIMEOUT_BASED' + """The driver has the following property: + + * Its operations are not based on the timeout of other clients, but on some + other more robust mechanisms. + """ + LINEARIZABLE = 'LINEARIZABLE' """The driver has the following properties: diff --git a/tooz/drivers/file.py b/tooz/drivers/file.py index e6b92b2..7d424a5 100644 --- a/tooz/drivers/file.py +++ b/tooz/drivers/file.py @@ -205,6 +205,7 @@ class FileDriver(coordination._RunWatchersMixin, """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, coordination.Characteristics.DISTRIBUTED_ACROSS_PROCESSES, ) diff --git a/tooz/drivers/ipc.py b/tooz/drivers/ipc.py index e705e0f..2698be5 100644 --- a/tooz/drivers/ipc.py +++ b/tooz/drivers/ipc.py @@ -150,6 +150,7 @@ class IPCDriver(coordination.CoordinationDriver): """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, coordination.Characteristics.DISTRIBUTED_ACROSS_PROCESSES, ) diff --git a/tooz/drivers/mysql.py b/tooz/drivers/mysql.py index cab05ff..467a54e 100644 --- a/tooz/drivers/mysql.py +++ b/tooz/drivers/mysql.py @@ -105,6 +105,7 @@ class MySQLDriver(coordination.CoordinationDriver): """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, coordination.Characteristics.DISTRIBUTED_ACROSS_PROCESSES, coordination.Characteristics.DISTRIBUTED_ACROSS_HOSTS, diff --git a/tooz/drivers/pgsql.py b/tooz/drivers/pgsql.py index e843dd3..c2a940b 100644 --- a/tooz/drivers/pgsql.py +++ b/tooz/drivers/pgsql.py @@ -161,6 +161,7 @@ class PostgresDriver(coordination.CoordinationDriver): """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, coordination.Characteristics.DISTRIBUTED_ACROSS_PROCESSES, coordination.Characteristics.DISTRIBUTED_ACROSS_HOSTS, diff --git a/tooz/drivers/zake.py b/tooz/drivers/zake.py index 7f81bf3..4a010be 100644 --- a/tooz/drivers/zake.py +++ b/tooz/drivers/zake.py @@ -33,6 +33,7 @@ class ZakeDriver(zookeeper.KazooDriver): """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, ) """ diff --git a/tooz/drivers/zookeeper.py b/tooz/drivers/zookeeper.py index 8675a6b..4f5521d 100644 --- a/tooz/drivers/zookeeper.py +++ b/tooz/drivers/zookeeper.py @@ -435,6 +435,7 @@ class KazooDriver(BaseZooKeeperDriver): """ CHARACTERISTICS = ( + coordination.Characteristics.NON_TIMEOUT_BASED, coordination.Characteristics.DISTRIBUTED_ACROSS_THREADS, coordination.Characteristics.DISTRIBUTED_ACROSS_PROCESSES, coordination.Characteristics.DISTRIBUTED_ACROSS_HOSTS, diff --git a/tooz/tests/test_coordination.py b/tooz/tests/test_coordination.py index 447249b..a096f25 100644 --- a/tooz/tests/test_coordination.py +++ b/tooz/tests/test_coordination.py @@ -47,13 +47,11 @@ class TestAPI(testscenarios.TestWithScenarios, 'bad_url': 'kazoo://localhost:1'}), ('zake', {'url': 'zake://?timeout=5'}), ('memcached', {'url': os.getenv("TOOZ_TEST_MEMCACHED_URL"), - 'bad_url': 'memcached://localhost:1', - 'timeout_capable': True}), + 'bad_url': 'memcached://localhost:1'}), ('ipc', {'url': 'ipc://'}), ('file', {'url': 'file:///tmp'}), ('redis', {'url': os.getenv("TOOZ_TEST_REDIS_URL"), - 'bad_url': 'redis://localhost:1', - 'timeout_capable': True}), + 'bad_url': 'redis://localhost:1'}), ('postgresql', {'url': os.getenv("TOOZ_TEST_POSTGRESQL_URL"), 'bad_url': 'postgresql://localhost:1'}), ('mysql', {'url': os.getenv("TOOZ_TEST_MYSQL_URL"), @@ -377,8 +375,9 @@ class TestAPI(testscenarios.TestWithScenarios, self.assertTrue(member_id_test2 not in members_ids) def test_timeout(self): - if not getattr(self, "timeout_capable", False): - self.skipTest("This test only works with timeout capable drivers") + if (tooz.coordination.Characteristics.NON_TIMEOUT_BASED + in self._coord.CHARACTERISTICS): + self.skipTest("This driver is not based on timeout") self._coord.stop() if "?" in self.url: sep = "&"