Skip to content

Commit

Permalink
test: add e2e tests (#504)
Browse files Browse the repository at this point in the history
* feat: move from fake ip vars to test types vars

* feat: add mock e2e scripts

* feat: add mocha setup

* feat: run probe container from e2e setup

* ci: trigger e2e

* feat: wait until probe connects

* feat: add failing usage of matchApiSchema

* fix: matchApiSchema method

* fix: mocha throwing ERROR: null in case of ts compilation error

* feat: add util parser

* feat: change runner

* feat: use got response in mocha plugin

* test: add measurement e2e tests

* feat: add e2e wallaby configuration

* feat: move e2e .mocharc

* feat: add e2e folder to tsconfig

* feat: add e2e cases for all measurement types

* fix: http schema

* refactor: move files

* feat: add locations e2e

* fix: add missing nulls to schema

* test: add offline probes tests

* test: add adopted probes tests e2e

* fix: e2e mocharc

* fix: tests order

* feat: run api as docker container

* fix: run api on port 3000

* fix: local run

* refactor: docker manager

* fix: e2e wallaby

* fix: schema hostname format

* fix: remove unused env var

* fix: add missing awaits

* fix: remove manual json.parse

* fix: log measurement status

* feat: disable rtt null

* fix: add wait for disconnect

* ci: trigger

* fix: retrun rtt null back

* refactor: move e2e to test folder

* fix: use db urls from config

* fix: build probe image from github master

* fix: get rtt schema back
  • Loading branch information
alexey-yarmosh authored and MartinKolarik committed Mar 18, 2024
1 parent 2276507 commit 24adbc4
Show file tree
Hide file tree
Showing 30 changed files with 958 additions and 31 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: self-hosted

env:
NODE_ENV: test
Expand Down Expand Up @@ -48,11 +48,14 @@ jobs:
run: |
npm ci
npm run build
- name: Test
- name: Test Unit
run: |
npm run lint
npm run coverage
npm run test:portman
- name: Test E2E
run: |
npm run test:e2e
- name: Test Dist
run: |
rm -rf node_modules
Expand Down
42 changes: 42 additions & 0 deletions .mocharc.e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"exit": true,
"timeout": 20000,
"check-leaks": true,
"file": [
"test/tests/e2e/setup-api.ts",
"test/tests/e2e/setup-probe.ts"
],
"spec": [
"test/tests/e2e/**/*.test.ts"
],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"globals": [
"__extends",
"__assign",
"__rest",
"__decorate",
"__param",
"__metadata",
"__awaiter",
"__generator",
"__exportStar",
"__createBinding",
"__values",
"__read",
"__spread",
"__spreadArrays",
"__spreadArray",
"__await",
"__asyncGenerator",
"__asyncDelegator",
"__asyncValues",
"__makeTemplateObject",
"__importStar",
"__importDefault",
"__classPrivateFieldGet",
"__classPrivateFieldSet"
]
}
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"test/setup.ts"
],
"spec": [
"test/**/*.test.ts"
"test/tests/integration/**/*.test.ts",
"test/tests/unit/**/*.test.ts"
],
"node-option": [
"experimental-specifier-resolution=node",
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Once the API is live, you can spin up a probe instance by running as described a

### Environment variables
- `PORT=3000` environment variable can start the API on another port (default is 3000)
- `FAKE_PROBE_IP=api` environment variable can be used to make debug easier. When defined, every Probe
- `FAKE_PROBE_IP=1` environment variable can be used to make debug easier. When defined, every Probe
that connects to the API will get an IP address from the list of predefined "real" addresses.

### Testing
Expand All @@ -43,7 +43,7 @@ Most IDEs have plugins integrating the used linter (eslint), including support f
- `NEW_RELIC_LICENSE_KEY={value}` used in production to send APM metrics to new relic
- `NEW_RELIC_APP_NAME={value}` used in production to send APM mentrics to new relic
- `NEW_RELIC_ENABLED=false` used in development to disable newrelic monitoring
- `FAKE_PROBE_IP={api|probe}` used in development to either use a random fake ip from the API or a fake ip from Probe
- `FAKE_PROBE_IP=1` used in development to use a random fake ip assigned by the API
- `ADMIN_KEY={value}` used to access additional information over the API
- `SYSTEM_API_KEY={value}` used for integration with the dashboard
- `DB_CONNECTION_HOST`, `DB_CONNECTION_USER`, `DB_CONNECTION_PASSWORD`, and `DB_CONNECTION_DATABASE` database connection details
12 changes: 6 additions & 6 deletions docs/staging-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exit

## API

Runs 2 API instances on ports 3001 and 3002 behind the haproxy on port 80. Geoip client is mocked so all probes get same location. `FAKE_PROBE_IP=probe` makes API to use fake ip provided by the probe.
Runs 2 API instances on ports 3001 and 3002 behind the haproxy on port 80. Geoip client is mocked so all probes get same location. `TEST_MODE=perf` makes API to use fake ip provided by the probe.

```bash
# Update that variables before start
Expand Down Expand Up @@ -79,20 +79,20 @@ npm run build

# Run the app
echo 'Run 2 app instances using:
PORT=3001 HOSTNAME=3001 REDIS_URL=redis://default:$REDIS_PASSWORD@$REDIS_HOST:6379 NODE_ENV=production ADMIN_KEY=admin FAKE_PROBE_IP=probe NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false node dist/index.js
PORT=3001 HOSTNAME=3001 REDIS_URL=redis://default:$REDIS_PASSWORD@$REDIS_HOST:6379 NODE_ENV=production ADMIN_KEY=admin TEST_MODE=perf NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false node dist/index.js
and
PORT=3002 HOSTNAME=3002 REDIS_URL=redis://default:$REDIS_PASSWORD@$REDIS_HOST:6379 NODE_ENV=production ADMIN_KEY=admin FAKE_PROBE_IP=probe NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false node dist/index.js
PORT=3002 HOSTNAME=3002 REDIS_URL=redis://default:$REDIS_PASSWORD@$REDIS_HOST:6379 NODE_ENV=production ADMIN_KEY=admin TEST_MODE=perf NEW_RELIC_ENABLED=false NEW_RELIC_LOG_ENABLED=false node dist/index.js
'
```

## Probe

Runs `PROBES_COUNT` number of probe processes. They all get a random fake ip which is passed to the API. Value of the `FAKE_PROBE_IP` is the first octet of the fake ip. Each probe process requires ~40mb of RAM.
Runs `PROBES_COUNT` number of probe processes. They all get a random fake ip which is passed to the API. Value of the `FAKE_IP_FIRST_OCTET` is the first octet of the fake ip. Each probe process requires ~40mb of RAM.

```bash
# Update that variables before start
API_HOST=<your_value>
FAKE_PROBE_IP=1
FAKE_IP_FIRST_OCTET=1
PROBES_COUNT=300

# Install node
Expand Down Expand Up @@ -124,6 +124,6 @@ sudo dpkg --extract "/tmp/expect.deb" /
# Auto start the probes
sudo npm i -g pm2
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
FAKE_PROBE_IP=$FAKE_PROBE_IP NODE_ENV=development PROBES_COUNT=$PROBES_COUNT API_HOST=ws://$API_HOST pm2 start dist/index.js
FAKE_IP_FIRST_OCTET=$FAKE_IP_FIRST_OCTET NODE_ENV=development PROBES_COUNT=$PROBES_COUNT API_HOST=ws://$API_HOST pm2 start dist/index.js
pm2 save
```
149 changes: 149 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 24adbc4

Please sign in to comment.