diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index cee425a2..ad4f3b1f 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -619,7 +619,7 @@ def _connect_attempt(self, host, hostip, port, retry): self.ping_outstanding.clear() last_send = time.monotonic() with self._socket_error_handling(): - while not self.client._stopped.is_set(): + while True: # Watch for something to read or send jitter_time = random.randint(1, 40) / 100.0 deadline = last_send + read_timeout / 2.0 - jitter_time diff --git a/kazoo/tests/test_client.py b/kazoo/tests/test_client.py index 178a4452..e376baaf 100644 --- a/kazoo/tests/test_client.py +++ b/kazoo/tests/test_client.py @@ -258,8 +258,6 @@ def test_async_auth_failure(self): with pytest.raises(AuthFailedError): client.add_auth("unknown-scheme", digest_auth) - client.stop() - def test_add_auth_on_reconnect(self): client = self._get_client() client.start() diff --git a/kazoo/tests/test_lock.py b/kazoo/tests/test_lock.py index 397e971f..7e5ecb77 100644 --- a/kazoo/tests/test_lock.py +++ b/kazoo/tests/test_lock.py @@ -487,27 +487,29 @@ def test_rw_lock(self): lock = self.client.WriteLock(self.lockpath, "test") lock.acquire() + wait = self.make_wait() reader_thread.start() + # make sure reader_thread is a contender before writer_thread + wait(lambda: len(lock.contenders()) == 2) writer_thread.start() # wait for everyone to line up on the lock - wait = self.make_wait() wait(lambda: len(lock.contenders()) == 3) contenders = lock.contenders() assert contenders[0] == "test" remaining = contenders[1:] - # release the lock and contenders should claim it in order - lock.release() - contender_bits = { "reader": (reader_thread, reader_event), "writer": (writer_thread, writer_event), } - for contender in ("reader", "writer"): - thread, event = contender_bits[contender] + # release the lock and contenders should claim it in order + lock.release() + + for contender, contender_bits in contender_bits.items(): + _, event = contender_bits with self.condition: while not self.active_thread: