Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve e2e tests #443

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions end2end/getFreePort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { randomInt } = require("crypto");
const used = [];

module.exports = function getFreePort(t) {
const port = randomInt(3000, 10000) + t.childId;

if (used.includes(port)) {
return getFreePort(t);
}

used.push(port);

return port;
};
170 changes: 169 additions & 1 deletion end2end/package-lock.json

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

5 changes: 3 additions & 2 deletions end2end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"private": true,
"dependencies": {
"@supercharge/promise-pool": "^3.1.1",
"tap": "^18.7.0"
"tap": "^18.7.0",
"wait-on": "^8.0.1"
},
"scripts": {
"test": "AIKIDO_CI=true tap tests/*.js --allow-empty-coverage -j 1"
"test": "AIKIDO_CI=true tap tests/*.js --allow-empty-coverage"
}
}
2 changes: 1 addition & 1 deletion end2end/server/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is a insecure mock server for testing purposes
// This is an insecure mock server for testing purposes
const express = require("express");
const config = require("./src/handlers/getConfig");
const captureEvent = require("./src/handlers/captureEvent");
Expand Down
14 changes: 8 additions & 6 deletions end2end/tests/big-payloads.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const t = require("tap");
const { spawn } = require("child_process");
const { resolve } = require("path");
const timeout = require("../timeout");
const waitOn = require("../waitOn");
const getFreePort = require("../getFreePort");
const { PromisePool } = require("@supercharge/promise-pool");

const pathToApp = resolve(
Expand All @@ -11,7 +12,8 @@ const pathToApp = resolve(
);

t.test("it does not crash if many attacks with big payloads", (t) => {
const server = spawn(`node`, ["--preserve-symlinks", pathToApp, "4000"], {
const port = getFreePort(t);
const server = spawn(`node`, ["--preserve-symlinks", pathToApp, port], {
env: { ...process.env, AIKIDO_DEBUG: "true", AIKIDO_BLOCKING: "true" },
});

Expand All @@ -20,7 +22,7 @@ t.test("it does not crash if many attacks with big payloads", (t) => {
});

server.on("error", (err) => {
t.fail(err.message);
t.fail(err);
});

let stdout = "";
Expand All @@ -36,7 +38,7 @@ t.test("it does not crash if many attacks with big payloads", (t) => {
const amount = 2000;

// Wait for the server to start
timeout(2000)
waitOn(port)
.then(() => {
return PromisePool.withConcurrency(3)
.for(Array.from({ length: amount }))
Expand All @@ -49,7 +51,7 @@ t.test("it does not crash if many attacks with big payloads", (t) => {
})),
};

return await fetch(`http://localhost:4000/search`, {
return await fetch(`http://localhost:${port}/search`, {
method: "POST",
signal: AbortSignal.timeout(5000),
body: JSON.stringify(filter),
Expand All @@ -64,7 +66,7 @@ t.test("it does not crash if many attacks with big payloads", (t) => {
);
})
.catch((error) => {
t.fail(error.message);
t.fail(error);
})
.finally(() => {
server.kill();
Expand Down
Loading
Loading