luadao / stress_test_queue.js
vipsphi's picture
Upload 11 files
58461df verified
const axios = require('axios');
const API_KEY = '5db36803-12cb-469b-8919-cc02dc284693'; // Replace with a valid key from your DB if needed
const URL = 'http://localhost:3000/api/solve';
async function sendRequest(id) {
console.log(`[Test] Sending request #${id}...`);
try {
const startTime = Date.now();
const response = await axios.post(URL, {
action: 'test_stress'
}, {
headers: { 'x-api-key': API_KEY }
});
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
console.log(`[Test] Request #${id} finished in ${duration}s. Success: ${response.data.success}`);
} catch (error) {
console.error(`[Test] Request #${id} failed: ${error.response?.data?.error || error.message}`);
}
}
async function runTest() {
console.log("Starting stress test with 5 concurrent requests...");
console.log("Since MAX_CONCURRENT_SOLVES is 2, you should see them being processed 2 at a time.");
const requests = [];
for (let i = 1; i <= 5; i++) {
requests.push(sendRequest(i));
}
await Promise.all(requests);
console.log("Stress test completed.");
}
runTest();