mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-12 17:15:15 +00:00
test: add load test for session creation (#8088)
# Which Problems Are Solved Extends load tests by testing session creation. # How the Problems Are Solved The test creates a session including a check for user id. # Additional Context - part of https://github.com/zitadel/zitadel/issues/7639
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { loginByUsernamePassword } from '../login_ui';
|
||||
import { createOrg, removeOrg } from '../org';
|
||||
import {createMachine, User, addMachineSecret} from '../user';
|
||||
import {clientCredentials, userinfo} from '../oidc';
|
||||
import { Config, MaxVUs } from '../config';
|
||||
|
||||
export async function setup() {
|
||||
const tokens = loginByUsernamePassword(Config.admin as User);
|
||||
console.info('setup: admin signed in');
|
||||
|
||||
const org = await createOrg(tokens.accessToken!);
|
||||
console.info(`setup: org (${org.organizationId}) created`);
|
||||
|
||||
let machines = (
|
||||
await Promise.all(
|
||||
Array.from({ length: MaxVUs() }, (_, i) => {
|
||||
return createMachine(`zitachine-${i}`, org, tokens.accessToken!);
|
||||
}),
|
||||
)
|
||||
).map((machine) => {
|
||||
return { userId: machine.userId, loginName: machine.loginNames[0] };
|
||||
});
|
||||
console.info(`setup: ${machines.length} machines created`);
|
||||
|
||||
let credentials = (
|
||||
await Promise.all(
|
||||
machines.map((machine) => {
|
||||
return addMachineSecret(machine.userId, org, tokens.accessToken!);
|
||||
}),
|
||||
)
|
||||
).map((credentials, i) => {
|
||||
return { userId: machines[i].userId, loginName: machines[i].loginName, password: credentials.clientSecret };
|
||||
});
|
||||
console.info(`setup: secrets added`);
|
||||
|
||||
return { tokens, machines: credentials, org };
|
||||
}
|
||||
|
||||
export default function (data: any) {
|
||||
clientCredentials(data.machines[__VU - 1].loginName, data.machines[__VU - 1].password)
|
||||
.then((token) => {
|
||||
userinfo(token.accessToken!)
|
||||
})
|
||||
}
|
||||
|
||||
export function teardown(data: any) {
|
||||
removeOrg(data.org, data.tokens.accessToken);
|
||||
console.info('teardown: org removed');
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { loginByUsernamePassword } from '../login_ui';
|
||||
import { createOrg, removeOrg } from '../org';
|
||||
import { User, createHuman } from '../user';
|
||||
import { Trend } from 'k6/metrics';
|
||||
import { Config, MaxVUs } from '../config';
|
||||
import { createSession } from '../session';
|
||||
import { check } from 'k6';
|
||||
|
||||
export async function setup() {
|
||||
const tokens = loginByUsernamePassword(Config.admin as User);
|
||||
console.log('setup: admin signed in');
|
||||
|
||||
const org = await createOrg(tokens.accessToken!);
|
||||
console.log(`setup: org (${org.organizationId}) created`);
|
||||
|
||||
const humanPromises = Array.from({ length: MaxVUs() }, (_, i) => {
|
||||
return createHuman(`zitizen-${i}`, org, tokens.accessToken!);
|
||||
});
|
||||
|
||||
const humans = (await Promise.all(humanPromises)).map((user) => {
|
||||
return { userId: user.userId, loginName: user.loginNames[0], password: 'Password1!' };
|
||||
});
|
||||
console.log(`setup: ${humans.length} users created`);
|
||||
return { tokens, users: humans, org };
|
||||
}
|
||||
|
||||
const addSessionTrend = new Trend('add_session_duration', true);
|
||||
export default async function (data: any) {
|
||||
const start = new Date();
|
||||
const session = await createSession(data.users[__VU - 1], data.org, data.tokens.accessToken);
|
||||
|
||||
check(session, {
|
||||
'add session is status ok': (s) => s.id !== "",
|
||||
});
|
||||
|
||||
addSessionTrend.add(new Date().getTime() - start.getTime());
|
||||
}
|
||||
|
||||
export function teardown(data: any) {
|
||||
removeOrg(data.org, data.tokens.accessToken);
|
||||
}
|
||||
Reference in New Issue
Block a user