Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
isandratskiy committed Sep 29, 2021
1 parent 21d6f87 commit 24976b6
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"printWidth": 80,
"tabWidth": 1,
"useTabs": true,
"semi": true,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
Expand Down
36 changes: 18 additions & 18 deletions src/controller/my.crocodiles.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import * as request from '../utils/request';
import { K6Interceptor } from '../utils/request';
import { sleep } from 'k6';
import { Crocodile } from '../types/crocodile.type';
import fake from 'faker';
import * as request from '../utils/request'
import { K6Interceptor } from '../utils/request'
import { sleep } from 'k6'
import { Crocodile } from '../types/crocodile.type'
import fake from 'faker'

const CROCODILES_ENDPOINT = 'my/crocodiles/';
const CROCODILES_ENDPOINT = 'my/crocodiles/'

export function createCrocodiles(
token: string,
crocodile: Crocodile,
interceptor?: K6Interceptor
): Crocodile {
const headers = request.headers(token);
const headers = request.headers(token)
const response = request.post<Crocodile>(
CROCODILES_ENDPOINT,
crocodile,
headers,
interceptor
);
)

sleep(0.3);
return response;
sleep(0.3)
return response
}

export function getCrocodiles(
token: string,
interceptor?: K6Interceptor
): Crocodile[] {
const headers = request.headers(token);
const headers = request.headers(token)
const response = request.get<Crocodile[]>(
CROCODILES_ENDPOINT,
headers,
interceptor
);
)

sleep(0.3);
return response;
sleep(0.3)
return response
}

export function prepareCrocodiles(token: string, count: number = 100): void {
Expand All @@ -44,10 +44,10 @@ export function prepareCrocodiles(token: string, count: number = 100): void {
name: fake.name.firstName(),
sex: 'M',
date_of_birth: '2020-10-15'
};
}

const headers = request.headers(token);
request.post(CROCODILES_ENDPOINT, crocodile, headers);
sleep(0.3);
const headers = request.headers(token)
request.post(CROCODILES_ENDPOINT, crocodile, headers)
sleep(0.3)
}
}
24 changes: 12 additions & 12 deletions src/controller/user.auth.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import * as request from '../utils/request';
import { K6Interceptor } from '../utils/request';
import { sleep } from 'k6';
import { AuthRequest, AuthResponse } from '../types/user.type';
import * as request from '../utils/request'
import { K6Interceptor } from '../utils/request'
import { sleep } from 'k6'
import { AuthRequest, AuthResponse } from '../types/user.type'

const AUTH_ENDPOINT = 'auth/token/login/';
const AUTH_ENDPOINT = 'auth/token/login/'

export function login(
authUser: AuthRequest,
interceptor?: K6Interceptor
): void {
const headers = request.headers();
request.post(AUTH_ENDPOINT, authUser, headers, interceptor);
sleep(0.3);
const headers = request.headers()
request.post(AUTH_ENDPOINT, authUser, headers, interceptor)
sleep(0.3)
}

export function getAuth({
username,
password
}: {
username: string;
password: string;
username: string
password: string
}): string {
const headers = request.headers();
const headers = request.headers()
return request.post<AuthResponse>(
AUTH_ENDPOINT,
{ username, password },
headers
).access;
).access
}
16 changes: 8 additions & 8 deletions src/controller/user.register.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { sleep } from 'k6';
import * as request from '../utils/request';
import { K6Interceptor } from '../utils/request';
import { User } from '../types/user.type';
import { sleep } from 'k6'
import * as request from '../utils/request'
import { K6Interceptor } from '../utils/request'
import { User } from '../types/user.type'

const REGISTER_ENDPOINT = 'user/register/';
const REGISTER_ENDPOINT = 'user/register/'

export function register(user: User, interceptor?: K6Interceptor): void {
const headers = request.headers();
request.post(REGISTER_ENDPOINT, user, headers, interceptor);
sleep(0.3);
const headers = request.headers()
request.post(REGISTER_ENDPOINT, user, headers, interceptor)
sleep(0.3)
}
32 changes: 16 additions & 16 deletions src/test/crocodiles.create.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as auth from '../controller/user.auth';
import * as user from '../controller/user.register';
import { Options } from 'k6/options';
import * as fake from 'faker';
import * as rate from '../utils/metrics';
import { createCrocodiles } from '../controller/my.crocodiles';
import { Crocodile } from '../types/crocodile.type';
import { User } from '../types/user.type';
import * as auth from '../controller/user.auth'
import * as user from '../controller/user.register'
import { Options } from 'k6/options'
import * as fake from 'faker'
import * as rate from '../utils/metrics'
import { createCrocodiles } from '../controller/my.crocodiles'
import { Crocodile } from '../types/crocodile.type'
import { User } from '../types/user.type'

export const options: Partial<Options> = {
vus: 30,
Expand All @@ -14,7 +14,7 @@ export const options: Partial<Options> = {
p80_within_1sec: ['rate >= 0.8'],
errors_rate: ['rate <= 0.1']
}
};
}

export function setup(): string {
const userPayload: User = {
Expand All @@ -23,21 +23,21 @@ export function setup(): string {
last_name: fake.name.lastName(),
email: fake.internet.email(),
password: fake.internet.password()
};
}

user.register(userPayload);
return auth.getAuth(userPayload);
user.register(userPayload)
return auth.getAuth(userPayload)
}

export default function (_token: string): void {
const crocodile: Crocodile = {
name: fake.name.firstName(),
sex: 'M',
date_of_birth: '2020-10-15'
};
}

createCrocodiles(_token, crocodile, response => {
rate.p80_within_1sec(response);
rate.errors(response, 201);
});
rate.p80_within_1sec(response)
rate.errors(response, 201)
})
}
32 changes: 16 additions & 16 deletions src/test/crocodiles.search.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Options } from 'k6/options';
import { User } from '../types/user.type';
import * as fake from 'faker';
import * as user from '../controller/user.register';
import * as auth from '../controller/user.auth';
import { getCrocodiles, prepareCrocodiles } from '../controller/my.crocodiles';
import * as rate from '../utils/metrics';
import { Options } from 'k6/options'
import { User } from '../types/user.type'
import * as fake from 'faker'
import * as user from '../controller/user.register'
import * as auth from '../controller/user.auth'
import { getCrocodiles, prepareCrocodiles } from '../controller/my.crocodiles'
import * as rate from '../utils/metrics'

export const options: Partial<Options> = {
scenarios: {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const options: Partial<Options> = {
]
},
discardResponseBodies: false
};
}

export function setup(): string {
const userPayload: User = {
Expand All @@ -50,17 +50,17 @@ export function setup(): string {
last_name: fake.name.lastName(),
email: fake.internet.email(),
password: fake.internet.password()
};
}

user.register(userPayload);
const token = auth.getAuth(userPayload);
prepareCrocodiles(token, 50);
return token;
user.register(userPayload)
const token = auth.getAuth(userPayload)
prepareCrocodiles(token, 50)
return token
}

export function searchCrocodiles(_token: string): void {
getCrocodiles(_token, response => {
rate.p80_within_1sec(response);
rate.errors(response, 200);
});
rate.p80_within_1sec(response)
rate.errors(response, 200)
})
}
10 changes: 5 additions & 5 deletions src/types/crocodile.type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface Crocodile {
id?: number;
name: string;
sex: string;
date_of_birth: string;
age?: number;
id?: number
name: string
sex: string
date_of_birth: string
age?: number
}
18 changes: 9 additions & 9 deletions src/types/user.type.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export interface User {
username: string;
first_name: string;
last_name: string;
email: string;
password: string;
username: string
first_name: string
last_name: string
email: string
password: string
}

export interface AuthRequest {
username: string;
password: string;
username: string
password: string
}

export interface AuthResponse {
refresh: string;
access: string;
refresh: string
access: string
}
12 changes: 6 additions & 6 deletions src/utils/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Rate } from 'k6/metrics';
import { RefinedResponse } from 'k6/http';
import { Rate } from 'k6/metrics'
import { RefinedResponse } from 'k6/http'

const P80 = new Rate('p80_within_1sec');
const ERRORS_RATE = new Rate('errors_rate');
const P80 = new Rate('p80_within_1sec')
const ERRORS_RATE = new Rate('errors_rate')

export function p80_within_1sec(response: RefinedResponse<any>): void {
P80.add(response.timings.duration < 1000);
P80.add(response.timings.duration < 1000)
}

export function errors(response: RefinedResponse<any>, status: number): void {
ERRORS_RATE.add(response.status !== status);
ERRORS_RATE.add(response.status !== status)
}
18 changes: 9 additions & 9 deletions src/utils/report.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const reporter = require('k6-html-reporter');
const fs = require('fs');
const reporter = require('k6-html-reporter')
const fs = require('fs')

const REPORT_FOLDER = './dist/reports';
const SOURCE_FOLDER = './dist/source';
const REPORT_FOLDER = './dist/reports'
const SOURCE_FOLDER = './dist/source'

fs.readdirSync(SOURCE_FOLDER).forEach(file => {
const name = file.replace('.json', '');
const name = file.replace('.json', '')
const options = {
jsonFile: `${SOURCE_FOLDER}/${file}`,
output: REPORT_FOLDER
};
}

reporter.generateSummaryReport(options);
reporter.generateSummaryReport(options)

fs.renameSync(`${REPORT_FOLDER}/report.html`, `${REPORT_FOLDER}/${name}.html`);
});
fs.renameSync(`${REPORT_FOLDER}/report.html`, `${REPORT_FOLDER}/${name}.html`)
})
Loading

0 comments on commit 24976b6

Please sign in to comment.