Overview

In this quick start, you’ll perform your first load test using Multiple to assess the performance of an example chat application. Our test scenario covers user sign-up, monitoring message traffic, and chat history retrieval using Multiple’s built-in axios as the HTTP client and faker for generating mock data. The built-in axios client automatically captures metrics for you. At the end of this guide, you’ll know how to create, run, and analyze load tests using Multiple.

This guide uses the same code that’s included in the demo test (”Lots of Chat”) loaded into your account when you sign up.

Sign up for a free Multiple account

Before running your first load test with Multiple, you’ll need to sign up for a free account and log in.

Create a New Test

After you’ve signed into your account. The first step is to create a new test. In the top-right corner of the screen, select + New Test and then select JS Test Spec.

Create a new test

Write Test Spec

The next step is to write your load test. In this section, you’ll initialize your test, configure your virtual users, and clean up after running the test.

Write a test spec

Use the code below to:

  1. Set your NPM dependencies
  2. Create an axios HTTP client
  3. Log in to obtain a JWT
  4. Post and get chat messages via the sample API repeatedly
Test Spec
// faker for generating synthetic data
import { faker } from '@faker-js/faker';

class LotsOfChatMxTestSpec {
  npmDeps = {
    '@faker-js/faker': '7.6.0',
  };

  async globalInit(ctx) {
    // `globalInit` runs once at the start of the test
    // Not needed for this test
  }

  async vuInit(ctx) {
    // Set the base url of Multiple's built-in axios instance
    // The built-in axios instance automatically capture metrics
    ctx.axios.defaults.baseURL = process.env.API_BASE_URL;

    // Log in as a user and get a JWT
    const res = await ctx.axios.post('login', {
      email: `user+${ctx.info.vuId}@multiple.dev`,
      password: 'testpassword#1234',
    });
    const jwt = res.data.token;

    // Debug Run log to check we are getting the JWT correctly
    console.debug('JWT Token: ', jwt);

    // Set the authorization header
    ctx.axios.defaults.headers.common['Authorization'] = `Bearer ${jwt}`;
  }

  async vuLoop(ctx) {
    // Send a POST request to the chat endpoint with a random message
    await ctx.axios.post('chat', {
      // Generate synthetic data with faker
      message: faker.lorem.paragraph(),
    });

    // Send a GET request to the chat endpoint
    await ctx.axios.get('chat');
  }

  async vuCleanup(ctx) {
    // `vuCleanup` runs once per VU (Virtual User) after `vuLoop`
    // Not needed for this test
  }

  async globalCleanup(ctx) {
    // `globalCleanup` runs once at the end of the test after `vuCleanup`
    // Not needed for this test
  }
}

Environment Variables

You can set the environment variables just like you would in a standard dotenv file. All environment variables are treated as strings.

Let’s add an environment variable for the base URL that this test requires.

You can configure and set multiple sets of environment variables.
# Base URL for the API
API_BASE_URL=https://example-api.multiple.dev

Run Load Test

In the top-right corner of the dashboard, select Start Test.

Run load test

On the next screen, there are a number of configurable options, like the number of VUs, the test duration, ramp up duration, loop duration, and environment variables to use. For this example, you’re going to use the default settings.

Select Start Test.

Test Run Options

View Results

When the test starts it can take a few seconds before you’ll see results. The report will continue to update for the duration of the test.

To view any previously run load tests, select Results from the left panel of the dashboard.

Test Results

Export Data

When the load test is done, you can download the data by selecting Export Data in the top-right of the dashboard.

Export Data