diff options
-rw-r--r-- | tooz/drivers/mysql.py | 7 | ||||
-rw-r--r-- | tooz/tests/test_mysql.py | 13 |
2 files changed, 19 insertions, 1 deletions
diff --git a/tooz/drivers/mysql.py b/tooz/drivers/mysql.py index 491eecc..8dc2691 100644 --- a/tooz/drivers/mysql.py +++ b/tooz/drivers/mysql.py @@ -58,11 +58,16 @@ class MySQLLock(locking.Lock): raise _retry.TryAgain return False + _, timeout = utils.convert_blocking(blocking) try: if not self._conn.open: self._conn.connect() cur = self._conn.cursor() - cur.execute("SELECT GET_LOCK(%s, 0);", self.name) + cur.execute( + ("SELECT GET_LOCK(%s, " + f"{timeout if timeout is not None else '0'});"), + self.name + ) # Can return NULL on error if cur.fetchone()[0] == 1: self.acquired = True diff --git a/tooz/tests/test_mysql.py b/tooz/tests/test_mysql.py index 735d9d0..c2a3941 100644 --- a/tooz/tests/test_mysql.py +++ b/tooz/tests/test_mysql.py @@ -85,3 +85,16 @@ class TestMySQLDriver(testcase.TestCase): ) ) + + @mock.patch("pymysql.Connect") + def test_parsing_timeout_settings(self, sql_mock): + c = self._create_coordinator("mysql://localhost:3306/test") + c.start() + + name = tests.get_random_uuid() + blocking_value = 10.12 + lock = c.get_lock(name) + with mock.patch.object(lock, 'acquire', wraps=True, autospec=True) as \ + mock_acquire: + with lock(blocking_value): + mock_acquire.assert_called_once_with(blocking_value) |