Comments (5)
Hi @bear-su ,
I just created a server that modelled that response, and I was able to get the capture working in the before
section just fine. Are you sure your response is being returned correctly from the API? It might be worth trying to log the response from the API using an afterResponse hook
This is what I used:
const express = require('express');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const app = express();
const port = 9099;
app.use(bodyParser.json());
app.post('/auth', (req, res) => {
const adminData = {
id: 7,
adminId: "bears",
name: "",
introduction: "",
profileImageUrl: "",
adminRole: "",
createdBy: 1,
updatedBy: 1,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
};
const token = jwt.sign(
{
admin_role: "abc",
admin_id: "asdfasdf",
name: "asfas",
id: "7",
exp: Math.floor(Date.now() / 1000) + (60 * 60) // 1 hour expiration
},
'your-secret-key',
{ algorithm: 'HS512' }
);
res.json({
status: "OK",
data: {
admin: adminData,
token: token
},
message: null
});
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
config:
target: 'http://localhost:9099'
phases:
- duration: 5
arrivalRate: 5
before:
flow:
- log: 'Get auth token'
- post:
url: '/auth'
json:
username: 'arto'
password: 'localpassword'
capture:
- json: $.data.token
as: token
scenarios:
- flow:
- log: "Token is {{ token }}"
from artillery.
@bernardobridge Hi ! I closely checked it again. It still shows the same error.
I remove capture
keyword and tried running. It runs well and shows "Token is undefined. "
config:
target: 'http://localhost:9099'
phases:
- duration: 5
arrivalRate: 5
before:
flow:
- log: 'Get auth token'
- post:
url: '/auth'
json:
username: 'arto'
password: 'localpassword'
scenarios:
- flow:
- log: "Token is {{ token }}"
from artillery.
Hello @bear-su ,
I still can't reproduce the error with the test server example I put above... It works fine in a before
hook.
Perhaps you can inspect the response that's coming from the post and see if anything stands out as wrong. You can attach an afterResponse
hook to check that:
config:
target: 'http://localhost:9099'
phases:
- duration: 5
arrivalRate: 5
processor: ./helpers.js
before:
flow:
- log: 'Get auth token'
- post:
url: '/auth'
json:
username: 'arto'
password: 'localpassword'
afterResponse: logResponse
scenarios:
- flow:
- log: "Token is {{ token }}"
And create a ./helpers.js file:
function logResponse(req, res, context, ee, next) {
console.log(`Response body is:`)
console.log(res.body);
console.log(`Status Code is: ${res.statusCode}`);
next();
};
module.exports = {
logResponse
}
from artillery.
@bernardobridge I tried it and share the result.
[.yml]
config:
target: 'http://localhost:9099' # 테스트 진행할 URL phases:
- duration: 1
arrivalRate: 1
processor: helper.js
before:
flow:
- post:
url: '/admins/login'
json:
username: 'arto'
password: 'localpassword'
capture:
- json: $.data.token
as: token
scenarios:
- flow:
- post:
url: '/admin/articles/recommendations'
headers:
authorization: 'Bearer {{ token }}'
- post:
url: '/admin/articles/recommendations'
headers:
authorization: 'Bearer {{ token }}'
json:
article:
- {{ title }}
- {{ content }}
- {{ author }}
- {{ domesticStockArticleType }}
afterResponse: 'logResponse'
[helper.js]
function logResponse(req, res, context, ee, next) {
console.log("This is test")
console.log(`Response body is:`)
console.log(res.body);
console.log(`Status Code is: ${res.statusCode}`);
next();
};
module.exports = {
logResponse
}
[console.log]
DEBUG=http artillery run test/domestic-stock-register-test.yml
Test run id: t7apy_z5bqjd9dpre6m4y77xjwkcxf8mkf8_64mj
⠋ http request: {
"url": "http://localhost:9099/admins/login",
"method": "POST",
"headers": {
"user-agent": "Artillery (https://artillery.io)"
},
"json": {
"username": "arto",
"password": "localpassword"
}
} +0ms
http captures and matches: +1ms
http {} +0ms
http { token: { value: undefined, strict: undefined, failed: true } } +1ms
/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/@artilleryio/int-core/lib/engine_http.js:677
return done(new Error('Failed capture or match'), context);
^
Error: Failed capture or match
at /Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/@artilleryio/int-core/lib/engine_http.js:677:33
at /Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:473:16
at replenish (/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:1009:25)
at /Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:1019:9
at eachLimit$1 (/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:3199:24)
at Object.<anonymous> (/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:1049:16)
at captured (/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/@artilleryio/int-core/lib/engine_http.js:632:21)
at /Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/@artilleryio/int-commons/engine_util.js:499:16
at /Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:473:16
at replenish (/Users/arto/.nvm/versions/node/v22.2.0/lib/node_modules/artillery/node_modules/async/dist/async.js:1009:25)
- It doesn't seem logging my response or showing useful messages.
from artillery.
I dig into the problem and I found the problem. It doesn't catch it as an error since I use custom API Response which is this.
@Getter
@Builder
public final class APIResponse<T> {
private final HttpStatus status;
private final T data;
private final String message;
}
So i added the debug log in engine_http.js
if (process.env.DEBUG) {
debug("Captured: {}", resForCapture);
}
from artillery.
Related Issues (20)
- Artillery / Fargate: Worker does not receive go signal and waits endlessly HOT 5
- Test hangs when many virtual users fail with ETIMEDOUT
- Artillery API test for 1VU showing incorrect value for 'median' under 'http.response_time' HOT 1
- Custom engine/plugin in private artifactory (run-lambda) HOT 2
- Artillery Cloud - Free Unresponsive on Mac Chrome HOT 4
- [Feature Request] Export of the --output file to S3 when using Artillery with Fargate
- Datadog Metrics are not sent when using Artillery with Fargate HOT 6
- Lambda testing at scale 8 million virtual users HOT 1
- Value is not being captured from JSON. HOT 1
- Getting TestDataSyncFailure some times when running on AWS Lambda HOT 1
- Callback was already called HOT 4
- Playwright Fargate HTTP_PROXY support HOT 1
- Bug: Payloads with `loadAll` and field names include unexpected objects HOT 3
- showAllPageMetrics doesn't work when Target is changed in runtime HOT 2
- requirejs vulnerable to prototype pollution HOT 1
- 'capture' keyword doesn't seem working with 'before' keyword
- Using $ref in YAML files to avoid duplication HOT 1
- loadAll param being ignored when not defined or set to false HOT 3
- Cookie Failed to Parse HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from artillery.