Merge pull request #2775 from proddy/dev

loop tests
This commit is contained in:
Proddy
2025-11-30 17:24:56 +01:00
committed by GitHub

View File

@@ -2,34 +2,52 @@
// node api_test.js // node api_test.js
const axios = require('axios'); const axios = require('axios');
async function testAPI(ip = "ems-esp.local", apiPath = "system") { async function testAPI(ip = "ems-esp.local", apiPath = "system", loopCount = 1, delayMs = 1000) {
const baseUrl = `http://${ip}/api`; const baseUrl = `http://${ip}/api`;
const url = `${baseUrl}/${apiPath}`; const url = `${baseUrl}/${apiPath}`;
const results = [];
try { for (let i = 0; i < loopCount; i++) {
const response = await axios.get(url, { if (loopCount > 1) {
timeout: 5000, console.log(`\n--- Request ${i + 1} of ${loopCount} ---`);
headers: { }
'Content-Type': 'application/json'
} try {
}); const response = await axios.get(url, {
timeout: 5000,
console.log('Status:', response.status); headers: {
console.log('Data:', JSON.stringify(response.data, null, 2)); 'Content-Type': 'application/json'
}
return response.data; });
} catch (error) {
console.error('Error:', error.message); console.log('Status:', response.status);
if (error.response) { console.log('Data:', JSON.stringify(response.data, null, 2));
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data); results.push(response.data);
// Delay before next request (except for the last one)
if (i < loopCount - 1) {
await new Promise(resolve => setTimeout(resolve, delayMs));
}
} catch (error) {
console.error('Error:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
throw error;
} }
throw error;
} }
return loopCount === 1 ? results[0] : results;
} }
// Run the test // Run the test
testAPI("192.168.1.65", "system") // Examples:
// testAPI("192.168.1.65", "system") - single call
// testAPI("192.168.1.65", "system", 5) - 5 calls with 1000ms delay
// testAPI("192.168.1.65", "system", 10, 2000) - 10 calls with 2000ms delay
testAPI("192.168.1.65", "system", 1000)
.then(() => { .then(() => {
console.log('Test completed successfully'); console.log('Test completed successfully');
process.exit(0); process.exit(0);