artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
8.06k stars 512 forks source link

Cannot find module when running test on Fargate #2751

Open madhugod opened 6 months ago

madhugod commented 6 months ago

Version info:

Artillery: 2.0.12
Node.js:   v16.19.1
OS:        win32

Running this command:

artillery run-fargate login/login.yml --region eu-west-1 --count 2 --record --key XXX

I expected to see this happen:

I expect the test to be ran successfully.

Instead, this happened:

But the console says:

Run URL: XXXXXXXX
Checking AWS connectivity... [15:42:29]
Checking cluster... [15:42:30]
Tags: name:login.yml [15:42:30]
Test run ID: XXXXXXXXX [15:42:30]
Preparing launch platform... [15:42:30]
Environment:
  Account:     XXXXXXX
  Region:      eu-west-1
  Count:       2
  Cluster:     artilleryio-cluster
  Launch type: ecs:fargate (On-demand)

Preparing test bundle... [15:42:32]
Test bundle prepared... [15:42:32]
Test bundle contents:
┌──────────────┬──────┬───────┐
│ Name         │ Type │ Notes │
├──────────────┼──────┼───────┤
│ login.yml    │ file │       │
├──────────────┼──────┤       │
│ functions.js │ file │       │
└──────────────┴──────┴───────┘

Launching workers... [15:42:33]
Waiting for Fargate... [15:42:34]
Waiting for workers to start: pending: 2 [15:43:06]
Waiting for workers to start: pending: 2 [15:43:16]
Waiting for workers to start: pending: 2 [15:43:26]
Waiting for workers to start: pending: 2 [15:43:36]
Waiting for workers to come online... [15:43:36]
Workers are running, waiting for reports... [15:43:57]
--------------------------------
Summary report @ 15:44:03(+0200)
--------------------------------

No measurements recorded during this period

And in the CloudWatch logs I can see the following error:

"worker error, id: 1 Error: Cannot find module 'bcrypt'"
Require stack:
'"- /artillery/test_data/functions.js"
'"- /artillery/packages/core/lib/runner.js"
'"- /artillery/packages/core/index.js"
'"- /artillery/packages/artillery/lib/artillery-global.js"
'"- /artillery/packages/artillery/lib/platform/local/worker.js"
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/artillery/test_data/functions.js:1:16)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19) {
"  code: 'MODULE_NOT_FOUND',"
  requireStack: [
"    '/artillery/test_data/functions.js',"
"    '/artillery/packages/core/lib/runner.js',"
"    '/artillery/packages/core/index.js',"
"    '/artillery/packages/artillery/lib/artillery-global.js',"
    '/artillery/packages/artillery/lib/platform/local/worker.js'
  ]
}
"cleanup called, signal:"
EXIT

Files being used:

- package.json
- package-lock.json
- login/login.yml
- login/functions.js

Note that bcrypt package is installed (in both package.json, package-lock.json and node_modules)

It is also used (via require keyword) in the function.js file that is referenced in the processor field of the login.yml file

hassy commented 6 months ago

Very odd, looks like the dependencies are not being discovered as expected. Will try to repro here!

madhugod commented 6 months ago

Did some tests again this morning and I believe this has to do with the fact that the yamls are stored in subfolders.

If I move the yml and js file to the root, I can see all files being bundled.

Test bundle contents:
┌─────────────────────┬─────────┬───────┐
│ Name                │ Type    │ Notes │
├─────────────────────┼─────────┼───────┤
│ login.yml           │ file    │       │
├─────────────────────┼─────────┤       │
│ functions.js        │ file    │       │
├─────────────────────┼─────────┤       │
│ package.json        │ file    │       │
├─────────────────────┼─────────┤       │
│ package-lock.json   │ file    │       │
├─────────────────────┼─────────┼───────┤
│ @types/artillery    │ package │       │
├─────────────────────┼─────────┼───────┤
│ @types/bcrypt       │ package │       │
├─────────────────────┼─────────┼───────┤
│ @types/jsonwebtoken │ package │       │
├─────────────────────┼─────────┼───────┤
│ @types/node         │ package │       │
├─────────────────────┼─────────┼───────┤
│ axios               │ package │       │
├─────────────────────┼─────────┼───────┤
│ bcrypt              │ package │       │
├─────────────────────┼─────────┼───────┤
│ jsonwebtoken        │ package │       │

And everything goes as expected.

Note I had another issue when installing packages (error 401) because my package-lock.json files references our own internal npm repository, which the workers don't have access too because missing the NPM_TOKEN, not sure if their is a solution for this yet, but in my case I didn't use any private package so I just removed the package-lock file in order to let the workers download from the public npmjs repository.

bernardobridge commented 5 months ago

@madhugod 👋 Glad you got it working.

Could you let me know what was your original folder structure like (and where you were running the test from, relative to that)? I'm interested in trying to reproduce your original issue.

Note I had another issue when installing packages (error 401) because my package-lock.json files references our own internal npm repository, which the workers don't have access too because missing the NPM_TOKEN, not sure if their is a solution for this yet, but in my case I didn't use any private package so I just removed the package-lock file in order to let the workers download from the public npmjs repository.

We have to document this better, but yes there is a way. It depends what private registry you're using, but it's possible to set some variables that Artillery will pick up to use a private registry. If you end up needing this, let us know!

madhugod commented 5 months ago

Hello @bernardobridge

My original folder structure looks like this (minus node_modules folder):

.
├── login
│   ├── full-funnel.yml
│   ├── functions.js
│   └── login.yml
├── package.json
├── package-lock.json
└── players-data
    ├── bulk.yml
    ├── functions.js
    ├── generateTokens.js
    ├── get.yml
    ├── patch-inventory.yml
    ├── sample-inventory.json
    └── tokens.csv

I was running artillery commands at the root, example:

artillery run-fargate login/login.yml --region eu-west-1 --count 2 --record --key XXX
bernardobridge commented 5 months ago

Thanks @madhugod 🙇 ! Can't reproduce it on Mac, so it could be windows-specific. Will try it out on a windows machine when I have a chance.