From 26d0ec2982277b04e2c1b5fcaad084698a4ce2b0 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Wed, 22 Jul 2026 01:07:41 +0300 Subject: [PATCH] Update: 2026-07-22 01:07:41 --- stress_test/load_test.js | 76 +++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/stress_test/load_test.js b/stress_test/load_test.js index 52cd6d7e..37b3062a 100644 --- a/stress_test/load_test.js +++ b/stress_test/load_test.js @@ -205,43 +205,61 @@ async function simulateTrip(tripIndex) { ); console.log(`[Trip ${tripIndex}] Accepted ride #${rideId}. (API: ${Date.now() - acceptStart}ms)`); - // 4. Simulate Driving (Updates Location) + // 4. Start Ride API Call + try { + const startFormData = new URLSearchParams({ id: String(rideId), driver_id: String(driverId), status: 'Begin' }); + await axios.post( + `${argv.baseUrl}/ride/rides/start_ride.php`, + startFormData.toString(), + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Authorization': `Bearer ${driverAuth.jwt}`, + 'X-Device-FP': driverAuth.fp + }, + timeout: 10000 + } + ); + console.log(`[Trip ${tripIndex}] 🚗 Started ride #${rideId}`); + } catch (e) { + debug(`start_ride error: ${e.message}`); + } + + // 5. Simulate Driving (4 Random GPS Location Updates) + let currentLat = 31.95; + let currentLng = 35.91; let steps = 0; + const driveInterval = setInterval(async () => { steps++; + currentLat += 0.0005 + (Math.random() * 0.0005); + currentLng += 0.0005 + (Math.random() * 0.0005); + socket.emit('update_location', { - lat: 31.95 + (steps * 0.001), - lng: 35.91 + (steps * 0.001), - heading: 90, - speed: 40, + lat: currentLat, + lng: currentLng, + heading: Math.floor(Math.random() * 360), + speed: 40 + Math.floor(Math.random() * 20), status: 'on' }); - if (steps === 3) { - try { - const startFormData = new URLSearchParams({ id: String(rideId), driver_id: String(driverId), status: 'start' }); - await axios.post( - `${argv.baseUrl}/ride/rides/start_ride.php`, - startFormData.toString(), - { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Authorization': `Bearer ${driverAuth.jwt}`, - 'X-Device-FP': driverAuth.fp - }, - timeout: 10000 - } - ); - console.log(`[Trip ${tripIndex}] Started ride #${rideId}`); - } catch (e) { - debug(`start_ride error: ${e.message}`); - } - } + console.log(`[Trip ${tripIndex}] 📍 Driver GPS update #${steps}: (${currentLat.toFixed(4)}, ${currentLng.toFixed(4)})`); - if (steps === 6) { + if (steps >= 4) { clearInterval(driveInterval); + + // 6. Finish Ride API Call try { - const finishFormData = new URLSearchParams({ id: String(rideId), driver_id: String(driverId), status: 'finish' }); + const finishFormData = new URLSearchParams({ + rideId: String(rideId), + driver_id: String(driverId), + passengerId: String(passengerId), + status: 'Finished', + actualDistance: '2.5', + actualDuration: '10', + country_code: 'Jordan' + }); + await axios.post( `${argv.baseUrl}/ride/rides/finish_ride_updates.php`, finishFormData.toString(), @@ -254,7 +272,7 @@ async function simulateTrip(tripIndex) { timeout: 10000 } ); - console.log(`[Trip ${tripIndex}] ✅ Finished ride #${rideId}.`); + console.log(`[Trip ${tripIndex}] 🏁 Finished ride #${rideId} successfully.`); } catch (e) { debug(`finish_ride error: ${e.message}`); } @@ -262,7 +280,7 @@ async function simulateTrip(tripIndex) { metrics.successful++; finish(true); } - }, 1000); + }, 500); } catch (err) { console.error(`[Trip ${tripIndex}] ❌ API Error (acceptRide): ${err.message}`);