Update: 2026-07-22 00:27:49

This commit is contained in:
Hamza-Ayed
2026-07-22 00:27:50 +03:00
parent 699b380f2b
commit cf95455bcf
5 changed files with 108 additions and 65 deletions
+52 -32
View File
@@ -35,23 +35,23 @@ function debug(msg) {
if (argv.debug) console.log(` [DEBUG] ${msg}`);
}
// Helper to get JWT for mock driver
function getMockDriverJwt(driverId) {
// Helper to get JWT and FP for mock user
function getMockJwt(userId, role = 'driver') {
try {
const output = execSync(`php generate_mock_data.php ${driverId}`, {
const output = execSync(`php generate_mock_data.php ${userId} ${role}`, {
timeout: 5000
}).toString();
debug(`JWT output for driver ${driverId}: ${output.substring(0, 80)}...`);
debug(`JWT output for ${role} ${userId}: ${output.substring(0, 80)}...`);
const jsonString = output.substring(output.indexOf('{'));
const parsed = JSON.parse(jsonString);
if (!parsed.jwt) {
console.error(`[Error] JWT generation returned empty for driver ${driverId}: ${output}`);
return '';
console.error(`[Error] JWT generation returned empty for ${role} ${userId}: ${output}`);
return { jwt: '', fp: '' };
}
return parsed.jwt;
return { jwt: parsed.jwt, fp: parsed.fp || `mock_device_fp_${userId}` };
} catch (err) {
console.error(`[Error] Failed to generate JWT for driver ${driverId}:`, err.message);
return '';
console.error(`[Error] Failed to generate JWT for ${role} ${userId}:`, err.message);
return { jwt: '', fp: '' };
}
}
@@ -67,17 +67,17 @@ let metrics = {
async function simulateTrip(tripIndex) {
const driverId = 900000 + tripIndex;
const passengerId = 800000 + tripIndex;
const driverJwt = getMockDriverJwt(driverId);
const driverAuth = getMockJwt(driverId, 'driver');
const passengerAuth = getMockJwt(passengerId, 'passenger');
if (!driverJwt) {
console.error(`[Trip ${tripIndex}] Skipping — JWT generation failed for driver ${driverId}`);
if (!driverAuth.jwt || !passengerAuth.jwt) {
console.error(`[Trip ${tripIndex}] Skipping — JWT generation failed.`);
metrics.jwtErrors++;
metrics.failed++;
return false;
}
console.log(`[Trip ${tripIndex}] Starting... Driver: ${driverId}, Passenger: ${passengerId}`);
debug(`JWT token (first 30 chars): ${driverJwt.substring(0, 30)}...`);
const tripStartTime = Date.now();
// 1. Connect Driver to Socket
@@ -88,7 +88,7 @@ async function simulateTrip(tripIndex) {
query: {
driver_id: String(driverId),
platform: 'android',
jwt: driverJwt
jwt: driverAuth.jwt
},
reconnection: false,
timeout: 10000,
@@ -108,7 +108,6 @@ async function simulateTrip(tripIndex) {
socket.on('connect_error', (err) => {
console.error(`[Trip ${tripIndex}] ❌ Socket Connection Error: ${err.message}`);
debug(`Full error: ${JSON.stringify(err)}`);
metrics.connectionErrors++;
metrics.failed++;
finish(false);
@@ -145,7 +144,11 @@ async function simulateTrip(tripIndex) {
`${argv.baseUrl}/ride/rides/add_ride.php`,
addRideFormData.toString(),
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${passengerAuth.jwt}`,
'X-Device-FP': passengerAuth.fp
},
timeout: 10000
}
);
@@ -177,7 +180,11 @@ async function simulateTrip(tripIndex) {
`${argv.baseUrl}/ride/rides/acceptRide.php`,
acceptFormData.toString(),
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${driverAuth.jwt}`,
'X-Device-FP': driverAuth.fp
},
timeout: 10000
}
);
@@ -198,7 +205,18 @@ async function simulateTrip(tripIndex) {
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(), { timeout: 10000 });
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}`);
@@ -209,7 +227,18 @@ async function simulateTrip(tripIndex) {
clearInterval(driveInterval);
try {
const finishFormData = new URLSearchParams({ id: String(rideId), driver_id: String(driverId), status: 'finish' });
await axios.post(`${argv.baseUrl}/ride/rides/finish_ride_updates.php`, finishFormData.toString(), { timeout: 10000 });
await axios.post(
`${argv.baseUrl}/ride/rides/finish_ride_updates.php`,
finishFormData.toString(),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${driverAuth.jwt}`,
'X-Device-FP': driverAuth.fp
},
timeout: 10000
}
);
console.log(`[Trip ${tripIndex}] ✅ Finished ride #${rideId}.`);
} catch (e) {
debug(`finish_ride error: ${e.message}`);
@@ -244,7 +273,6 @@ async function simulateTrip(tripIndex) {
}
async function runTest() {
// ── Pre-flight checks ──
console.log(`\n======================================================`);
console.log(`🚀 Siro Stress Test`);
console.log(`======================================================`);
@@ -254,23 +282,18 @@ async function runTest() {
console.log(`🐛 Debug: ${argv.debug ? 'ON' : 'OFF'}`);
console.log(`------------------------------------------------------`);
// Test 1: Can we generate JWT?
console.log(`\n🔑 Pre-flight: Testing JWT generation...`);
const testJwt = getMockDriverJwt(999999);
if (!testJwt) {
console.error(`❌ FATAL: Cannot generate JWT tokens. Check that:\n` +
` - PHP is installed on this server\n` +
` - /home/location/env/.env or backend/.env has JWT_SECRET_KEY\n` +
` - loction_server/vendor/autoload.php exists (run composer install)`);
const testJwt = getMockJwt(999999, 'driver');
if (!testJwt.jwt) {
console.error(`❌ FATAL: Cannot generate JWT tokens.`);
process.exit(1);
}
console.log(` ✅ JWT generation works.`);
// Test 2: Can we reach the socket server?
console.log(`\n🔌 Pre-flight: Testing socket connection...`);
const testResult = await new Promise((resolve) => {
const testSocket = io(argv.socketUrl, {
query: { driver_id: '999999', platform: 'android', jwt: testJwt },
query: { driver_id: '999999', platform: 'android', jwt: testJwt.jwt },
reconnection: false,
timeout: 5000,
forceNew: true
@@ -282,8 +305,6 @@ async function runTest() {
});
testSocket.on('connect_error', (err) => {
console.error(` ❌ Socket connection failed: ${err.message}`);
console.error(` 💡 Make sure the Location Server (driver_socket.php) is running on ${argv.socketUrl}`);
console.error(` 💡 Check with: ps aux | grep driver_socket`);
testSocket.disconnect();
resolve(false);
});
@@ -303,7 +324,6 @@ async function runTest() {
process.exit(1);
}
// ── Run the actual test ──
console.log(`\n------------------------------------------------------`);
console.log(`🏁 Starting ${argv.trips} concurrent trips...\n`);