Skip to content

Commit 187a3ad

Browse files
authored
Merge pull request Azure#11 from KieranBrantnerMagee/kibrantn/servicebus/track-2-stress-test-cleanup
Kibrantn/servicebus/track 2 stress test cleanup
2 parents 1deb525 + ab85245 commit 187a3ad

10 files changed

+35
-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

+29-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,33 @@ 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
40+
41+
def __repr__(self):
42+
return str(vars(self))
3443

3544

3645
class StressTestRunner:
46+
'''Framework for running a service bus stress test.
47+
Duration can be overriden via the --stress_test_duration flag from the command line'''
48+
3749
def __init__(self,
3850
senders,
3951
receivers,
@@ -58,6 +70,11 @@ def __init__(self,
5870
# If we ever require multiple runs of this one after another, just make Run() reset this.
5971
self._state = StressTestRunnerState()
6072

73+
self._duration_override = None
74+
for arg in sys.argv:
75+
if arg.startswith('--stress_test_duration_seconds='):
76+
self._duration_override = timedelta(seconds=int(arg.split('=')[1]))
77+
6178

6279
# Plugin functions the caller can override to further tailor the test.
6380
@staticmethod
@@ -103,7 +120,7 @@ def _ConstructMessage(self):
103120
message = Message(self.PreProcessMessageBody("a" * self.message_size))
104121
self.PreProcessMessage(message)
105122
batch.add(message)
106-
self.PreProcessBatch(batch)
123+
self.PreProcessMessageBatch(batch)
107124
return batch
108125
else:
109126
message = Message(self.PreProcessMessageBody("a" * self.message_size))
@@ -147,7 +164,7 @@ def _Receive(self, receiver, end_time):
147164

148165
def Run(self):
149166
start_time = datetime.now()
150-
end_time = start_time + self.duration
167+
end_time = start_time + (self._duration_override or self.duration)
151168
sent_messages = 0
152169
received_messages = 0
153170
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as proc_pool:
@@ -160,5 +177,6 @@ def Run(self):
160177
result.total_sent = sum([r.total_sent for r in result.state_by_sender.values()])
161178
result.total_received = sum([r.total_received for r in result.state_by_receiver.values()])
162179
result.time_elapsed = end_time - start_time
180+
print("Stress test completed. Results:\n", result)
163181
return result
164182

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)