A request file mainly refers to the files needed to build your request in a stress test scenario, such as the files to be uploaded in a stress test API. Users can directly operate these request files in the scenario.
For example:
The stress test scenario for Qzone users posting images requires simulating the scenario of users uploading images.
In some bank scenarios, certificates need to be installed on the client, and simulating these scenarios requires opening and loading the certificates on the client.
Use the Request File
1. Upload request file:
2. Use request file in script:
Code for defining global variables (global): It runs once per concurrency.
Code for the main function (default): It runs once per iteration for each concurrency, and each VU will continuously iterate until it reaches the duration limit or iteration limit configured in the current stress test.
Therefore, it is recommended to define some static file read operations in the global scope, as a single concurrency only needs to read the file once. Avoid defining file reads in the main function, as this will result in reading the file in each iteration, leading to performance loss in stress testing.
// send a post request
import http from "pts/http";
const makefile = open("Makefile");
export const options = {};
export default function main() {
let response;
response = http.post("https://httpbin.org/post", makefile, {
headers: {
"Content-Type": "application/octet-stream",
},
});
}
3. The open function provides two modes. If the second parameter is empty, it returns a string; if it is 'b', it returns an ArrayBuffer.
export default function main() {
let data = open('Makefile');
console.log(data); // SHELL := /bin/bash ...
data = open('Makefile', 'b');
console.log(data); // [object ArrayBuffer]
}