Skip to content

Commit 7dc732a

Browse files
authored
[ServiceBus] initial stress test onboarding (Azure#22982)
* initial stress onboarding * lint + ignore stress tests * adams comments
1 parent d02051b commit 7dc732a

20 files changed

+856
-448
lines changed

eng/.docsettings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ known_content_issues:
7676
- ['sdk/loganalytics/azure-loganalytics/README.md', '#4554']
7777
- ['sdk/servicebus/azure-servicebus/README.md', '#4554']
7878
- ['sdk/servicebus/azure-servicebus/tests/perf_tests/README.md', '#4554']
79+
- ['sdk/servicebus/azure-servicebus/stress/scripts/README.md', '#4554']
7980
- ['sdk/servicefabric/azure-servicefabric/README.md', '#4554']
8081
- ['sdk/storage/azure-storage-blob/swagger/README.md', '#4554']
8182
- ['cognitivelanguage/azure-ai-language-questionanswering/swagger/README.md', '#4554']

sdk/servicebus/azure-servicebus/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Only run stress tests on request.
1616
if not any([arg.startswith('test_stress') or arg.endswith('StressTest') for arg in sys.argv]):
17-
collect_ignore.append("tests/stress_tests")
17+
collect_ignore.append("stress/scripts")
1818

1919
# Allow us to pass stress_test_duration from the command line.
2020
def pytest_addoption(parser):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: stress-test-addons
3+
repository: https://stresstestcharts.blob.core.windows.net/helm/
4+
version: 0.1.13
5+
digest: sha256:007ec9983233e0f8c8ad8aa7f1df5f57b1b4c127d223d59d233b3c5366bd5173
6+
generated: "2021-12-02T16:05:20.2152434-05:00"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2
2+
name: python-servicebus-stress-test
3+
description: python service bus stress test.
4+
version: 0.1.2
5+
appVersion: v0.2
6+
annotations:
7+
stressTest: 'true'
8+
namespace: python
9+
10+
dependencies:
11+
- name: stress-test-addons
12+
version: 0.1.13
13+
repository: https://stresstestcharts.blob.core.windows.net/helm/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.8-slim-buster
4+
5+
WORKDIR /app
6+
7+
COPY ./scripts /app/stress/scripts
8+
9+
WORKDIR /app/stress/scripts
10+
RUN pip3 install -r dev_requirements.txt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ServiceBus Stress Tests
2+
3+
TODO: README is currently a WIP and has minimal information for local testing. Need to update later.
4+
5+
The `stress_runner.py` file is AN EXAMPLE of how to run the tests, not the actual stress test file.
6+
The actual test files are prefixed with `test_` and `stress_test_`.
7+
8+
## Setup for local stress test runs
9+
10+
```cmd
11+
(env) ~/azure-servicebus> pip install .
12+
(env) ~/azure-servicebus/stress/scripts> pip install -r dev_requirements.txt
13+
```
14+
15+
## Test commands for local testing
16+
17+
Run the chosen test file with the following command:
18+
19+
```cmd
20+
(env) ~/azure-servicebus/stress/scripts> python test_stress_queues.py
21+
```

sdk/servicebus/azure-servicebus/tests/stress_tests/app_insights_metric.py renamed to sdk/servicebus/azure-servicebus/stress/scripts/app_insights_metric.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def __init__(self, test_name, test_description=None):
8888
self.mmap = self.stats_recorder.new_measurement_map()
8989

9090
def record_messages_cpu_memory(self, number_of_messages, cpu_usage, memory_usage):
91+
if not number_of_messages:
92+
# if not batch size, then only single message being sent
93+
number_of_messages = 1
9194
self.mmap.measure_int_put(self.messages_measure, number_of_messages)
9295
self.mmap.measure_float_put(self.memory_measure, memory_usage)
9396
self.mmap.measure_float_put(self.cpu_measure, cpu_usage)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#-------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
#--------------------------------------------------------------------------
6+
import pytest
7+
import os
8+
import sys
9+
from azure.servicebus import ServiceBusClient
10+
from dotenv import load_dotenv
11+
12+
LOGGING_ENABLE = False
13+
ENV_FILE = os.environ.get('ENV_FILE')
14+
load_dotenv(dotenv_path=ENV_FILE, override=True)
15+
16+
# Allow us to pass stress_test_duration from the command line. TODO: may not actually be using this.
17+
def pytest_addoption(parser):
18+
parser.addoption('--stress_test_duration_seconds', action="store", default=None)
19+
20+
# Note: This is duplicated between here and the basic conftest, so that it does not throw warnings if you're
21+
# running locally to this SDK. (Everything works properly, pytest just makes a bit of noise.)
22+
def pytest_configure(config):
23+
# register an additional marker
24+
config.addinivalue_line(
25+
"markers", "liveTest: mark test to be a live test only"
26+
)
27+
config.addinivalue_line(
28+
"markers", "live_test_only: mark test to be a live test only"
29+
)
30+
config.addinivalue_line(
31+
"markers", "playback_test_only: mark test to be a playback test only"
32+
)
33+
34+
# fixture needs to be visible from conftest
35+
36+
@pytest.fixture(scope="session", autouse=True)
37+
def sb_client():
38+
service_bus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR']
39+
client = ServiceBusClient.from_connection_string(
40+
service_bus_connection_str, logging_enable=LOGGING_ENABLE)
41+
return client
42+
43+
@pytest.fixture()
44+
def servicebus_queue_name(sb_client):
45+
sb_queue_name = os.environ['SERVICE_BUS_QUEUE_NAME']
46+
return sb_queue_name
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
aiohttp>=3.0; python_version >= '3.5'
22
opencensus-ext-azure
33
psutil
4+
pytest
5+
azure-servicebus
6+
python-dotenv

0 commit comments

Comments
 (0)