mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
loop tests
This commit is contained in:
@@ -2,9 +2,15 @@
|
|||||||
// 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 = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < loopCount; i++) {
|
||||||
|
if (loopCount > 1) {
|
||||||
|
console.log(`\n--- Request ${i + 1} of ${loopCount} ---`);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
@@ -17,7 +23,12 @@ async function testAPI(ip = "ems-esp.local", apiPath = "system") {
|
|||||||
console.log('Status:', response.status);
|
console.log('Status:', response.status);
|
||||||
console.log('Data:', JSON.stringify(response.data, null, 2));
|
console.log('Data:', JSON.stringify(response.data, null, 2));
|
||||||
|
|
||||||
return 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) {
|
} catch (error) {
|
||||||
console.error('Error:', error.message);
|
console.error('Error:', error.message);
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
@@ -28,8 +39,15 @@ async function testAPI(ip = "ems-esp.local", apiPath = "system") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user