check method to create checkpoints.check method are as follows:check method is of the Boolean type, indicating whether this check is successful.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); // Set a checkpoint to collect statistics on checkpoint metrics.check('statusCode is 200', () => resp.statusCode === 200, resp); // Set a checkpoint to collect statistics on checkpoint metrics and record checkpoint logs.};
import { check } from 'pts';export default function () {check("is empty", () => "" === "") // true//@ts-ignorecheck("is not empty", () => "str" !== "") // truecheck("equals", () => 1.00 == 1) // truecheck("not equal", () => 1.00 === 1) // truecheck("less than", () => 1 < 2) // truecheck("less or equal", () => 1 <= 1) // truecheck("greater than", () => 2 > 1) // truecheck("greater or equal", () => 2 >= 2) // truecheck("has key", () => ({key:"value"}).hasOwnProperty("key")) // truecheck("string has value", () => "str".includes("s")) // truecheck("array has value", () => ["a", "b", "c"].includes("a")) // true};

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.


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',},});// A request can correspond to multiple checkpoints.check('status is 200', () => resp.statusCode === 200, resp);check('body.args.name1 equals value1', () => resp.json().args.name1 === 'value1', resp);// The status code 200 is returned for a request, but the checkpoint may still fail (depending on the check conditions configured by users).check('body.args.name1 equals value2', () => resp.json().args.name1 === 'value2', resp);// A checkpoint can check non-request content.let v = 1;check("v==1", () => v==1);check("v==2", () => v==2);}
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',},});// Print user logs within the check conditions of a checkpoint.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;});}
Feedback