httpyac icon indicating copy to clipboard operation
httpyac copied to clipboard

Parallel use error with exported variables

Open auriou opened this issue 6 months ago • 0 comments

I want to run load tests using httpyac's parallel mode, but it doesn't work when I use javascript blocks with exported variables. Here is an example of code that works without parallel mode, but gives errors with this mode.

{{
    const { faker } = require('@faker-js/faker');
    exports.sexType = faker.person.sexType()
    exports.password = faker.internet.password({ length: 10})
    exports.firstName = faker.person.firstName(exports.sexType)
    exports.lastName = faker.person.lastName(exports.sexType)
    exports.email = faker.internet.email({ firstName: exports.firstName, lastName: exports.lastName });
    exports.phone = faker.helpers.fromRegExp(/0[67][0-9]{8}/)
    exports.auth = "Basic " + Buffer.from(exports.firstName + ":" + exports.password).toString("base64")
}}

GET https://httpbin.org/basic-auth/{{firstName}}/{{password}}
Authorization: {{auth}}

{{
    exports.user = response.parsedBody.user;
    console.log('user', exports.user)
}}

GET https://httpbin.org/uuid
Token: {{user}}
{{
    exports.uuid = response.parsedBody.uuid;
}}

POST https://httpbin.org/anything/{{user}}
Token: {{uuid}}

It's ok without parallel

httpyac.js send senario-httpbin.http  --all  -o short 

GET https://httpbin.org/basic-auth/Carrie/KjnXrfgHzK
=> 200 (657 ms, 231 B)
user Carrie
---------------------
GET https://httpbin.org/uuid
=> 200 (543 ms, 235 B)
---------------------
POST https://httpbin.org/anything/Carrie
=> 200 (871 ms, 752 B)
3 requests processed (3 succeeded))

but Error with parallel mode

httpyac.js send senario-httpbin.http  --all  -o short --repeat 10  --repeat-mode  parallel  --parallel 2

GET https://httpbin.org/basic-auth/Marsha/A6ZL0Eqs25
=> 200 (2760.8 ms, ?)
user undefined

---------------------

GET https://httpbin.org/uuid
Token: {{user}}
[-] user is not defined (ReferenceError: user is not defined - Object.userJS (C:/Users/p.auriou/Documents/GIT/httpyac/examples/faker/senario-httpbin.http:23:20)
expression user throws error

---------------------

POST https://httpbin.org/anything/{{user}}
Token: {{uuid}}
[-] user is not defined (ReferenceError: user is not defined - Object.userJS (C:/Users/p.auriou/Documents/GIT/httpyac/examples/faker/senario-httpbin.http:28:20)
expression user throws error

3 requests processed (1 succeeded, 2 errored))

auriou avatar Aug 09 '24 09:08 auriou