Complex Example: Multiple Capabilities

A comprehensive example demonstrating many advanced features of the LPS tool in one scenario.

Complete Script

name: SecureDataExample
variables:
- name: baseUrl
  value: https://example.com
- name: tokenEndpoint
  value: ${baseUrl}/auth/token
- name: dataEndpoint
  value: ${baseUrl}/data
- name: csvData
  value: $read(path=data/users.csv)
  as: csv
- name: number
  value: 10
  as: int
rounds:
- name: SecureDataRound
  numberOfClients: 100
  arrivalDelay: 100
  runInParallel: false
  iterations:
  - name: FetchToken
    httpRequest:
      url: $tokenEndpoint
      httpMethod: POST
      payload:
        raw: '{"client_id": "$users[$counter(name=namesCounter, start=0, reset=5),1]", "client_secret": "$users[$counter(name=passwordsCounter, start=0, reset=5),2]"}'
      capture:
        to: authResponse
        as: qjson
      httpHeaders:
        Content-Type: application/json
  - name: GetData
    skipIf: '${authResponse.Body.access_token} = "" or $authResponse.StatusCode <>200'
    httpRequest:
      url: $dataEndpoint
      httpMethod: Get
  - name: GetPaginatedData
    mode: R
    requestCount: 10
    skipIf: '${authResponse.Body.access_token} = "" or $authResponse.StatusCode <>200'
    httpRequest:
      url: $dataEndpoint/?page=$counter(name=pageCounter, start=0, reset=200, step=20)
      httpMethod: Get
    failureRules:
      - metric: "ErrorRate > 0.3"
        errorStatusCodes: ">= 400"
    terminationRules:
      - metric: "ErrorRate > 0.3"
        errorStatusCodes: ">= 400"
        gracePeriod: "00:00:03"
      - metric: "TotalTime.P90 > 400"
        gracePeriod: "00:00:10"
environments:
- name: production
  variables:
  - name: environment
    value: production
    as: qstring
  - name: baseUrl
    value: https://example.com

Overview

The SecureDataExample plan demonstrates a secure data-fetching workflow where:

  1. Tokens are fetched from an authentication endpoint
  2. Those tokens are used to retrieve paginated data from a protected API
  3. The test runs under specific conditions, with failure rules and termination rules

Variables Section

Variable Description
baseUrl Base URL for the API requests
tokenEndpoint Built dynamically using ${baseUrl}
dataEndpoint Built dynamically as ${baseUrl}/data
csvData Reads data from CSV file, parsed into rows and columns
number Numeric variable with value 10, typed as integer

The $read() function demonstrates how LPS can pull external data into tests.

Round Configuration

Property Description
numberOfClients 100 virtual users simulate concurrent clients
arrivalDelay Each client starts after a 100 ms delay
runInParallel false means iterations run sequentially

Iteration 1: FetchToken

Simulates a login or token retrieval request.

Details:

  • Sends a POST request to $tokenEndpoint.
  • Uses dynamic credentials pulled from the CSV file:
    • $counter cycles through CSV rows.
    • start=0 β†’ starts from row 0.
    • reset=5 β†’ after 5 cycles, it resets.
    • [ ,1] β†’ refers to column index 1.
  • The request body is JSON with Content-Type: application/json.
  • The response is captured into a variable called authResponse as qjson (quoted JSON).

Iteration 2: GetData

Fetches protected data only if the token is valid.

Key condition:

skipIf: '${authResponse.Body.access_token} = "" or $authResponse.StatusCode <>200'

Prevents running this iteration if:

  • The token (access_token) is empty, or
  • The request failed (StatusCode not equal to 200).

πŸ’‘ Note: Placeholders containing underscores or any special character like (_) must be wrapped with ${}.

Iteration 3: GetPaginatedData

Tests repeated (looped) requests under certain conditions.

PropertyDescription
mode: Rβ€œRepeat” mode β€” repeats requests multiple times.
requestCount: 10Each client sends 10 repeated requests.
skipIfSame condition as before (skip if token invalid).
httpRequest.urlAdds a page number using $counter with step increments of 20.
failureRulesDefines when the iteration is marked as failed after completion. Uses inline metric expressions.
terminationRulesDefines live stop conditions during execution. Uses inline metric expressions.

⚠️ Note: The old failureCriteria format (with maxErrorRate, maxP90, etc.) and old terminationRules format have been permanently removed as of version 3.0.2.6. The last version supporting the old format was 3.0.2.5.

Failure & Termination Rules

Failure Rules

failureRules:
  - metric: "ErrorRate > 0.3"
    errorStatusCodes: ">= 400"

If the error rate exceeds 30% (counting 4xx and 5xx errors), the iteration is marked as Failed.

Termination Rules

terminationRules:
  - metric: "ErrorRate > 0.3"
    errorStatusCodes: ">= 400"
    gracePeriod: "00:00:03"
  - metric: "TotalTime.P90 > 400"
    gracePeriod: "00:00:10"
  • Error-based rule: If errors exceed 30% for 3 continuous seconds, the iteration stops
  • Latency-based rule: If P90 latency exceeds 400 ms for 10 continuous seconds, the iteration stops

These rules are continuously monitored by the master node.

Environments Section

Defines environment-specific overrides.

VariableDescription
environmentMarks this environment as "production".
baseUrlOverrides the base URL to https://example.com.

βœ… This allows running the same plan across environments (staging, production, etc.) just by switching the flag.

Summary

Concept Demonstrated Feature
Variables Basic, dynamic, environment-specific, and from CSV
Loops $counter() for cycling through CSV rows or paginated requests
Capture Store response data into variables for later use
Conditional Execution skipIf to skip iterations based on runtime logic
Metrics & Termination Failure rules and real-time termination rules
Environments Override variables cleanly per environment

Run Command

lps run SecureDataExample.yaml --environment production

Executes the test plan using the production environment variables.

In Short

This example simulates logging in with multiple user credentials, fetching secure data, and paging through results β€” all while automatically stopping when error or performance thresholds are breached.

It demonstrates how LPS dynamically controls test behavior using variables, metrics, and intelligent execution rules.