Files
anubis-mirror/test/log-file/test.mjs
Xe Iaso bf5d66222c chore: set up commitlint, husky, and prettier (#1451)
* chore: add prettier configuration

Signed-off-by: Xe Iaso <me@xeiaso.net>

* format: run prettier tree-wide

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore(prettier): ignore intentionally ungrammatical files

Signed-off-by: Xe Iaso <me@xeiaso.net>

* ci: add PR title lint rule

Signed-off-by: Xe Iaso <me@xeiaso.net>

* ci: add DCO check

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore: add commitlint and husky

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore: add CONTRIBUTING guidelines

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore: set SKIP_INTEGRATION in precommit tests

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore: update spelling

Signed-off-by: Xe Iaso <me@xeiaso.net>

* ci(dco): remove reopened trigger

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore: remove dead file

Signed-off-by: Xe Iaso <me@xeiaso.net>

* chore(prettier): don't format nginx includes

Signed-off-by: Xe Iaso <me@xeiaso.net>

---------

Signed-off-by: Xe Iaso <me@xeiaso.net>
2026-02-15 08:19:12 -05:00

95 lines
2.2 KiB
JavaScript

import { statSync } from "fs";
async function getPage(path) {
return fetch(`http://localhost:8923${path}`, {
headers: {
"User-Agent": "CHALLENGE",
},
})
.then((resp) => {
if (resp.status !== 200) {
throw new Error(`wanted status 200, got status: ${resp.status}`);
}
return resp;
})
.then((resp) => resp.text());
}
async function getFileSize(filePath) {
try {
return statSync(filePath).size;
} catch (error) {
return 0;
}
}
(async () => {
const logFilePath = "./var/anubis.log";
// Get initial log file size
const initialSize = await getFileSize(logFilePath);
console.log(`Initial log file size: ${initialSize} bytes`);
// Make 35 requests with different paths
const requests = [];
for (let i = 0; i < 35; i++) {
requests.push(`/test${i}`);
}
const resultSheet = {};
let failed = false;
for (const path of requests) {
try {
const resp = await getPage(path);
resultSheet[path] = {
success: true,
line: resp.split("\n")[0],
};
} catch (error) {
resultSheet[path] = {
success: false,
error: error.message,
};
console.log(`✗ Request to ${path} failed: ${error.message}`);
failed = true;
}
}
// Check final log file size
const finalSize = await getFileSize(logFilePath);
console.log(`Final log file size: ${finalSize} bytes`);
console.log(`Size increase: ${finalSize - initialSize} bytes`);
// Verify that log file size increased
if (finalSize <= initialSize) {
console.error(
"ERROR: Log file size did not increase after making requests!",
);
failed = true;
}
let successCount = 0;
for (let [k, v] of Object.entries(resultSheet)) {
if (!v.success) {
console.error({ path: k, error: v.error });
} else {
successCount++;
}
}
console.log(`Successful requests: ${successCount}/${requests.length}`);
if (failed) {
console.error(
"Test failed: Some requests failed or log file size did not increase",
);
process.exit(1);
} else {
console.log(
"Test passed: All requests succeeded and log file size increased",
);
process.exit(0);
}
})();