1
1
from collections import namedtuple , deque
2
+ import logging
3
+
2
4
import os
3
5
import threading
4
6
import time
18
20
from kazoo .protocol .states import KazooState
19
21
from kazoo .protocol .connection import _CONNECTION_DROP
20
22
from 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__ )
23
27
24
28
25
29
class Delete (namedtuple ("Delete" , "path version" )):
@@ -258,7 +262,7 @@ def back(state):
258
262
class TestReadOnlyMode (KazooTestCase ):
259
263
def setUp (self ):
260
264
os .environ ["ZOOKEEPER_LOCAL_SESSION_RO" ] = "true"
261
- self .setup_zookeeper (read_only = True )
265
+ self .setup_zookeeper (retry_no_interrupt = True )
262
266
skip = False
263
267
if CI_ZK_VERSION and CI_ZK_VERSION < (3 , 4 ):
264
268
skip = True
@@ -278,8 +282,15 @@ def tearDown(self):
278
282
def test_read_only (self ):
279
283
from kazoo .exceptions import NotReadOnlyCallError
280
284
from kazoo .protocol .states import KeeperState
285
+ from kazoo .retry import KazooRetry
281
286
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 ()
283
294
states = []
284
295
ev = threading .Event ()
285
296
@@ -289,6 +300,7 @@ def listen(state):
289
300
if client .client_state == KeeperState .CONNECTED_RO :
290
301
ev .set ()
291
302
303
+ client .start ()
292
304
try :
293
305
# stopping both nodes at the same time
294
306
# else the test seems flaky when on CI hosts
@@ -303,7 +315,13 @@ def listen(state):
303
315
thread .start ()
304
316
for thread in zk_stop_threads :
305
317
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 )
307
325
assert ev .is_set ()
308
326
assert client .client_state == KeeperState .CONNECTED_RO
309
327
0 commit comments