Skip to content

Commit 3e5509d

Browse files
Fix small lingering bugs in stress_test,
make duration overrideable from command line, remove historical stress tests now that they're ported.
1 parent 6accc80 commit 3e5509d

10 files changed

+32
-635
lines changed

sdk/servicebus/azure-servicebus/conftest.py

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
if not any([arg.startswith('test_stress') or arg.endswith('StressTest') for arg in sys.argv]):
2121
collect_ignore.append("tests/stress_tests")
2222

23+
# Allow us to pass stress_test_duration from the command line.
24+
def pytest_addoption(parser):
25+
parser.addoption('--stress_test_duration_seconds', action="store", default=None)
26+
2327
# Note: This is duplicated between here and the basic conftest, so that it does not throw warnings if you're
2428
# running locally to this SDK. (Everything works properly, pytest just makes a bit of noise.)
2529
def pytest_configure(config):

sdk/servicebus/azure-servicebus/tests/stress_tests/stress_test_base.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
from datetime import datetime, timedelta
99
import concurrent
10+
import sys
1011
import uuid
1112

1213
from azure.servicebus import ServiceBusClient, Message, BatchMessage
@@ -18,22 +19,30 @@ class ReceiveType:
1819
pull="pull"
1920

2021

21-
class StressTestResults:
22-
total_sent=0
23-
total_received=0
24-
time_elapsed=None
25-
state_by_sender={}
26-
state_by_receiver={}
22+
class StressTestResults(object):
23+
def __init__(self):
24+
self.total_sent=0
25+
self.total_received=0
26+
self.time_elapsed=None
27+
self.state_by_sender={}
28+
self.state_by_receiver={}
2729

30+
def __repr__(self):
31+
return str(vars(self))
2832

29-
class StressTestRunnerState:
33+
34+
class StressTestRunnerState(object):
3035
'''Per-runner state, e.g. if you spawn 3 senders each will have this as their state object,
3136
which will be coalesced at completion into StressTestResults'''
32-
total_sent=0
33-
total_received=0
37+
def __init__(self):
38+
self.total_sent=0
39+
self.total_received=0
3440

3541

3642
class StressTestRunner:
43+
'''Framework for running a service bus stress test.
44+
Duration can be overriden via the --stress_test_duration flag from the command line'''
45+
3746
def __init__(self,
3847
senders,
3948
receivers,
@@ -58,6 +67,11 @@ def __init__(self,
5867
# If we ever require multiple runs of this one after another, just make Run() reset this.
5968
self._state = StressTestRunnerState()
6069

70+
self._duration_override = None
71+
for arg in sys.argv:
72+
if arg.startswith('--stress_test_duration_seconds='):
73+
self._duration_override = timedelta(seconds=int(arg.split('=')[1]))
74+
6175

6276
# Plugin functions the caller can override to further tailor the test.
6377
@staticmethod
@@ -103,7 +117,7 @@ def _ConstructMessage(self):
103117
message = Message(self.PreProcessMessageBody("a" * self.message_size))
104118
self.PreProcessMessage(message)
105119
batch.add(message)
106-
self.PreProcessBatch(batch)
120+
self.PreProcessMessageBatch(batch)
107121
return batch
108122
else:
109123
message = Message(self.PreProcessMessageBody("a" * self.message_size))
@@ -147,7 +161,7 @@ def _Receive(self, receiver, end_time):
147161

148162
def Run(self):
149163
start_time = datetime.now()
150-
end_time = start_time + self.duration
164+
end_time = start_time + (self._duration_override or self.duration)
151165
sent_messages = 0
152166
received_messages = 0
153167
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as proc_pool:
@@ -160,5 +174,6 @@ def Run(self):
160174
result.total_sent = sum([r.total_sent for r in result.state_by_sender.values()])
161175
result.total_received = sum([r.total_received for r in result.state_by_receiver.values()])
162176
result.time_elapsed = end_time - start_time
177+
print("Stress test completed. Results:\n", result)
163178
return result
164179

sdk/servicebus/azure-servicebus/tests/stress_tests/stress_test_queue_peeklock_send_receive.py

-119
This file was deleted.

sdk/servicebus/azure-servicebus/tests/stress_tests/stress_test_queue_peeklock_send_receive_batch.py

-89
This file was deleted.

sdk/servicebus/azure-servicebus/tests/stress_tests/stress_test_queue_receivedelete_send_receive.py

-85
This file was deleted.

0 commit comments

Comments
 (0)