
Jira Integration & Graphical Test Builder
We are proud to announce the release of two new features, available immediately. 🚀 Jira Integration: Automate Issue Tracking for...
Guide on load testing real-time GraphQL subscriptions with LoadForge using Locust.
You are now browsing the LoadForge locust test directory. You can use these tests as a starting point for your own tests, or use our AI wizard to generate one automatically.
GraphQL subscriptions provide real-time data streams over WebSockets. LoadForge supports subscription load testing by leveraging Locust and the WebSocketUser
from locust-plugins
.
# locust.py
import json
from locust import between, task
from locust_plugins.users import WebSocketUser
class GraphqlSubsUser(WebSocketUser):
wait_time = between(1, 3)
host = "wss://api.yourdomain.com/graphql"
def on_start(self):
# Open WebSocket connection
self.connect("/graphql")
# Initialize the subscription
init_msg = {"type": "connection_init", "payload": {}}
self.send(json.dumps(init_msg))
self.receive()
# Start subscription
sub_msg = {
"id": "1",
"type": "start",
"payload": {"query": "subscription { newMessage { content sender } }"}
}
self.send(json.dumps(sub_msg))
@task
def listen(self):
# Receive a subscription event
event = self.receive()
data = json.loads(event)
print(data)
Notes:
pip install locust locust-plugins websockets
if you wish to test locally.host
and GraphQL query with your subscription endpoint.