parent
6b23dea477
commit
a580841973
|
@ -1,10 +1,15 @@
|
|||
import axios from "axios"
|
||||
import faker from "faker"
|
||||
import { config } from '../config'
|
||||
import { CertificateRunner } from '../models/CertificateRunner'
|
||||
import { DistanceDonation } from '../models/DistanceDonation'
|
||||
import { Donor } from '../models/Donor'
|
||||
import { Runner } from '../models/Runner'
|
||||
import { RunnerCard } from '../models/RunnerCard'
|
||||
import { RunnerGroup } from '../models/RunnerGroup'
|
||||
|
||||
const baseurl = "http://localhost:4010"
|
||||
const key = config.api_key;
|
||||
|
||||
axios.interceptors.request.use((config) => {
|
||||
config.headers['request-startTime'] = process.hrtime()
|
||||
|
@ -46,6 +51,36 @@ function generateCards(amount: number): RunnerCard[] {
|
|||
return cards;
|
||||
}
|
||||
|
||||
function generateCertificateRunners(amount: number): CertificateRunner[] {
|
||||
let runners: CertificateRunner[] = new Array<CertificateRunner>();
|
||||
let group = new RunnerGroup();
|
||||
let runner = new CertificateRunner();
|
||||
let donor = new Donor();
|
||||
let donation = new DistanceDonation();
|
||||
for (var i = 0; i < amount; i++) {
|
||||
group.name = faker.company.bsBuzz();
|
||||
group.id = Math.floor(Math.random() * (9999999 - 1) + 1);
|
||||
|
||||
donor.firstname = faker.name.firstName();
|
||||
donor.lastname = faker.name.lastName();
|
||||
donor.id = Math.floor(Math.random() * (9999999 - 1) + 1);
|
||||
|
||||
runner.firstname = faker.name.firstName();
|
||||
runner.lastname = faker.name.lastName();
|
||||
runner.id = Math.floor(Math.random() * (9999999 - 1) + 1);
|
||||
runner.distance = Math.floor(Math.random() * (9999999 - 1) + 1);
|
||||
|
||||
donation.id = Math.floor(Math.random() * (9999999 - 1) + 1);
|
||||
donation.donor = donor;
|
||||
donation.runner = runner;
|
||||
donation.amountPerDistance = Math.floor(Math.random() * (10000 - 1) + 1);
|
||||
|
||||
runner.distanceDonations = [donation, donation]
|
||||
runners.push(runner);
|
||||
}
|
||||
return runners;
|
||||
}
|
||||
|
||||
function idToEan13(id): string {
|
||||
const multiply = [1, 3];
|
||||
id = id.toString();
|
||||
|
@ -64,15 +99,20 @@ function idToEan13(id): string {
|
|||
}
|
||||
|
||||
async function postContracts(runners: Runner[]): Promise<Measurement> {
|
||||
const res = await axios.post(`${baseurl}/contracts`, runners);
|
||||
const res = await axios.post(`${baseurl}/contracts?key=${key}`, runners);
|
||||
return new Measurement("contract", runners.length, parseInt(res.headers['request-duration']))
|
||||
}
|
||||
|
||||
async function postCards(cards: RunnerCard[]): Promise<Measurement> {
|
||||
const res = await axios.post(`${baseurl}/cards`, cards);
|
||||
const res = await axios.post(`${baseurl}/cards?key=${key}`, cards);
|
||||
return new Measurement("card", cards.length, parseInt(res.headers['request-duration']))
|
||||
}
|
||||
|
||||
async function postCertificates(runners: CertificateRunner[]): Promise<Measurement> {
|
||||
const res = await axios.post(`${baseurl}/certificates?key=${key}`, runners);
|
||||
return new Measurement("certificate", runners.length, parseInt(res.headers['request-duration']))
|
||||
}
|
||||
|
||||
async function testContracts(sizes): Promise<Measurement[]> {
|
||||
let measurements = new Array<Measurement>();
|
||||
console.log("#### Testing contracts ####");
|
||||
|
@ -97,16 +137,30 @@ async function testCards(sizes): Promise<Measurement[]> {
|
|||
return measurements;
|
||||
}
|
||||
|
||||
async function testCertificates(sizes): Promise<Measurement[]> {
|
||||
let measurements = new Array<Measurement>();
|
||||
console.log("#### Testing Certificates ####");
|
||||
|
||||
for (let size of sizes) {
|
||||
const m = await postCertificates(generateCertificateRunners(size));
|
||||
console.log(m.toString());
|
||||
measurements.push(m);
|
||||
}
|
||||
return measurements;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const sizes = [0, 1, 10, 50, 100, 200, 500, 1000]
|
||||
const sizes = [1, 10, 50, 100]
|
||||
console.log("########### Speedtest ###########");
|
||||
console.log(`Document server version (according to the api): ${(await axios.get("http://localhost:4010/version")).data.version}`);
|
||||
console.log("####### Running tests #######");
|
||||
const contractResults = await testContracts(sizes);
|
||||
const cardResults = await testCards(sizes);
|
||||
const certificateResults = await testCertificates(sizes);
|
||||
console.log("####### Results #######");
|
||||
console.table(contractResults);
|
||||
console.table(cardResults);
|
||||
console.table(certificateResults);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue