Skip to content

Commit

Permalink
load tests authenticated (#1201)
Browse files Browse the repository at this point in the history
* Introduce authenticated load-tests

* wip

* wip

* wip

* Add homepage requests

* wip

* wip
  • Loading branch information
ofux committed Oct 11, 2024
1 parent 89b2f5e commit e4150fd
Show file tree
Hide file tree
Showing 5 changed files with 5,862 additions and 0 deletions.
21 changes: 21 additions & 0 deletions load-tests/k6/anonymous-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Run with: K6_WEB_DASHBOARD=true K6_WEB_DASHBOARD_EXPORT=html-report.html k6 run load-tests/k6/anonymous-users.js

import http from 'k6/http';

export const options = {
scenarios: {
display_homepage: {
executor: 'per-vu-iterations',
vus: 20,
iterations: 100,
startTime: '5s',
},
},
};

const BASE_URL = 'https://develop-api.onlydust.com/api/v1';

export default function () {
http.get(`${BASE_URL}/projects`);
http.get(`${BASE_URL}/public-activity?pageIndex=0&pageSize=10`);
}
133 changes: 133 additions & 0 deletions load-tests/k6/authenticated-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Run with: K6_WEB_DASHBOARD=true K6_WEB_DASHBOARD_EXPORT=html-report.html k6 run load-tests/k6/authenticated-users.js
// For datadog: K6_STATSD_ENABLE_TAGS=true k6 run --tag test_run_id=1 --out output-statsd load-tests/k6/authenticated-users.js

import {check, sleep} from 'k6';
import http from 'k6/http';
import exec from 'k6/execution';
import {userIds as userIdsDevelop} from "./users/develop.js";
import {userIds as userIdsStaging} from "./users/staging.js";
import {userIds as userIdsProduction} from "./users/production.js";

export const options = {
scenarios: {
odhack: {
executor: 'ramping-vus',
startVUs: 1,
stages: [
{duration: '120s', target: 5000},
{duration: '30s', target: 0},
],
gracefulRampDown: '0s',
},
},
};

const ENV = 'perf';
const BASE_URL = `https://${ENV}-api.onlydust.com/api/v1`;//'http://localhost:9999/api/v1';
const ACCESS_TOKEN = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InlvcHBLQzlTTFptT1pBbXhtV2J6NiJ9.eyJpc3MiOiJodHRwczovL3Byb2R1Y3Rpb24tb25seWR1c3QuZXUuYXV0aDAuY29tLyIsInN1YiI6ImdpdGh1Ynw1OTU1MDUiLCJhdWQiOlsiaHR0cHM6Ly9hcGkub25seWR1c3QuY29tL2FwaSIsImh0dHBzOi8vcHJvZHVjdGlvbi1vbmx5ZHVzdC5ldS5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNzI4NDkzMTk4LCJleHAiOjE3Mjg0OTQzOTgsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwgb2ZmbGluZV9hY2Nlc3MiLCJhenAiOiJ2TkxwYU1EQU1RZVIwZHJhdkxreHdZdlZpVGRXYzZUSSJ9.Qaoh2wS8cFCzb86QVqmXe3_6zPR3oxYV6XXpD2jD8rSEqPd8jyLf0Xa6zKaTsV7WOfoHPrFAmIWu6bY33EL9gcOJUIBtYrFi6L5ekigJLkTlzv-V7wWvWSSFGqXkmKGopwIgxhmbsfFyrFjWUuqNlTeSjiyjBl78sz3a5E2klafvrldZBCMpC2GiWx1Zy-jonHEoCUVmCf0dIrptEHEVgZJJEWc1TxFn4zvc69Gu0ragE9ekpzBqwpDMCCLrMQeIyWKcUtXTChrxL1IRpk_GSkrFSoDF9ir0tNMUZQ1WU_GI4Rn__z_toyN8VYuP4ObaaE9B7tySdw5bnul4W_YfSw';
const HACKATHON_SLUG = 'odhack-80';


function userIds() {
return ENV === 'perf' ? userIdsProduction : ENV === 'staging' ? userIdsStaging : userIdsDevelop;
}

function userId() {
return userIds()[exec.vu.idInTest % userIds().length];
}

function idle(min, max) {
sleep(Math.random() * (max - min) + min);
}


export default function () {
const params = {
headers: {
'Authorization': `Bearer ${ACCESS_TOKEN}`,
'X-Impersonation-Claims': `{"sub":"github|${userId()}"}`,
'Content-Type': 'application/json',
},
};

console.debug(`User ${userId()} started`);
notificationRequests(params);
//http.get(`${BASE_URL}/me/recommended-projects`, params);
sleep(5);
// globalRequests(params);
// homeRequests(params);
//
// idle(3, 10);
// globalRequests(params);
// hackathonsRequests(params);
}

function globalRequests(params) {
http.get(`${BASE_URL}/me/billing-profiles`, params);
console.debug(`User ${userId()} first global requests done`);
http.get(`${BASE_URL}/me/profile`, params);
http.get(`${BASE_URL}/me/onboarding`, params);
http.get(`${BASE_URL}/banner?hiddenIgnoredByMe=true`, params);
notificationRequests(params);
}

function notificationRequests(params) {
http.get(`${BASE_URL}/me/notifications/count?status=UNREAD`, params);
}

function homeRequests(params) {
http.get(`${BASE_URL}/me/rewards`, params);
http.get(`${BASE_URL}/me/projects`, params);
http.get(`${BASE_URL}/me/recommended-projects`, params);
http.get(`${BASE_URL}/projects`, params);
http.get(`${BASE_URL}/public-activity`, params);
console.debug('Home requests done');
}

function hackathonsRequests(params) {
http.get(`${BASE_URL}/hackathons`, params);
idle(1, 10);

const hackathon = http.get(`${BASE_URL}/hackathons/slug/${HACKATHON_SLUG}`, params);
const hackathonId = hackathon.json().id;
console.debug(`Selected hackathon: ${HACKATHON_SLUG} (id: ${hackathonId})`);
registerToHackathon(hackathonId, params);
hackathonRequests(hackathonId, params);
}

function registerToHackathon(hackathonId, params) {
idle(10, 15);
const profilePatchRes = http.patch(`${BASE_URL}/me/profile`, JSON.stringify({
"contacts": [
{
"channel": "TELEGRAM",
"contact": "t.me/foo",
"visibility": "public"
}
]
}), params);
check(profilePatchRes, {
'successfully patched profile': (r) => r.status === 204,
});

const res = http.put(`${BASE_URL}/me/hackathons/${hackathonId}/registrations`, null, params);
check(res, {
'successfully registered to hackathon': (r) => r.status === 204,
});
console.debug(`User ${userId()} registered to hackathon ${hackathonId}`);
}

function hackathonRequests(hackathonId, params) {
const hackathonProjectIssues = http.get(`${BASE_URL}/hackathons/${hackathonId}/project-issues?statuses=OPEN`, params);
const projectIds = hackathonProjectIssues.json().projects.map(p => p.project.id);
console.debug(`Hackathon projects: ${projectIds}`);
projectIds.forEach(projectId => hackathonProjectsRequests(hackathonId, projectId, params));
}

function hackathonProjectsRequests(hackathonId, projectId, params) {
idle(10, 20);
const res = http.get(`${BASE_URL}/projects/${projectId}/public-issues?statuses=OPEN&hackathonId=${hackathonId}`, params);
const projectIssueCount = res.json().totalItemNumber;
console.debug(`Fetched ${projectIssueCount} issues from project ${projectId}`);
notificationRequests(params);
}
43 changes: 43 additions & 0 deletions load-tests/k6/users/develop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const userIds = [
"07c86607-e94d-409c-8214-f67c7ffb9067",
"0d29b7bd-9514-4a03-ad14-99bbcbef4733",
"1ad3bf8d-b76a-4e26-951d-4c2905f21228",
"1df5b5a4-2ee0-481f-8b88-3dd591247623",
"1fba47bf-3528-45d9-ba74-1dd337073e16",
"2ef2674e-69fe-4251-877f-b6d8efc0c5da",
"3d2fed77-0fc4-40c1-9bd9-3ad273be8063",
"44e078b7-d095-49f2-a7b3-647149337dc5",
"45e98bf6-25c2-4edf-94da-e340daba8964",
"46fec596-7a91-422e-8532-5f479e790217",
"4c392643-6d88-400b-a51a-a6e7cad45844",
"4fefe583-ccec-4734-a2c2-90434d3bae55",
"500af662-1ce0-4b57-aafc-b9487ef08c50",
"6115f024-159a-4b1f-b713-1e2ad5c6063e",
"6a99fd92-3243-4193-bce9-6a1047cd6590",
"6aee4803-2be0-49a4-84c8-3878ad9e5dbe",
"6e68f92c-9adb-4b57-92d0-550fbd39efba",
"6ea59e8d-c612-4625-b329-3824218db737",
"705e134d-e9e3-4ea3-85e2-a59a9628ecfc",
"743e096e-c922-4097-9e6f-8ea503055336",
"747e663f-4e68-4b42-965b-b5aebedcd4c4",
"8243910f-863e-4b00-8e9b-7e0f08a07610",
"83612081-949a-47c4-a467-6f28f6adad6d",
"844e61e9-f96e-4ea5-9fae-ecc6a63d3dde",
"987bf960-bbae-4a1b-9b70-928df48a3a94",
"9a779f53-5762-4110-94b8-5596bbbd74ec",
"a0da3c1e-6493-4ea1-8bd0-8c46d653f274",
"bdc705b5-cf8e-488f-926a-258e1800ed79",
"c69f41be-c364-482f-91ae-5e55e3ea719b",
"c8d76bf1-d711-4297-b46c-ab97f2c42b3b",
"c9acd14f-4985-467e-b44d-0bcedbf8f4f4",
"cce1dd16-ba22-4aef-8828-221ab41fd982",
"cde93e0e-99cf-4722-8aaa-2c27b91e270d",
"dd0ab03c-5875-424b-96db-a35522eab365",
"e461c019-ba23-4671-9b6c-3a5a18748af9",
"eaa1ddf3-fea5-4cef-825b-336f8e775e05",
"f171edf6-b32b-4a38-975a-4fc591decdd8",
"f20e6812-8de8-432b-9c31-2920434fe7d0",
"f2215429-83c7-49ce-954b-66ed453c3315",
"f4af340d-6923-453c-bffe-2f1ce1880ff4",
"fc92397c-3431-4a84-8054-845376b630a0",
];
Loading

0 comments on commit e4150fd

Please sign in to comment.