44import gc
55import logging
66import multiprocessing
7- import os
87import platform
98import sys
109import threading
3029from redis_lock import TimeoutTooLarge
3130from redis_lock import reset_all
3231
32+ pytest_plugins = 'pytester' ,
3333
3434def maybe_decode (data ):
3535 if isinstance (data , bytes ):
@@ -56,6 +56,22 @@ def conn(request, make_conn):
5656 return make_conn ()
5757
5858
59+ @pytest .fixture (params = ['normal' , 'gevent' , 'eventlet' ])
60+ def effect (request ):
61+ def wrap_name_with_effect (name ):
62+ if request .param == 'normal' :
63+ return name
64+ else :
65+ return '{}:{}' .format (name , request .param )
66+
67+ wrap_name_with_effect .expected_impl = {
68+ 'normal' : '_thread' ,
69+ 'gevent' : 'gevent.thread' ,
70+ 'eventlet' : 'eventlet.green.thread' ,
71+ }[request .param ]
72+ return wrap_name_with_effect
73+
74+
5975@pytest .fixture
6076def make_process (request ):
6177 """Process factory, that makes processes, that terminate themselves
@@ -78,19 +94,38 @@ def test_upgrade(request, conn):
7894 assert not lock .acquire (blocking = False )
7995
8096
81- def test_simple (redis_server ):
82- with TestProcess (sys .executable , HELPER , 'test_simple' ) as proc :
97+ def test_simple (redis_server , effect ):
98+ with TestProcess (sys .executable , HELPER , effect ( 'test_simple' ) ) as proc :
8399 with dump_on_error (proc .read ):
84100 name = 'lock:foobar'
85101 wait_for_strings (
86102 proc .read , TIMEOUT ,
87- 'Getting %r ...' % name ,
88- 'Got lock for %r .' % name ,
89- 'Releasing %r .' % name ,
103+ 'Acquiring Lock(%r) ...' % name ,
104+ 'Acquired Lock(%r) .' % name ,
105+ 'Releasing Lock(%r) .' % name ,
90106 'DIED.' ,
91107 )
92108
93109
110+ def test_simple_auto_renewal (redis_server , effect , LineMatcher ):
111+ with TestProcess (sys .executable , HELPER , effect ('test_simple_auto_renewal' )) as proc :
112+ with dump_on_error (proc .read ):
113+ name = 'lock:foobar'
114+ wait_for_strings (proc .read , TIMEOUT , 'DIED.' , )
115+ LineMatcher (proc .read ().splitlines ()).fnmatch_lines ([
116+ '* threading.get_ident.__module__=%s' % effect .expected_impl ,
117+ '* Acquiring Lock(%r) ...' % name ,
118+ '* Acquired Lock(%r).' % name ,
119+ '* Starting renewal thread for Lock(%r). Refresh interval: 0.6666666666666666 seconds.' % name ,
120+ '* Refreshing Lock(%r).' % name ,
121+ '* Refreshing Lock(%r).' % name ,
122+ '* Signaling renewal thread for Lock(%r) to exit.' % name ,
123+ '* Exiting renewal thread for Lock(%r).' % name ,
124+ '* Renewal thread for Lock(%r) exited.' % name ,
125+ '* Releasing Lock(%r).' % name ,
126+ ])
127+
128+
94129def test_no_block (conn ):
95130 with Lock (conn , "foobar" ):
96131 with TestProcess (sys .executable , HELPER , 'test_no_block' ) as proc :
0 commit comments