File size: 1,221 Bytes
58461df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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();