Update: 2026-07-22 01:07:41
This commit is contained in:
+47
-29
@@ -205,43 +205,61 @@ async function simulateTrip(tripIndex) {
|
|||||||
);
|
);
|
||||||
console.log(`[Trip ${tripIndex}] Accepted ride #${rideId}. (API: ${Date.now() - acceptStart}ms)`);
|
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;
|
let steps = 0;
|
||||||
|
|
||||||
const driveInterval = setInterval(async () => {
|
const driveInterval = setInterval(async () => {
|
||||||
steps++;
|
steps++;
|
||||||
|
currentLat += 0.0005 + (Math.random() * 0.0005);
|
||||||
|
currentLng += 0.0005 + (Math.random() * 0.0005);
|
||||||
|
|
||||||
socket.emit('update_location', {
|
socket.emit('update_location', {
|
||||||
lat: 31.95 + (steps * 0.001),
|
lat: currentLat,
|
||||||
lng: 35.91 + (steps * 0.001),
|
lng: currentLng,
|
||||||
heading: 90,
|
heading: Math.floor(Math.random() * 360),
|
||||||
speed: 40,
|
speed: 40 + Math.floor(Math.random() * 20),
|
||||||
status: 'on'
|
status: 'on'
|
||||||
});
|
});
|
||||||
|
|
||||||
if (steps === 3) {
|
console.log(`[Trip ${tripIndex}] 📍 Driver GPS update #${steps}: (${currentLat.toFixed(4)}, ${currentLng.toFixed(4)})`);
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (steps === 6) {
|
if (steps >= 4) {
|
||||||
clearInterval(driveInterval);
|
clearInterval(driveInterval);
|
||||||
|
|
||||||
|
// 6. Finish Ride API Call
|
||||||
try {
|
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(
|
await axios.post(
|
||||||
`${argv.baseUrl}/ride/rides/finish_ride_updates.php`,
|
`${argv.baseUrl}/ride/rides/finish_ride_updates.php`,
|
||||||
finishFormData.toString(),
|
finishFormData.toString(),
|
||||||
@@ -254,7 +272,7 @@ async function simulateTrip(tripIndex) {
|
|||||||
timeout: 10000
|
timeout: 10000
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
console.log(`[Trip ${tripIndex}] ✅ Finished ride #${rideId}.`);
|
console.log(`[Trip ${tripIndex}] 🏁 Finished ride #${rideId} successfully.`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debug(`finish_ride error: ${e.message}`);
|
debug(`finish_ride error: ${e.message}`);
|
||||||
}
|
}
|
||||||
@@ -262,7 +280,7 @@ async function simulateTrip(tripIndex) {
|
|||||||
metrics.successful++;
|
metrics.successful++;
|
||||||
finish(true);
|
finish(true);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 500);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[Trip ${tripIndex}] ❌ API Error (acceptRide): ${err.message}`);
|
console.error(`[Trip ${tripIndex}] ❌ API Error (acceptRide): ${err.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user