mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-22 12:58:46 +00:00
test(session): load tests for session api (#9212)
# Which Problems Are Solved We currently are not able to benchmark the performance of the session api # How the Problems Are Solved Load tests were added to - use sessions in oidc tokens analog https://zitadel.com/docs/guides/integrate/login-ui/oidc-standard # Additional Context - Closes https://github.com/zitadel/zitadel/issues/7847
This commit is contained in:
+35
-19
@@ -3,33 +3,23 @@ import { Org } from './org';
|
||||
import http from 'k6/http';
|
||||
import url from './url';
|
||||
import { check } from 'k6';
|
||||
import { User } from './user';
|
||||
|
||||
export type Session = {
|
||||
challenges: any;
|
||||
id: string;
|
||||
token: string;
|
||||
};
|
||||
|
||||
const addSessionTrend = new Trend('session_add_session_duration', true);
|
||||
export function createSession(user: User, org: Org, accessToken: string): Promise<Session> {
|
||||
export function createSession(org: Org, accessToken: string, checks?: any): Promise<Session> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let response = http.asyncRequest(
|
||||
'POST',
|
||||
url('/v2beta/sessions'),
|
||||
JSON.stringify({
|
||||
checks: {
|
||||
user: {
|
||||
userId: user.userId,
|
||||
}
|
||||
}
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'x-zitadel-orgid': org.organizationId,
|
||||
},
|
||||
let response = http.asyncRequest('POST', url('/v2/sessions'), checks ? JSON.stringify({ checks: checks }) : null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'x-zitadel-orgid': org.organizationId,
|
||||
},
|
||||
);
|
||||
});
|
||||
response.then((res) => {
|
||||
check(res, {
|
||||
'add Session status ok': (r) => r.status === 201,
|
||||
@@ -40,3 +30,29 @@ export function createSession(user: User, org: Org, accessToken: string): Promis
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const setSessionTrend = new Trend('session_set_session_duration', true);
|
||||
export function setSession(id: string, session: any, accessToken: string, challenges?: any, checks?: any): Promise<Session> {
|
||||
const body = {
|
||||
sessionToken: session.sessionToken,
|
||||
checks: checks ? checks : null,
|
||||
challenges: challenges ? challenges : null,
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
let response = http.asyncRequest('PATCH', url(`/v2/sessions/${id}`), JSON.stringify(body), {
|
||||
headers: {
|
||||
authorization: `Bearer ${accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
// 'x-zitadel-orgid': org.organizationId,
|
||||
},
|
||||
});
|
||||
response.then((res) => {
|
||||
check(res, {
|
||||
'set Session status ok': (r) => r.status === 200,
|
||||
}) || reject(`unable to set Session status: ${res.status} body: ${res.body}`);
|
||||
|
||||
setSessionTrend.add(res.timings.duration);
|
||||
resolve(res.json() as Session);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user