Overview
You can use custom checkpoints to check whether the response results of requests meet business expectations. The check results will be summarized into checkpoint metrics for you to view details in the performance testing report.
Additionally, you can enable recording of associated logs for checkpoints and requests to view checkpoint information related to the requests on the request sampling side.
Usage
The PTS JavaScript API provides the check
method to create checkpoints.
The input parameters of the check
method are as follows:
name: name of the checkpoint.
callback: function used for checking, which should return a value of the Boolean type.
response (optional): response to the request being checked, which is used to enable checkpoint log recording.
The return value of the check
method is of the Boolean type, indicating whether this check is successful.
A basic example is as follows:
import http from 'pts/http';
import { check } from 'pts';
export default function () {
const resp = http.get('http://mockhttpbin.pts.svc.cluster.local/get');
check('statusCode is 200', () => resp.statusCode === 200);
check('statusCode is 200', () => resp.statusCode === 200, resp);
};
A common check logic example is as follows:
import { check } from 'pts';
export default function () {
check("is empty", () => "" === "")
check("is not empty", () => "str" !== "")
check("equals", () => 1.00 == 1)
check("not equal", () => 1.00 === 1)
check("less than", () => 1 < 2)
check("less or equal", () => 1 <= 1)
check("greater than", () => 2 > 1)
check("greater or equal", () => 2 >= 2)
check("has key", () => ({key:"value"}).hasOwnProperty("key"))
check("string has value", () => "str".includes("s"))
check("array has value", () => ["a", "b", "c"].includes("a"))
};
Note:
For more detailed API documentation, see pts.check. Metric Details
Log in to the TCOP console and select PTS > Test Scenarios in the left sidebar. On the performance testing report page, click Checkpoint Details and view the multidimensional metrics summarized from all check results. Associated Requests
When calling the check
method, if you pass in optional response parameters, the check results will be recorded in the request sampling logs in addition to being reflected in the above checkpoint metrics. You can view them on the request sampling page.
Click to select the sampling item you want to view.
Click a sampling request to enter the details page, where you can view the checkpoint content associated with the sampling request.
Log Printing of Checkpoints and Corresponding Requests
Checkpoints are logically separated from requests. A request can correspond to multiple checkpoints, and a checkpoint can check non-request content. At the same time, a request is responded normally (status code: 200), but the checkpoint may still fail, depending on the check conditions configured by users.
import http from 'pts/http';
import { check, sleep } from 'pts';
export default function () {
const resp = http.get('http://mockhttpbin.pts.svc.cluster.local/get', {
headers: {
Connection: 'keep-alive',
'User-Agent': 'pts-engine',
},
query: {
name1: 'value1',
name2: 'value2',
},
});
check('status is 200', () => resp.statusCode === 200, resp);
check('body.args.name1 equals value1', () => resp.json().args.name1 === 'value1', resp);
check('body.args.name1 equals value2', () => resp.json().args.name1 === 'value2', resp);
let v = 1;
check("v==1", () => v==1);
check("v==2", () => v==2);
}
However, in actual use, checkpoints and requests are often used together to check whether the request response meets expectations. Therefore, it is crucial to obtain the association between checkpoints and requests.
In the Associated Requests section, by setting the response parameters in the check
method, you can record the checkpoint results in the request sampling logs, which meets the association requirements for both in some cases. However, in certain situations, there may be more customized requirements for details. In this case, you can print the required content in logs within the check conditions of a checkpoint to view more details.
import http from 'pts/http';
import { check } from 'pts';
export default function () {
const resp = http.get('http://mockhttpbin.pts.svc.cluster.local/get', {
query: {
name1: 'value1',
},
});
check('body.args.name1 equals value2', () => {
if (resp.json().args.name1 === 'value2') {
return true
};
console.log(resp.body);
console.log(`check not pass, name1 need value2 but ${resp.json().args.name1}`);
return false;
});
}