Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/performance/auth/login.stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 100 },
{ duration: '1m', target: 100 },
{ duration: '30s', target: 600 },
{ duration: '1m', target: 600 },
{ duration: '30s', target: 0 },
],
thresholds: {
Expand Down
44 changes: 44 additions & 0 deletions test/performance/auth/report_login.html

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions test/performance/auth/report_reset-password.html

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions test/performance/auth/reset-password.stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 100 },
{ duration: '1m', target: 100 },
{ duration: '30s', target: 200 },
{ duration: '1m', target: 400 },
{ duration: '30s', target: 0 },
],
thresholds: {
Expand All @@ -18,16 +18,9 @@ export const options = {
},
};

const STRESS_TEST_URL = __ENV.STRESS_TEST_URL || 'http://localhost:3001';

export default function () {
const params = {
headers: {
'Content-Type': 'application/json',
'X-Client-Type': 'web'
},
};
const STRESS_TEST_URL = __ENV.STRESS_TEST_URL || 'https://test.api.raven.cmp27.space';

export function setup() {
const resCreate = http.post(
`${STRESS_TEST_URL}/test/users`,
);
Expand All @@ -39,6 +32,17 @@ export default function () {

const userData = resCreate.json('data');
const userEmail = userData.email;
return { userEmail };
}

export default function (data) {
const { userEmail } = data;
const params = {
headers: {
'Content-Type': 'application/json',
'X-Client-Type': 'web'
},
};

const payloadForgot = JSON.stringify({
identifier: userEmail,
Expand Down
6 changes: 3 additions & 3 deletions test/performance/auth/signup.stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 100 },
{ duration: '1m', target: 100 },
{ duration: '30s', target: 200 },
{ duration: '1m', target: 400 },
{ duration: '30s', target: 0 },
],
thresholds: {
Expand All @@ -22,7 +22,7 @@ export const options = {
},
};

const STRESS_TEST_URL = __ENV.STRESS_TEST_URL || 'http://localhost:3000';
const STRESS_TEST_URL = __ENV.STRESS_TEST_URL || 'https://test.api.raven.cmp27.space';

export default function () {
const uniqueId = `${__VU}-${__ITER}-${Date.now()}`;
Expand Down
192 changes: 192 additions & 0 deletions test/performance/media/media-upload.stress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import http from 'k6/http';
import { check, sleep, group } from 'k6';
import encoding from 'k6/encoding';

export const options = {
stages: [
{ duration: '30s', target: 50 }, // Ramp up to 50 users
{ duration: '1m', target: 100 }, // Ramp up to 100 users
{ duration: '30s', target: 200 }, // Ramp up to 200 users
{ duration: '2m', target: 200 }, // Sustain at 200 users
{ duration: '30s', target: 0 }, // Ramp down
],
thresholds: {
http_req_failed: ['rate<0.05'], // Allow up to 5% failure rate for media uploads (I/O heavy)
'http_req_duration{name:01_Login_Action}': ['p(95)<3000'],
'http_req_duration{name:02_Upload_Image}': ['p(95)<10000'], // Image uploads can take longer
'http_req_duration{name:03_Upload_Video}': ['p(95)<15000'], // Video uploads can take longer
'http_req_duration{name:04_Upload_Gif}': ['p(95)<5000'], // GIF (Tenor lookup) should be faster
},
};

const STRESS_TEST_URL = __ENV.STRESS_TEST_URL || 'http://localhost:3000';

// Minimal valid PNG file (1x1 red pixel) - properly encoded
const MINIMAL_PNG_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADklEQVQI12P4z8DwHwAFAAH/q842AAAAAElFTkSuQmCC';

// Minimal valid MP4 bytes - ftyp box only (smallest valid MP4 structure)
// We'll create this as raw bytes array instead of base64 to avoid encoding issues
function createMinimalMP4Bytes() {
// Minimal ftyp box: box size (4) + box type (4) + brand (4) + version (4)
const bytes = new Uint8Array([
0x00, 0x00, 0x00, 0x14, // box size: 20 bytes
0x66, 0x74, 0x79, 0x70, // box type: 'ftyp'
0x69, 0x73, 0x6F, 0x6D, // brand: 'isom'
0x00, 0x00, 0x00, 0x01, // version: 1
0x69, 0x73, 0x6F, 0x6D, // compatible brand: 'isom'
]);
return bytes.buffer; // Return ArrayBuffer, not Uint8Array
}

/**
* Helper function to create and login a user
* Returns { accessToken } or null on failure
*/
function createAndLoginUser(tagName) {
const resCreateUser = http.post(`${STRESS_TEST_URL}/test/users`);

if (!check(resCreateUser, { 'User Created 201': (r) => r.status === 201 })) {
console.error(`Setup Failed (Create User): ${resCreateUser.body}`);
return null;
}

const userData = resCreateUser.json('data');
const userEmail = userData.email;
const userPassword = userData.password;

const loginPayload = JSON.stringify({
identifier: userEmail,
password: userPassword,
});

const loginParams = {
headers: {
'Content-Type': 'application/json',
'X-Client-Type': 'web',
},
tags: { name: tagName },
};

const resLogin = http.post(`${STRESS_TEST_URL}/auth/login`, loginPayload, loginParams);

if (!check(resLogin, { 'Login 200': (r) => r.status === 200 })) {
console.error(`Setup Failed (Login): ${resLogin.body}`);
return null;
}

return {
accessToken: resLogin.json('data.accessToken'),
};
}

export default function () {
// ─────────────────────────────────────────────────────────────────────────────
// SETUP: Create and login user
// ─────────────────────────────────────────────────────────────────────────────
const user = createAndLoginUser('01_Login_Action');
if (!user) return;

const authHeaders = {
'X-Client-Type': 'web',
Authorization: `Bearer ${user.accessToken}`,
};

sleep(0.2);

// ─────────────────────────────────────────────────────────────────────────────
// STEP 1: Upload Image (POST /media/upload/image)
// ─────────────────────────────────────────────────────────────────────────────
group('Image Upload', function () {
const imageBytes = encoding.b64decode(MINIMAL_PNG_BASE64);

const formData = {
file: http.file(imageBytes, `test-image-${__VU}-${__ITER}.png`, 'image/png'),
folder: 'tweets',
};

const resUploadImage = http.post(
`${STRESS_TEST_URL}/media/upload/image`,
formData,
{
headers: authHeaders,
tags: { name: '02_Upload_Image' },
}
);

const imageUploadOk = check(resUploadImage, {
'Upload Image 2xx': (r) => r.status >= 200 && r.status < 300,
});

if (!imageUploadOk) {
console.error(`Upload Image Failed [VU:${__VU}]: ${resUploadImage.status} - ${resUploadImage.body}`);
}
});

sleep(0.3);

// ─────────────────────────────────────────────────────────────────────────────
// STEP 2: Upload Video (POST /media/upload/video)
// ─────────────────────────────────────────────────────────────────────────────
group('Video Upload', function () {
const videoBytes = createMinimalMP4Bytes();

const formData = {
file: http.file(videoBytes, `test-video-${__VU}-${__ITER}.mp4`, 'video/mp4'),
folder: 'tweets',
};

const resUploadVideo = http.post(
`${STRESS_TEST_URL}/media/upload/video`,
formData,
{
headers: authHeaders,
tags: { name: '03_Upload_Video' },
}
);

const videoUploadOk = check(resUploadVideo, {
'Upload Video 2xx': (r) => r.status >= 200 && r.status < 300,
});

if (!videoUploadOk) {
console.error(`Upload Video Failed [VU:${__VU}]: ${resUploadVideo.status} - ${resUploadVideo.body}`);
}
});

sleep(0.3);

// ─────────────────────────────────────────────────────────────────────────────
// STEP 3: Upload GIF via Tenor ID (POST /media/upload/gif)
// ─────────────────────────────────────────────────────────────────────────────
group('GIF Upload', function () {
// Note: This requires a valid Tenor GIF ID
// Using a commonly available GIF ID - may need to be updated if Tenor API changes
const tenorId = '16989471141791455574';

const gifPayload = JSON.stringify({
tenorId: tenorId,
});

const resUploadGif = http.post(
`${STRESS_TEST_URL}/media/upload/gif`,
gifPayload,
{
headers: {
...authHeaders,
'Content-Type': 'application/json',
},
tags: { name: '04_Upload_Gif' },
}
);

const gifUploadOk = check(resUploadGif, {
'Upload GIF 2xx': (r) => r.status >= 200 && r.status < 300,
});

if (!gifUploadOk) {
console.error(`Upload GIF Failed [VU:${__VU}]: ${resUploadGif.status} - ${resUploadGif.body}`);
}
});

sleep(0.2);
}
44 changes: 44 additions & 0 deletions test/performance/media/report.html

Large diffs are not rendered by default.

Loading
Loading