This topic describes how to orchestrate a stress testing scenario in Performance Testing (PTS) and perform stress testing. In this example, a common online education scenario is used.
Scenario description
An online education website needs to perform stress testing on web pages related to course selection. The course selection procedure is divided into three steps based on business logic. The following information describes the stress testing requirement for each step:
Log on to the online education system.
Construct the logon information of a user, including the username and password.
Pass the logon information of the user to the following requests: view the list of courses and submit selected courses. The logon information is stored in cookies.
View the list of courses.
Pass course IDs to the submit selected courses request.
Submit selected courses.
Use course IDs that are obtained from the preceding request to construct a "submit selected courses" request.
Determine whether the "submit selected courses" request is successful.
The following figure shows the basic settings of the stress testing scenario.
Prerequisites
PTS is activated. For more information, see Activate PTS.
A parameter file in the
CSV
format is prepared. The following sample code provides an example of the content format. For information about the requirements for parameter files, see Parameter file conventions.username,password user1,Password1 user2,Password2 user3,Password3
Step 1: Configure a stress testing scenario
Log on to the PTS console, choose , and then click PTS.
Import a parameter file to add a data source.
Click Data Sources. On the Files tab, click + Upload File and select an on-premises parameter file that you want to upload.
After you upload the parameter file, select Use First Row as Parameter Name. If you select this option, you do not need to define parameter names. The data in the first row of the parameter file is ignored when PTS reads the file.
Select Use First Row as Parameter Name. After you select this option, you do not need to specify the parameter names. The data in the first row is used as the parameter names. When PTS reads the parameter file, PTS ignores the data in the first row. If the data in the first row of the parameter file is not parameter names, you must specify a parameter name for each column based on your business scenario.
Add a parameter node.
On the Scenario Settings tab, add a stress testing API, click the drop-down arrow next to Add Instruction, and then select Parameter.
On the Data Source Parameters tab, select existing parameter names.
NoteIf you want to use each row only once to assemble requests, select Use Once. When the required data is polled once, the stress testing scenario stops generating new stress testing requests, regardless of the configured load level.
If you want to recycle parameters during a stress test, do not select Use Once.
You can select Use Once or Baseline Column, but not both for parameters. If you select Use Once, you cannot select Baseline Column.
Orchestrate the stress testing scenario.
Configure a logon API operation.
Test URL: Enter the URL that you want to test. In this example,
http://web.example.com/login
is used.Request Method: Select
POST
.Body definition: Set the
Content-Type
parameter tox-www-form-urlencoded
, click Text Format in the upper-right corner of the text editor, and then enter{"username":"${username}","password":"${password}"}
in the text editor.NoteThe user logon information that is stored in cookies is automatically shared with the other API operations in the stress testing scenario. You do not need to manually configure the logon information for the other API operations.
Configure an API operation used to query the list of courses.
Click Add API and select HTTP to add an API operation. Then, configure basic request information.
Test URL: Enter the URL on which you want to perform stress testing. In this example,
http://web.example.com/mocks/online/list
is used.Request Method: Select
POST
.
To pass a specific course ID to the next request, you must extract the course ID from the response of the current API operation and use the course ID as an output parameter. The following figure shows the required settings on the Output Parameter Definition tab.
Output Parameter Name: Enter a custom parameter name.
Source: Select the parsing format of the response body. For example, you can select Body: JSON.
Parsing expression: Enter a parsing expression based on the response details.
For example, if you want to extract the second course ID that is shown in the following response body, you must configure the
schedule_list[1].ID
expression.{ "schedule_list": [ { "Name": "math", "ID": "001" }, { "Name": "english", "ID": "002" }, { "Name": "science", "ID": "003" } ] }
NoteYou can use the expression debugging feature to debug the expressions that you configure for the output parameters of an API operation. This helps check whether the expressions are correct and meet your business requirements. If debugging is successful, you can use the expressions in the list of output parameters of the API operation. For more information, see Debug a stress testing scenario.
Configure an API operation used to submit selected courses.
Click Add API and select HTTP to add an API operation. Then, configure basic request information.
Test URL: Enter the URL on which you want to perform stress testing. In this example,
http://web.example.com/mocks/online/submit
is used.Request Method: Select
POST
.
Click the Request Body Definition tab. On this tab, configure the course ID that is extracted from the response information of the preceding API operation in the
request body
.Content-Type: Select
x-www-form-urlencoded
.Key: Enter a custom key. Example:
ID_from_last_api
.Value: In the lower part of the page, click Parameters. In the Parameters panel, click the Session Parameters tab. On the Session Parameters tab, view business session parameters such as ID and click the copy icon to copy the desired parameter value. Then, paste the copied parameter value into the Value column.
Click the Output Parameter Definition tab. On this tab, configure the following parameters.
Output Parameter Name: Enter a custom parameter name. Example:
result
.Source: Select the parsing format of the response body. Example: Body: TEXT.
NoteIn this example, you must select Body: TEXT for the Source parameter. You can use the expression debugging feature to debug the configured expressions when you debug the stress testing scenario.
Parsing expression: Enter a parsing expression based on the response details. In this example, the response body is
result:success
. In this case, the parsing expression must be configured asresult:(.+)
.
Click the Check Point (Assertion) tab. On this tab, configure a checkpoint for the API operation. The checkpoint can be used to determine whether the "submit selected courses" request is successful.
Check Point Type: Select Output Parameters.
Check Object: Select result.
Condition: Select Equal To.
Content: Enter
success
.
Step 2: Configure settings related to stress testing
After you configure the stress testing scenario, you must configure settings related to stress testing in the Stress Mode Configuration and Load Level Configuration sections of the Create PTS Scenario page.
Step 3: Debug the stress testing scenario and start stress testing
You can debug the scenario to check whether the configurations are valid and prevent test failures. We recommend that you debug the scenario. For more information, see Debug a scenario.
In the lower part of the PTS Scenario page, click Save and Start. In the Note dialog box, set the Execution Cycle parameter to Execute Now, select the check box for The test is permitted and complies with the applicable laws and regulations, and then click Start Test.
Analyze the stress testing results
After the stress test is complete, the system obtains the data generated during the test, such as the stress testing scenario metrics, business details, monitoring details, and API sampling logs, and then generates a stress testing report. You can view the report on the Reports page. For more information, see View a PTS-based stress testing report.