2929from .server import args , get_host_port , get_uri , handler
3030
3131
32- @contextlib .asynccontextmanager
33- async def short_backoff_delay ():
32+ def short_backoff ():
3433 defaults = backoff .__defaults__
35- backoff . __defaults__ = (
34+ yield from backoff (
3635 defaults [0 ] * MS ,
3736 defaults [1 ] * MS ,
3837 defaults [2 ] * MS ,
3938 defaults [3 ],
4039 )
41- try :
42- yield
43- finally :
44- backoff .__defaults__ = defaults
4540
4641
4742@contextlib .asynccontextmanager
@@ -157,7 +152,6 @@ def create_connection(*args, **kwargs):
157152 ) as client :
158153 self .assertTrue (client .create_connection_ran )
159154
160- @short_backoff_delay ()
161155 async def test_reconnect (self ):
162156 """Client reconnects to server."""
163157 iterations = 0
@@ -179,7 +173,11 @@ async def process_request(connection, request):
179173
180174 async with serve (* args , process_request = process_request ) as server :
181175 with self .assertRaises (InvalidStatus ) as raised :
182- async for client in connect (get_uri (server ), open_timeout = 3 * MS ):
176+ async for client in connect (
177+ get_uri (server ),
178+ open_timeout = 3 * MS ,
179+ reconnect_delays = short_backoff ,
180+ ):
183181 self .assertEqual (client .protocol .state .name , "OPEN" )
184182 successful += 1
185183
@@ -190,7 +188,6 @@ async def process_request(connection, request):
190188 self .assertEqual (iterations , 6 )
191189 self .assertEqual (successful , 2 )
192190
193- @short_backoff_delay ()
194191 async def test_reconnect_with_custom_process_exception (self ):
195192 """Client runs process_exception to tell if errors are retryable or fatal."""
196193 iteration = 0
@@ -213,7 +210,9 @@ def process_exception(exc):
213210 async with serve (* args , process_request = process_request ) as server :
214211 with self .assertRaises (Exception ) as raised :
215212 async for _ in connect (
216- get_uri (server ), process_exception = process_exception
213+ get_uri (server ),
214+ process_exception = process_exception ,
215+ reconnect_delays = short_backoff ,
217216 ):
218217 self .fail ("did not raise" )
219218
@@ -223,7 +222,6 @@ def process_exception(exc):
223222 "🫖 💔 ☕️" ,
224223 )
225224
226- @short_backoff_delay ()
227225 async def test_reconnect_with_custom_process_exception_raising_exception (self ):
228226 """Client supports raising an exception in process_exception."""
229227
@@ -238,7 +236,9 @@ def process_exception(exc):
238236 async with serve (* args , process_request = process_request ) as server :
239237 with self .assertRaises (Exception ) as raised :
240238 async for _ in connect (
241- get_uri (server ), process_exception = process_exception
239+ get_uri (server ),
240+ process_exception = process_exception ,
241+ reconnect_delays = short_backoff ,
242242 ):
243243 self .fail ("did not raise" )
244244
0 commit comments