Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

locust install: pip3.11 install locust

01 Simple scenarios ("Hello World" mode)

Configuration

Simply pass through the URL entered at the start in the input form ("Number of Users", "Spawn rate", "Host") and test it - e.g. test  the homepage of your DS7 repo

vi locustfile.py

from locust import HttpUser, task

class HelloWorldUser(HttpUser):

@task def

   hello_world(self):

      self.client.get("/")

more on configs read https://docs.locust.io/en/stable/writing-a-locustfile.html#writing-a-locustfile

...

Attention: Standard http vs. https; Certs and Keys

[locust]$ locust --tls-cert /etc/pki/tls/certs/SERVERNAME/cert.pem --tls-key /etc/pki/tls/certs/SERVERNAME/privkey.pem

[2024-01-31 14:40:56,153] INFO/locust.main: Starting web interface at https://0.0.0.0:8089

[2024-01-31 14:40:56,166] INFO/locust.main: Starting Locust 2.20.1

UI

call Browser https://SERVERNAME:8089/ and start loadtests. First easy with 1 user:

...

See charts, failures, statistics and many more...

Screenshot 2024-01-30 at 10-39-05 Locust for locustfile.py.png

...

02 Real (warning) test scenarios (static & dynamic content)

  • Homepage

  • SubPage Communities

  • Search

  • Login Process incl. Token Autentication

...

Configuration (“complex” Mode)

vi locustfile.py

# Jens Witzel, Uni Zuerich 2024/01/30

import requests

from locust import HttpUser, task, between


class HelloWorldUser(HttpUser):

    @task

        def browse_homepage(self):

             self.client.get("/")


    @task

        def browse_cummunity(self):

             self.client.get("/communities/dc75f221-6ec0-4ff2-a72b-46d11444daa4")


         @task

         def search_items(self):

               needle = "test"

               self.client.get("/search?q={needle}") # Replace with the actual endpoint for searching items


       @task 

        def view_item_details(self): 

                item_id = "e0da84e0-0d71-41b6-9aee-17d7b29edca6" # Replace with the actual item ID

                self.client.get(f"/items/{item_id}") # Replace with the actual endpoint for viewing item details


class DSpaceUser(HttpUser):

           wait_time = between(1, 3) # Random wait time between 1 and 3 seconds

           @task def login(self): # get token

           getauthncookies = self.client.get("/server/api/authn", headers={})

          dscookies = dict(getauthncookies.cookies.get_dict()) 

           csrftoken = dscookies['DSPACE-XSRF-COOKIE']

           # post login with credentials and token

           response = self.client.post("https://SERVER/server/api/authn/login", {"user": USER, "password": PASSWORD}, headers={"X-XSRF-TOKEN":csrftoken}, cookies={"DSPACE-XSRF-COOKIE":csrftoken})

         if response.status_code == 200:

            print("Login successful")

        else:

           print(f"Login failed with status code: {response.status_code}")



Notes

  •     2 types of users (anonymous, registered user), login with token handling
  •     further, sequential storybook possible: login, workflow, upload, edit metadata, logout

...

Error rate increases as soon as system is overloaded


03 Really hard test scenarios: Recording workflow steps in FireFox to generate script for Locust

Creating a Locust configuration file from scratch is sometimes difficult, especially when complex workflows and work steps need to be analysed. 

One solution is to record typical work steps in the browser and save them in HAR format (
 ). This, in turn, can be created with the tool har2locust (
 ) into locustfile.py configuration files and an analysis as described above is ready to go.

The procedure:

    read the notes on

    [locust]$ pip3.11 install har2locust

Record FF session:

    Open DS7 page in browser

    Menu / Tools for developers | right mouse button + Examine

    Network analysis tab, click on bin (delete) - from then on the recording of the activities runs

    Execute DS7 actions (Login, MyDSpace, ... Logout)

    In column "File" right mouse button "Save as Har-File" save the recording

    sftp Har-File => SERVER

    [locust]$ har2locust x1.har > locustfile.py

    [locust]$ locust --tls-cert /etc/pki/tls/certs/SERVERNAME/cert.pem --tls-key /etc/pki/tls/certs/SERVERNAME/privkey.pem

...