I’m looking for a method to run a collection “calls” and have the calls execute Simultaneously. I’m familiar with the Performance test feature but there does not appear to be a way to remove the sequential aspect out of using it in a collection run.
I’m basically trying to execute 5 calls at exactly the same time - and repeat this process over and over.
I am not certain that there is a way to achieve this currently in Postman. However, I am curious to understand your specific use case for this feature. A workaround might be to make this API call in your scripts tabs, but that might be a bit hacky and inefficient.
Thanks for the reply - the use case is as stated wanting to determine the servers ability to handle these simultaneous calls - and if to see if there is a performance degradation as a result of doing it multiple times.
Yes. The performance testing feature allows you to specify a number of virtual users, it can be configured to have the virtual users make the same request at the same time. Why does this not work for your usecase?
While I do not know a method to run requests from a collection simultaneously, you could start them asynchronously from a pre-request script. Here is an example:
/**
* @summary Promisifies the pm.sendRequest API
* @param options The request configuration object
* @returns {Promise} If successful, the returned promise is resolved returning the response
* to the request. If it fails, the returned promise is rejected with the reported error.
*/
const asyncSendRequest = async (options) => {
return new Promise((resolve, reject) => {
pm.sendRequest(options, (error, response) =>{
if (error) reject(error);
else resolve(response);
});
});
};
const request1 = {
url: `${apiUrl}/your_POST_endpoint`,
method: 'POST',
header: {
'Content-Type': 'application/json',
},
body: {
mode: 'raw',
raw: JSON.stringify({ postData: "your data here"),
}
}
const request2 = {
url: `${apiUrl}/your_GET_endpoint`,
method: 'GET',
header: {
'Content-Type': 'application/json',
},
}
const responseStrings = Promise.all(
asyncSendRequest(request1),
asyncSendRequest(request2),
);
const responses = responseStrings.forEach((responseString) => JSON.parse(responseString));
// Do something with the responses. Of course, you should also do some error handling as some of the requests may fail for whatever reason.