1010import sys
1111import time
1212
13- from azure .servicebus import ServiceBusClient
13+ from azure .servicebus import ServiceBusClient , AutoLockRenewer
1414from azure .servicebus ._common .constants import ReceiveMode
1515
1616from devtools_testutils import AzureMgmtTestCase , CachedResourceGroupPreparer
@@ -35,7 +35,7 @@ def test_stress_queue_send_and_receive(self, servicebus_namespace_connection_str
3535 receivers = [sb_client .get_queue_receiver (servicebus_queue .name )],
3636 duration = timedelta (seconds = 60 ))
3737
38- result = stress_test .Run ()
38+ result = stress_test .run ()
3939 assert (result .total_sent > 0 )
4040 assert (result .total_received > 0 )
4141
@@ -54,7 +54,7 @@ def test_stress_queue_send_and_pull_receive(self, servicebus_namespace_connectio
5454 receive_type = ReceiveType .pull ,
5555 duration = timedelta (seconds = 60 ))
5656
57- result = stress_test .Run ()
57+ result = stress_test .run ()
5858 assert (result .total_sent > 0 )
5959 assert (result .total_received > 0 )
6060
@@ -73,7 +73,7 @@ def test_stress_queue_batch_send_and_receive(self, servicebus_namespace_connecti
7373 duration = timedelta (seconds = 60 ),
7474 send_batch_size = 5 )
7575
76- result = stress_test .Run ()
76+ result = stress_test .run ()
7777 assert (result .total_sent > 0 )
7878 assert (result .total_received > 0 )
7979
@@ -92,7 +92,7 @@ def test_stress_queue_slow_send_and_receive(self, servicebus_namespace_connectio
9292 duration = timedelta (seconds = 3501 * 3 ),
9393 send_delay = 3500 )
9494
95- result = stress_test .Run ()
95+ result = stress_test .run ()
9696 assert (result .total_sent > 0 )
9797 assert (result .total_received > 0 )
9898
@@ -110,7 +110,7 @@ def test_stress_queue_receive_and_delete(self, servicebus_namespace_connection_s
110110 receivers = [sb_client .get_queue_receiver (servicebus_queue .name , receive_mode = ReceiveMode .ReceiveAndDelete )],
111111 duration = timedelta (seconds = 60 ))
112112
113- result = stress_test .Run ()
113+ result = stress_test .run ()
114114 assert (result .total_sent > 0 )
115115 assert (result .total_received > 0 )
116116
@@ -129,7 +129,7 @@ def test_stress_queue_unsettled_messages(self, servicebus_namespace_connection_s
129129 duration = timedelta (seconds = 350 ),
130130 should_complete_messages = False )
131131
132- result = stress_test .Run ()
132+ result = stress_test .run ()
133133 # This test is prompted by reports of an issue where enough unsettled messages saturate a service-side cache
134134 # and prevent further receipt.
135135 assert (result .total_sent > 2500 )
@@ -150,15 +150,16 @@ def test_stress_queue_receive_large_batch_size(self, servicebus_namespace_connec
150150 duration = timedelta (seconds = 60 ),
151151 max_message_count = 50 )
152152
153- result = stress_test .Run ()
153+ result = stress_test .run ()
154154 assert (result .total_sent > 0 )
155155 assert (result .total_received > 0 )
156156
157157 # Cannot be defined at local scope due to pickling into multiproc runner.
158158 class ReceiverTimeoutStressTestRunner (StressTestRunner ):
159- def OnSend (self , state , sent_message ):
159+ def on_send (self , state , sent_message , sender ):
160160 '''Called on every successful send'''
161161 if state .total_sent % 10 == 0 :
162+ # To make receive time out, in push mode this delay would trigger receiver reconnection
162163 time .sleep (self .max_wait_time + 5 )
163164
164165 @pytest .mark .liveTest
@@ -177,6 +178,124 @@ def test_stress_queue_pull_receive_timeout(self, servicebus_namespace_connection
177178 receive_type = ReceiveType .pull ,
178179 duration = timedelta (seconds = 600 ))
179180
180- result = stress_test .Run ()
181+ result = stress_test .run ()
181182 assert (result .total_sent > 0 )
182- assert (result .total_received > 0 )
183+ assert (result .total_received > 0 )
184+
185+
186+ class LongRenewStressTestRunner (StressTestRunner ):
187+ def on_receive (self , state , received_message , receiver ):
188+ '''Called on every successful receive'''
189+ renewer = AutoLockRenew ()
190+ renewer .register (received_message , timeout = 300 )
191+ time .sleep (300 )
192+
193+ @pytest .mark .liveTest
194+ @pytest .mark .live_test_only
195+ @CachedResourceGroupPreparer (name_prefix = 'servicebustest' )
196+ @ServiceBusNamespacePreparer (name_prefix = 'servicebustest' )
197+ @ServiceBusQueuePreparer (name_prefix = 'servicebustest' )
198+ def test_stress_queue_long_renew_send_and_receive (self , servicebus_namespace_connection_string , servicebus_queue ):
199+ sb_client = ServiceBusClient .from_connection_string (
200+ servicebus_namespace_connection_string , debug = False )
201+
202+ stress_test = ServiceBusQueueStressTests .LongRenewStressTestRunner (
203+ senders = [sb_client .get_queue_sender (servicebus_queue .name )],
204+ receivers = [sb_client .get_queue_receiver (servicebus_queue .name )],
205+ duration = timedelta (seconds = 3000 ),
206+ send_delay = 300 )
207+
208+ result = stress_test .run ()
209+ assert (result .total_sent > 0 )
210+ assert (result .total_received > 0 )
211+
212+
213+ class LongSessionRenewStressTestRunner (StressTestRunner ):
214+ def on_receive (self , state , received_message , receiver ):
215+ '''Called on every successful receive'''
216+ renewer = AutoLockRenewer ()
217+ def on_fail (renewable , error ):
218+ print ("FAILED AUTOLOCKRENEW: " + str (error ))
219+ renewer .register (receiver .session , timeout = 600 , on_lock_renew_failure = on_fail )
220+
221+ @pytest .mark .liveTest
222+ @pytest .mark .live_test_only
223+ @CachedResourceGroupPreparer (name_prefix = 'servicebustest' )
224+ @ServiceBusNamespacePreparer (name_prefix = 'servicebustest' )
225+ @ServiceBusQueuePreparer (name_prefix = 'servicebustest' , requires_session = True )
226+ def test_stress_queue_long_renew_session_send_and_receive (self , servicebus_namespace_connection_string , servicebus_queue ):
227+ sb_client = ServiceBusClient .from_connection_string (
228+ servicebus_namespace_connection_string , debug = False )
229+
230+ session_id = 'test_stress_queue_long_renew_send_and_receive'
231+
232+ stress_test = ServiceBusQueueStressTests .LongSessionRenewStressTestRunner (
233+ senders = [sb_client .get_queue_sender (servicebus_queue .name )],
234+ receivers = [sb_client .get_queue_receiver (servicebus_queue .name , session_id = session_id )],
235+ duration = timedelta (seconds = 3000 ),
236+ send_delay = 300 ,
237+ send_session_id = session_id )
238+
239+ result = stress_test .run ()
240+ assert (result .total_sent > 0 )
241+ assert (result .total_received > 0 )
242+
243+
244+ class Peekon_receiveStressTestRunner (StressTestRunner ):
245+ def on_receive_batch (self , state , received_message , receiver ):
246+ '''Called on every successful receive'''
247+ assert receiver .peek_messages ()[0 ]
248+
249+ @pytest .mark .liveTest
250+ @pytest .mark .live_test_only
251+ @CachedResourceGroupPreparer (name_prefix = 'servicebustest' )
252+ @ServiceBusNamespacePreparer (name_prefix = 'servicebustest' )
253+ @ServiceBusQueuePreparer (name_prefix = 'servicebustest' )
254+ def test_stress_queue_peek_messages (self , servicebus_namespace_connection_string , servicebus_queue ):
255+ sb_client = ServiceBusClient .from_connection_string (
256+ servicebus_namespace_connection_string , debug = False )
257+
258+ stress_test = ServiceBusQueueStressTests .Peekon_receiveStressTestRunner (
259+ senders = [sb_client .get_queue_sender (servicebus_queue .name )],
260+ receivers = [sb_client .get_queue_receiver (servicebus_queue .name )],
261+ duration = timedelta (seconds = 300 ),
262+ receive_delay = 30 ,
263+ receive_type = ReceiveType .none )
264+
265+ result = stress_test .run ()
266+ assert (result .total_sent > 0 )
267+ # TODO: This merits better validation, to be implemented alongside full metric spread.
268+
269+
270+ class RestartHandlerStressTestRunner (StressTestRunner ):
271+ def post_receive (self , state , receiver ):
272+ '''Called after completion of every successful receive'''
273+ if state .total_received % 3 == 0 :
274+ receiver .__exit__ ()
275+ receiver .__enter__ ()
276+
277+ def on_send (self , state , sent_message , sender ):
278+ '''Called after completion of every successful receive'''
279+ if state .total_sent % 3 == 0 :
280+ sender .__exit__ ()
281+ sender .__enter__ ()
282+
283+ @pytest .mark .liveTest
284+ @pytest .mark .live_test_only
285+ @CachedResourceGroupPreparer (name_prefix = 'servicebustest' )
286+ @ServiceBusNamespacePreparer (name_prefix = 'servicebustest' )
287+ @ServiceBusQueuePreparer (name_prefix = 'servicebustest' )
288+ def test_stress_queue_close_and_reopen (self , servicebus_namespace_connection_string , servicebus_queue ):
289+ sb_client = ServiceBusClient .from_connection_string (
290+ servicebus_namespace_connection_string , debug = False )
291+
292+ stress_test = ServiceBusQueueStressTests .RestartHandlerStressTestRunner (
293+ senders = [sb_client .get_queue_sender (servicebus_queue .name )],
294+ receivers = [sb_client .get_queue_receiver (servicebus_queue .name )],
295+ duration = timedelta (seconds = 300 ),
296+ receive_delay = 30 ,
297+ send_delay = 10 )
298+
299+ result = stress_test .run ()
300+ assert (result .total_sent > 0 )
301+ assert (result .total_received > 0 )
0 commit comments