Skip to content

Commit

Permalink
first working locust
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Apr 17, 2024
1 parent 56eccee commit 1efb2ad
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions tests/storm/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
from locust import HttpUser, between, task, tag
from locust import FastHttpUser, between, task

import json
import pika
import time


class RabbitMQUser(HttpUser):
host = "http://localhost:5672"
wait_time = between(1, 5)

# def on_start(self):
# # Establish connection to RabbitMQ server
# self.connection = pika.BlockingConnection(
# pika.ConnectionParameters(host="localhost", port=5672)
# )
# self.channel = self.connection.channel()
# API endpoint for publishing messages to a queue
# https://www.freekb.net/Article?id=3108
PUBLISH_URL = "/api/exchanges/%2f/pids/publish"

# self.channel.exchange_declare(exchange="pids", exchange_type="topic")

# def on_stop(self):
# # Close RabbitMQ connection
# self.connection.close()
class RabbitMQUser(FastHttpUser):
host = "http://localhost:15672"
wait_time = between(1, 5)

@task
def send_cmip6_message(self):
Expand All @@ -36,10 +26,26 @@ def send_cmip6_message(self):
"url_original_data": "http://vesg.ipsl.upmc.fr/thredds/fileServer/cmip6/temp.nc",
"url_replica": "http://esgf3.dkrz.de/thredds/fileServer/cmip6/temp.nc",
}
# Publish message to RabbitMQ queue
# self.channel.basic_publish(
# exchange="pids", routing_key="cmip6.test", body=json.dumps(message)
# )

time.sleep(1)
return True
data = json.dumps(message)

# Message payload
payload = {
"properties": {},
"routing_key": "cmip6.test",
"payload": data,
"payload_encoding": "string",
}

# Send the message to RabbitMQ
with self.rest(
"POST", PUBLISH_URL, json=payload, auth=("guest", "guest")
) as response:
if response.js is None:
pass # no need to do anything, already marked as failed
elif "routed" not in response.js:
response.failure(f"'routed' missing from response {response.text}")
elif response.js["routed"] is False:
response.failure(
f"'routed' had an unexpected value: {response.js['routed']}"
)

0 comments on commit 1efb2ad

Please sign in to comment.