11from collections import namedtuple , deque
2+ import logging
3+
24import os
35import threading
46import time
1820from kazoo .protocol .states import KazooState
1921from kazoo .protocol .connection import _CONNECTION_DROP
2022from kazoo .testing import KazooTestCase
21- from kazoo .tests .util import wait
22- from kazoo .tests .util import CI_ZK_VERSION
23+ from kazoo .tests .util import wait , CI_ZK_VERSION , CI
24+
25+
26+ log = logging .getLogger (__name__ )
2327
2428
2529class Delete (namedtuple ("Delete" , "path version" )):
@@ -258,7 +262,7 @@ def back(state):
258262class TestReadOnlyMode (KazooTestCase ):
259263 def setUp (self ):
260264 os .environ ["ZOOKEEPER_LOCAL_SESSION_RO" ] = "true"
261- self .setup_zookeeper (read_only = True )
265+ self .setup_zookeeper (retry_no_interrupt = True )
262266 skip = False
263267 if CI_ZK_VERSION and CI_ZK_VERSION < (3 , 4 ):
264268 skip = True
@@ -278,8 +282,15 @@ def tearDown(self):
278282 def test_read_only (self ):
279283 from kazoo .exceptions import NotReadOnlyCallError
280284 from kazoo .protocol .states import KeeperState
285+ from kazoo .retry import KazooRetry
281286
282- client = self .client
287+ time .sleep (15 )
288+ self .client .stop ()
289+ conn_retry = KazooRetry (max_tries = - 1 , delay = 0.2 , max_delay = 180 )
290+ client = self ._get_client (connection_retry = conn_retry , read_only = True )
291+ # XXX: avoid the use of `interrupt`
292+ conn_retry .interrupt = None
293+ client ._connection .retry_sleeper = conn_retry .copy ()
283294 states = []
284295 ev = threading .Event ()
285296
@@ -289,6 +300,7 @@ def listen(state):
289300 if client .client_state == KeeperState .CONNECTED_RO :
290301 ev .set ()
291302
303+ client .start ()
292304 try :
293305 # stopping both nodes at the same time
294306 # else the test seems flaky when on CI hosts
@@ -303,7 +315,13 @@ def listen(state):
303315 thread .start ()
304316 for thread in zk_stop_threads :
305317 thread .join ()
306- ev .wait (15 )
318+ client .stop ()
319+ client .start ()
320+ # the latest ZK node can take time to recover on the CI
321+ time_to_wait = 30 if CI else 10
322+ ev .wait (time_to_wait )
323+ for line in self .cluster [0 ].get_logs (num_lines = 250 ):
324+ log .warning (line )
307325 assert ev .is_set ()
308326 assert client .client_state == KeeperState .CONNECTED_RO
309327
0 commit comments