13
13
from .conftest import asynccontextmanager
14
14
from .test_pubsub import wait_for_message
15
15
16
+ pytestmark = pytest .mark .asyncio
17
+
16
18
17
19
@pytest .mark .onlynoncluster
18
20
class TestRedisAutoReleaseConnectionPool :
@@ -40,15 +42,13 @@ def has_no_connected_connections(pool: redis.ConnectionPool):
40
42
for x in pool ._available_connections + list (pool ._in_use_connections )
41
43
)
42
44
43
- @pytest .mark .asyncio
44
45
async def test_auto_disconnect_redis_created_pool (self , r : redis .Redis ):
45
46
new_conn = await self .create_two_conn (r )
46
47
assert new_conn != r .connection
47
48
assert self .get_total_connected_connections (r .connection_pool ) == 2
48
49
await r .aclose ()
49
50
assert self .has_no_connected_connections (r .connection_pool )
50
51
51
- @pytest .mark .asyncio
52
52
async def test_do_not_auto_disconnect_redis_created_pool (self , r2 : redis .Redis ):
53
53
assert r2 .auto_close_connection_pool is False , (
54
54
"The connection pool should not be disconnected as a manually created "
@@ -62,7 +62,6 @@ async def test_do_not_auto_disconnect_redis_created_pool(self, r2: redis.Redis):
62
62
assert len (r2 .connection_pool ._available_connections ) == 1
63
63
assert r2 .connection_pool ._available_connections [0 ].is_connected
64
64
65
- @pytest .mark .asyncio
66
65
async def test_auto_release_override_true_manual_created_pool (self , r : redis .Redis ):
67
66
assert r .auto_close_connection_pool is True , "This is from the class fixture"
68
67
await self .create_two_conn (r )
@@ -74,15 +73,13 @@ async def test_auto_release_override_true_manual_created_pool(self, r: redis.Red
74
73
assert self .has_no_connected_connections (r .connection_pool )
75
74
76
75
@pytest .mark .parametrize ("auto_close_conn_pool" , [True , False ])
77
- @pytest .mark .asyncio
78
76
async def test_close_override (self , r : redis .Redis , auto_close_conn_pool ):
79
77
r .auto_close_connection_pool = auto_close_conn_pool
80
78
await self .create_two_conn (r )
81
79
await r .aclose (close_connection_pool = True )
82
80
assert self .has_no_connected_connections (r .connection_pool )
83
81
84
82
@pytest .mark .parametrize ("auto_close_conn_pool" , [True , False ])
85
- @pytest .mark .asyncio
86
83
async def test_negate_auto_close_client_pool (
87
84
self , r : redis .Redis , auto_close_conn_pool
88
85
):
@@ -139,7 +136,6 @@ async def get_pool(
139
136
finally :
140
137
await pool .disconnect (inuse_connections = True )
141
138
142
- @pytest .mark .asyncio
143
139
async def test_connection_creation (self ):
144
140
connection_kwargs = {"foo" : "bar" , "biz" : "baz" }
145
141
async with self .get_pool (
@@ -149,7 +145,6 @@ async def test_connection_creation(self):
149
145
assert isinstance (connection , DummyConnection )
150
146
assert connection .kwargs == connection_kwargs
151
147
152
- @pytest .mark .asyncio
153
148
async def test_aclosing (self ):
154
149
connection_kwargs = {"foo" : "bar" , "biz" : "baz" }
155
150
pool = redis .ConnectionPool (
@@ -160,15 +155,13 @@ async def test_aclosing(self):
160
155
async with aclosing (pool ):
161
156
pass
162
157
163
- @pytest .mark .asyncio
164
158
async def test_multiple_connections (self , master_host ):
165
159
connection_kwargs = {"host" : master_host [0 ]}
166
160
async with self .get_pool (connection_kwargs = connection_kwargs ) as pool :
167
161
c1 = await pool .get_connection ()
168
162
c2 = await pool .get_connection ()
169
163
assert c1 != c2
170
164
171
- @pytest .mark .asyncio
172
165
async def test_max_connections (self , master_host ):
173
166
connection_kwargs = {"host" : master_host [0 ]}
174
167
async with self .get_pool (
@@ -179,7 +172,6 @@ async def test_max_connections(self, master_host):
179
172
with pytest .raises (redis .ConnectionError ):
180
173
await pool .get_connection ()
181
174
182
- @pytest .mark .asyncio
183
175
async def test_reuse_previously_released_connection (self , master_host ):
184
176
connection_kwargs = {"host" : master_host [0 ]}
185
177
async with self .get_pool (connection_kwargs = connection_kwargs ) as pool :
@@ -188,7 +180,6 @@ async def test_reuse_previously_released_connection(self, master_host):
188
180
c2 = await pool .get_connection ()
189
181
assert c1 == c2
190
182
191
- @pytest .mark .asyncio
192
183
async def test_repr_contains_db_info_tcp (self ):
193
184
connection_kwargs = {
194
185
"host" : "localhost" ,
@@ -202,7 +193,6 @@ async def test_repr_contains_db_info_tcp(self):
202
193
expected = "host=localhost,port=6379,db=1,client_name=test-client"
203
194
assert expected in repr (pool )
204
195
205
- @pytest .mark .asyncio
206
196
async def test_repr_contains_db_info_unix (self ):
207
197
connection_kwargs = {"path" : "/abc" , "db" : 1 , "client_name" : "test-client" }
208
198
async with self .get_pool (
@@ -228,7 +218,6 @@ async def get_pool(self, connection_kwargs=None, max_connections=10, timeout=20)
228
218
finally :
229
219
await pool .disconnect (inuse_connections = True )
230
220
231
- @pytest .mark .asyncio
232
221
async def test_connection_creation (self , master_host ):
233
222
connection_kwargs = {
234
223
"foo" : "bar" ,
@@ -241,7 +230,6 @@ async def test_connection_creation(self, master_host):
241
230
assert isinstance (connection , DummyConnection )
242
231
assert connection .kwargs == connection_kwargs
243
232
244
- @pytest .mark .asyncio
245
233
async def test_disconnect (self , master_host ):
246
234
"""A regression test for #1047"""
247
235
connection_kwargs = {
@@ -254,15 +242,13 @@ async def test_disconnect(self, master_host):
254
242
await pool .get_connection ()
255
243
await pool .disconnect ()
256
244
257
- @pytest .mark .asyncio
258
245
async def test_multiple_connections (self , master_host ):
259
246
connection_kwargs = {"host" : master_host [0 ], "port" : master_host [1 ]}
260
247
async with self .get_pool (connection_kwargs = connection_kwargs ) as pool :
261
248
c1 = await pool .get_connection ()
262
249
c2 = await pool .get_connection ()
263
250
assert c1 != c2
264
251
265
- @pytest .mark .asyncio
266
252
async def test_connection_pool_blocks_until_timeout (self , master_host ):
267
253
"""When out of connections, block for timeout seconds, then raise"""
268
254
connection_kwargs = {"host" : master_host [0 ]}
@@ -279,7 +265,6 @@ async def test_connection_pool_blocks_until_timeout(self, master_host):
279
265
assert asyncio .get_running_loop ().time () - start >= 0.05
280
266
await c1 .disconnect ()
281
267
282
- @pytest .mark .asyncio
283
268
async def test_connection_pool_blocks_until_conn_available (self , master_host ):
284
269
"""
285
270
When out of connections, block until another connection is released
@@ -300,7 +285,6 @@ async def target():
300
285
stop = asyncio .get_running_loop ().time ()
301
286
assert (stop - start ) <= 0.2
302
287
303
- @pytest .mark .asyncio
304
288
async def test_reuse_previously_released_connection (self , master_host ):
305
289
connection_kwargs = {"host" : master_host [0 ]}
306
290
async with self .get_pool (connection_kwargs = connection_kwargs ) as pool :
@@ -592,7 +576,6 @@ def get_connection(self):
592
576
593
577
594
578
class TestConnection :
595
- @pytest .mark .asyncio
596
579
async def test_on_connect_error (self ):
597
580
"""
598
581
An error in Connection.on_connect should disconnect from the server
@@ -611,7 +594,6 @@ async def test_on_connect_error(self):
611
594
@pytest .mark .onlynoncluster
612
595
@skip_if_server_version_lt ("2.8.8" )
613
596
@skip_if_redis_enterprise ()
614
- @pytest .mark .asyncio
615
597
async def test_busy_loading_disconnects_socket (self , r ):
616
598
"""
617
599
If Redis raises a LOADING error, the connection should be
@@ -625,7 +607,6 @@ async def test_busy_loading_disconnects_socket(self, r):
625
607
@pytest .mark .onlynoncluster
626
608
@skip_if_server_version_lt ("2.8.8" )
627
609
@skip_if_redis_enterprise ()
628
- @pytest .mark .asyncio
629
610
async def test_busy_loading_from_pipeline_immediate_command (self , r ):
630
611
"""
631
612
BusyLoadingErrors should raise from Pipelines that execute a
@@ -644,7 +625,6 @@ async def test_busy_loading_from_pipeline_immediate_command(self, r):
644
625
@pytest .mark .onlynoncluster
645
626
@skip_if_server_version_lt ("2.8.8" )
646
627
@skip_if_redis_enterprise ()
647
- @pytest .mark .asyncio
648
628
async def test_busy_loading_from_pipeline (self , r ):
649
629
"""
650
630
BusyLoadingErrors should be raised from a pipeline execution
@@ -661,14 +641,12 @@ async def test_busy_loading_from_pipeline(self, r):
661
641
662
642
@skip_if_server_version_lt ("2.8.8" )
663
643
@skip_if_redis_enterprise ()
664
- @pytest .mark .asyncio
665
644
async def test_read_only_error (self , r ):
666
645
"""READONLY errors get turned into ReadOnlyError exceptions"""
667
646
with pytest .raises (redis .ReadOnlyError ):
668
647
await r .execute_command ("DEBUG" , "ERROR" , "READONLY blah blah" )
669
648
670
649
@skip_if_redis_enterprise ()
671
- @pytest .mark .asyncio
672
650
async def test_oom_error (self , r ):
673
651
"""OOM errors get turned into OutOfMemoryError exceptions"""
674
652
with pytest .raises (redis .OutOfMemoryError ):
@@ -701,7 +679,6 @@ def test_connect_from_url_unix(self):
701
679
)
702
680
703
681
@skip_if_redis_enterprise ()
704
- @pytest .mark .asyncio
705
682
async def test_connect_no_auth_supplied_when_required (self , r ):
706
683
"""
707
684
AuthenticationError should be raised when the server requires a
@@ -713,7 +690,6 @@ async def test_connect_no_auth_supplied_when_required(self, r):
713
690
)
714
691
715
692
@skip_if_redis_enterprise ()
716
- @pytest .mark .asyncio
717
693
async def test_connect_invalid_password_supplied (self , r ):
718
694
"""AuthenticationError should be raised when sending the wrong password"""
719
695
with pytest .raises (redis .AuthenticationError ):
@@ -744,14 +720,12 @@ def assert_interval_advanced(self, connection):
744
720
diff = connection .next_health_check - asyncio .get_running_loop ().time ()
745
721
assert self .interval >= diff > (self .interval - 1 )
746
722
747
- @pytest .mark .asyncio
748
723
async def test_health_check_runs (self , r ):
749
724
if r .connection :
750
725
r .connection .next_health_check = asyncio .get_running_loop ().time () - 1
751
726
await r .connection .check_health ()
752
727
self .assert_interval_advanced (r .connection )
753
728
754
- @pytest .mark .asyncio
755
729
async def test_arbitrary_command_invokes_health_check (self , r ):
756
730
# invoke a command to make sure the connection is entirely setup
757
731
if r .connection :
@@ -765,7 +739,6 @@ async def test_arbitrary_command_invokes_health_check(self, r):
765
739
766
740
self .assert_interval_advanced (r .connection )
767
741
768
- @pytest .mark .asyncio
769
742
async def test_arbitrary_command_advances_next_health_check (self , r ):
770
743
if r .connection :
771
744
await r .get ("foo" )
@@ -775,7 +748,6 @@ async def test_arbitrary_command_advances_next_health_check(self, r):
775
748
await r .get ("foo" )
776
749
assert next_health_check < r .connection .next_health_check
777
750
778
- @pytest .mark .asyncio
779
751
async def test_health_check_not_invoked_within_interval (self , r ):
780
752
if r .connection :
781
753
await r .get ("foo" )
@@ -786,7 +758,6 @@ async def test_health_check_not_invoked_within_interval(self, r):
786
758
ping_call_spec = (("PING" ,), {"check_health" : False })
787
759
assert ping_call_spec not in m .call_args_list
788
760
789
- @pytest .mark .asyncio
790
761
async def test_health_check_in_pipeline (self , r ):
791
762
async with r .pipeline (transaction = False ) as pipe :
792
763
pipe .connection = await pipe .connection_pool .get_connection ()
@@ -798,7 +769,6 @@ async def test_health_check_in_pipeline(self, r):
798
769
m .assert_any_call ("PING" , check_health = False )
799
770
assert responses == [True , b"bar" ]
800
771
801
- @pytest .mark .asyncio
802
772
async def test_health_check_in_transaction (self , r ):
803
773
async with r .pipeline (transaction = True ) as pipe :
804
774
pipe .connection = await pipe .connection_pool .get_connection ()
@@ -810,7 +780,6 @@ async def test_health_check_in_transaction(self, r):
810
780
m .assert_any_call ("PING" , check_health = False )
811
781
assert responses == [True , b"bar" ]
812
782
813
- @pytest .mark .asyncio
814
783
async def test_health_check_in_watched_pipeline (self , r ):
815
784
await r .set ("foo" , "bar" )
816
785
async with r .pipeline (transaction = False ) as pipe :
@@ -835,7 +804,6 @@ async def test_health_check_in_watched_pipeline(self, r):
835
804
assert responses == [True , b"not-bar" ]
836
805
m .assert_any_call ("PING" , check_health = False )
837
806
838
- @pytest .mark .asyncio
839
807
async def test_health_check_in_pubsub_before_subscribe (self , r ):
840
808
"""A health check happens before the first [p]subscribe"""
841
809
p = r .pubsub ()
@@ -855,7 +823,6 @@ async def test_health_check_in_pubsub_before_subscribe(self, r):
855
823
subscribe_message = await wait_for_message (p )
856
824
assert subscribe_message ["type" ] == "subscribe"
857
825
858
- @pytest .mark .asyncio
859
826
async def test_health_check_in_pubsub_after_subscribed (self , r ):
860
827
"""
861
828
Pubsub can handle a new subscribe when it's time to check the
@@ -896,7 +863,6 @@ async def test_health_check_in_pubsub_after_subscribed(self, r):
896
863
m .assert_any_call ("PING" , p .HEALTH_CHECK_MESSAGE , check_health = False )
897
864
self .assert_interval_advanced (p .connection )
898
865
899
- @pytest .mark .asyncio
900
866
async def test_health_check_in_pubsub_poll (self , r ):
901
867
"""
902
868
Polling a pubsub connection that's subscribed will regularly
0 commit comments