Example tests and snippets

WordPress Load Test Example

Load testing (aka stress testing) your WordPress Blog or CMS is made extremely easy by LoadForge, and you can test it with a free account today. We are going to be showing how to simulate a real set of users, browsing through your latest blog posts at random.

The nicest feature about this test is that it will automatically crawl valid URLs and then request them like a real user, at random. This can be applied to many types of tests.

Code example

The below code requests /blog/ and then gets all the anchor tags on that page to crawl all your latest blog posts. You can adjust this to whatever the appropriate settings would be for your site.

You should also replace the static_content with appropriate links for your theme.

from locust import HttpUser, task, between
from pyquery import PyQuery
import random


class QuickstartUser(HttpUser):
    wait_time = between(5, 9)


    def index_page(self):
        r = self.client.get("/blog/")
        pq = PyQuery(r.content)


        link_elements = pq(".blog-list-post h2 a")
        self.blog_urls = []


        for l in link_elements:
          if "href" in l.attrib:
            self.blog_urls.append(l.attrib["href"])


    def on_start(self):
        self.index_page()


    @task(1)
    def static_content(self):
        # images
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/cta_img.png")
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/footer_fire.png")
        # styles
        self.client.get("/css/compiled.css?id=629e6d86d0748098936a")
        # scripts
        self.client.get("/js/compiled.js?id=1a927dbcfa8d96520959")


    @task(3)
    def blog_post(self):
        url = random.choice(self.blog_urls)
        r = self.client.get(url)


    @task(3)
    def home_page(self):
        self.client.get("/blog/")

Locust Test Example

LoadForge is powered by locust, meaning open source locust users can copy this script as well. If you are a locust user, consider importing your script to LoadForge to supercharge your testing!

Previous
Websockets (SocketIO)