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:
- Tokens are fetched from an authentication endpoint
- Those tokens are used to retrieve paginated data from a protected API
- 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 |
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
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.