Skip to content

Commit

Permalink
soak test with sms
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Oct 24, 2023
1 parent 86be8bc commit 1d5a824
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
1 change: 1 addition & 0 deletions scripts/soak_test/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
API_KEY=
EMAIL_TEMPLATE_ID=
SMS_TEMPLATE_ID=
30 changes: 0 additions & 30 deletions scripts/soak_test/soak_test_send_email.py

This file was deleted.

38 changes: 38 additions & 0 deletions scripts/soak_test/soak_test_send_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

from dotenv import load_dotenv
from locust import HttpUser, constant_pacing, events, task
from soak_utils import url_with_prefix

load_dotenv()


@events.init_command_line_parser.add_listener
def _(parser):
parser.add_argument("--ref", type=str, default="test", help="reference")
parser.add_argument("--type", type=str, default="email", help="email or sms")


class NotifyApiUser(HttpUser):
wait_time = constant_pacing(1) # each user makes one post per second

def __init__(self, *args, **kwargs):
self.host = url_with_prefix(self.host, "api")

super(NotifyApiUser, self).__init__(*args, **kwargs)
self.headers = {"Authorization": f"apikey-v1 {os.getenv('API_KEY')}"}
self.email_template = os.getenv("EMAIL_TEMPLATE_ID")
self.sms_template = os.getenv("SMS_TEMPLATE_ID")
self.email_address = "[email protected]"
self.phone_number = "+16135550123" # INTERNAL_TEST_NUMBER
self.reference_id = self.environment.parsed_options.ref
self.type = self.environment.parsed_options.type

@task(1)
def send_notification(self):
if self.type == "email":
json = {"email_address": self.email_address, "template_id": self.email_template, "reference": self.reference_id}
self.client.post("/v2/notifications/email", json=json, headers=self.headers)
else:
json = {"phone_number": self.phone_number, "template_id": self.sms_template, "reference": self.reference_id}
self.client.post("/v2/notifications/sms", json=json, headers=self.headers)

0 comments on commit 1d5a824

Please sign in to comment.