New test execution APIs

Trigger Real Load test programmatically

Version 8.4.23 of the Real Load platform expose new API methods that allow triggering Load Test scripts programmatically, via REST API calls. This enhancement is quite important, as it allows you to automate performance test execution as part of build processes, etc…

Another use case would be to regularly execute performance test to maintain data volume in application databases. One of the applications I work with (Outseer’s Fraud Manager on Premise) has got internal housekeeping processes that over time will remove runtime data from its DB. While this is to be expected, it might be detrimental to environments to be used for performance testing, where you might want to simulate production like data volume, or at least maintain data to a specific size.

In this case, a good way to maintain the application data volume to a given size would be to simulate on a daily basis the same number of transactions that actually occur in production environment, by simulating a similar volume of API calls.

In this blog post I’ll illustrate with a simple PowerShell example how you can automate execution of a Real Load performance test using the newly exposed API methods.

The new API methods

As you can see in the v4.8.23 release notes, Real Load now exposes these new API methods:

  • getTestjobTemplates
  • defineNewTestjobFromTemplate
  • submitTestjob
  • makeTestjobReadyToRun
  • startTestjob
  • getMeasuringAgentTestjobs
  • getTestjobOutDirectoryFilesInfo
  • getTestjobOutDirectoryFile
  • saveTestjobOutDirectoryFileToProjectTree
  • deleteTestjob

Pre-requisites

Before getting started with the script, you’ll need to:

  1. Obtain the API authentication token from the Real Load portal:

  2. Configure a Load Testing template and note its ID

In the Load Test Jobs menu, look for a recently load test job that you’d like to trigger via the new APIs. To create a template from it, select the item pointed out in the screenshot:

  1. Get the AgentID from where you want to generate execute the test

… as shown in this screenshot.

Prepare you script

The next step involves preparing a script to invoke the Real Load API methods to trigger the test. I’ve used the following PowerShell script, which I’ll execute regularly as an Azure RunBook.

We’ll use 4 API methods:

  • defineNewTestjobFromTemplate
  • submitTestjob
  • makeTestjobReadyToRun
  • startTestjob

You’ll need to change the value of the agentId and templateId variables as needed. If you’re planning to run this script from an on-premises scheduler then you can hardcode the authToken value, instead of invoking Get-AutomationVariable.

$url='https://portal.realload.com/RemoteUserAPI'
$authToken=Get-AutomationVariable -Name 'RL_Portal_authToken'
$agentId=78
$templateId=787676

## Define test
$body = @{
  'authTokenValue'=$authToken
  'action'='defineNewTestjobFromTemplate'
  'templateId'=$templateId
  'measuringAgentOrClusterId'=$agentId
  'isCluster'=$false
  'jobDescription'= 'Daily seeding test'
}
$definedJobResp = Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"
Write-Host "JobId:" $definedJobResp.newTestjobId

if ($definedJobResp.isError -eq $true)
{
    Write-Error "defineNewTestjobFromTemplate failed"
    exit -1
}


## Submit job
$body = @{
  'authTokenValue'=$authToken
  'action'='submitTestjob'
  'localTestjobId'=$definedJobResp.newTestjobId
}
$submitJobResp = Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"

if ($submitJobResp.isError -eq $true)
{
    Write-Error "submitTestjob failed"
    exit -1
}

## Make job ready to run
$body = @{
  'authTokenValue'=$authToken
  'action'='makeTestjobReadyToRun'
  'localTestjobId'=$definedJobResp.newTestjobId
}
$makeJobReadyToRunResp = Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"

if ($makeJobReadyToRunResp.isError -eq $true)
{
    Write-Error "makeTestjobReadyToRun failed"
    exit -1
}
Write-Host "LocalTestJobId:" $makeJobReadyToRunResp.agentResponse.testjobProperties.localTestjobId
Write-Host "Max Test duration (s):" $makeJobReadyToRunResp.agentResponse.testjobProperties.testjobMaxTestDuration

## Start Job
$body = @{
  'authTokenValue'=$authToken
  'action'='startTestjob'
  'localTestjobId'=$definedJobResp.newTestjobId
}
$startTestjobnResp = Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"

if ($startTestjobnResp.isError -eq $true)
{
    Write-Error "startTestjob failed"
    exit -1
}
Write-Host "Job state:" $startTestjobnResp.agentResponse.testjobProperties.testjobState

Configure RunBook variable

Configure an Azure RunBook variable by the same name as used in the powershell script, in this example “RL_Portal_authToken”. Make sure you set the type to String and select the “Encrypted” flag.

Create a new PowerShell RunBook

Now create a new RunBook of type PowerShell and copy and paste the above code in it. Use the “Test pane” to test execution and when successfully tested save and publish.

Create a schedule

Create a schedule to fit your needs. In this example, it’s an hourly schedule with an expiration date set (optional).

Associate the schedule to the RunBook

The last step is to associate the schedule to the RunBook:

Done. From now on the selected perfomance test will be executed as per the configured schedule. You’ll be able to see the results of the executed Load Test in the Real Load portal.

Other use cases

The use case illustrated in this blog is a trivial use case. You can use similar code to integrate Real Load in your build pipelines of almost any CI/CD tool that you’re using.