To customize the behavior (passing in custom parameter values and overriding the default configuration) of the performance testing engine during the execution of performance testing tasks, you can set the global Options to control parameters, such as Transport Layer Security (TLS)/HTTP/WebSocket communication configuration parameters and preprocessing/post-processing timeout interval.
To set the global Options, you can define an option object (export const option = {...}
) at the outermost layer of the script, and define fields, such as tlsConfig
and http
in the option object based on your needs.
Note:
For parameter details, see the PTS JavaScript API documentation Option. HTTP Global Configuration
Through the http
field in option
, you can configure relevant parameters for the performance testing engine as an HTTP client. These parameters take effect globally for all HTTP requests in this performance testing task.
Common parameters are as follows:
headers
: Request header.
basicAuth
: When using HTTP basic authentication, pass in the username and password through this parameter.
disableKeepAlives
: To disable persistent connection, set this field to true.
discardResponseBody
: To discard the response body returned by the server, set this field to true.
http2
: To enable HTTP/2, set this field to true.
maxIdleConns
: Maximum number of connections per VU. The default value is 100.
maxIdleConnsPerHost
: Maximum number of connections per VU for a single host (address + port). The default value is 2.
maxRedirects
: Maximum number of redirects. The default value is 10.
timeout
: Request timeout interval, in milliseconds. The default value is 10000 (10 seconds).
Script example:
import http from 'pts/http';
import { check } from 'pts';
export const option = {
http: {
maxRedirects: 10,
maxIdleConns: 100,
headers: {
'key': 'value'
}
}
}
export default function () {
// get request with headers and parameters
const resp1 = http.get('http://httpbin.org/get', {
headers: {
Connection: 'keep-alive',
'User-Agent': 'pts-engine',
},
query: {
name1: 'value1',
name2: 'value2',
},
});
console.log(resp1.json().args.name1); // 'value1'
check('status is 200', () => resp1.statusCode === 200);
check('body.args.name1 equals value1', () => resp1.json().args.name1 === 'value1');
check('headers.key equals value', () => resp1.json().headers.key === 'value')
}
WebSocket Global Configuration
Through the ws
field in option
, you can configure relevant parameters for the performance testing engine as a WebSocket client. These parameters take effect globally for all WebSocket requests in this performance testing task.
Common parameters are as follows:
handshakeTimeout
: Handshake timeout interval, in milliseconds. The default value is 30 seconds.
readTimeout
: Timeout interval for reading messages, in milliseconds. It is not limited by default.
writeControlTimeout
: Timeout interval for writing control instructions, in milliseconds. The default value is 10 seconds.
writeTimeout
: Timeout interval for writing messages, in milliseconds. It is not limited by default.
Example:
export const option = {
ws: {
writeTimeout: 3000,
readTimeout: 3000,
}
}
TLS Global Configuration
As the client, the performance testing engine supports the following configuration options when a TLS connection is established:
insecureSkipVerify
: Whether to verify the certificate chain and hostname of the server. If it is set to true, no validation will be performed (the default value is false).
rootCAs
: A set of root certificate authorities used when verifying server certificates. If it is left empty, the root CA set of the host will be used by default.
certificates
: A list of certificates provided by the client for server verification in mutual TLS authentication (certificate files can be uploaded through File Management > Request File
in the scenario).
Example:
export const option = {
tlsConfig: {
'localhost': {
insecureSkipVerify: false,
rootCAs: [open('ca.crt')],
certificates: [{cert: open('client.crt'), key: open('client.key')}]
}
}
}
Preprocessing and Post-Processing Configuration
setupTimeoutSeconds: timeout interval for the preprocessing (setup) step. The default value is 60 seconds. Example:
export const option = { setupTimeoutSeconds: 30 }
teardownTimeoutSeconds
: Timeout interval for the post-processing (teardown) step. The default value is 60 seconds.
export const option = {
teardownTimeoutSeconds: 30
}