Search code examples
javascripttypescriptperformance-testingload-testingk6

How to wait first post issue and use while loop in k6 load test scripts?


I have two post request. This post request should run until the response is "createdIsCompleted" == false .I m taking createdIsCompleted response from second post isssue. So how can I run two requests in while loop. By the way, I have to wait first post issue before the second post issue should be run...I know there is no await operator in k6. But I want to learn alternative ways. This while loop not working as I want. The response still returns "createdIsCompleted" == true

let createdISCompleted;
 describe('place products', (t) => {
            while (createdIsCompleted == false) {
              

               http.post(requestUrlAPI + 'PickingProcess.checkCell', JSON.stringify({
                    cellLabel: `${createdCellLabel}`,
                    pickingReferenceNumber: `${createdpickingProcessReferenceNumber}`,
                    allocatedItemId: `${createdAllocatedItemId}`,
                }), generateTokenHeader)

                let placeProductRes = http.post(requestUrlAPI + 'PickingProcess.placeProduct', JSON.stringify({
                    cellLabel: `${createdCellLabel}`,
                    pickingReferenceNumber: `${createdpickingProcessReferenceNumber}`,
                    pickingToteLabel: `${createdPickingToteLabel}`,
                    productLabel: `${createdProductLabel}`,
                    allocatedItemId: `${createdAllocatedItemId}`,
                }), generateTokenHeader) 
                createdIsCompleted = placeProductRes.json().isCompleted;
               
                break;
            }
        });


Solution

  • By the way, I have to wait first post issue before the second post issue should be run...I know there is no await operator in k6

    K6 currently has only blocking calls so each post will finish fully before the next one starts.

    On the loop question you have two(three) problems:

    • createdISCompleted is unitialized, so the while loop will never be run as it's not false.
    • you have big S in the declaration but then you have small s in the while loop.
    • you have break at the end of the loop which means it will always exit after the first iteration.