mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-26 17:22:15 +00:00
# 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
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
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);
|
|
}
|