parent
1eb634fe11
commit
68572b194e
|
@ -1,6 +1,7 @@
|
|||
import axios from "axios"
|
||||
import faker from "faker"
|
||||
import { Runner } from '../models/Runner'
|
||||
import { RunnerCard } from '../models/RunnerCard'
|
||||
import { RunnerGroup } from '../models/RunnerGroup'
|
||||
|
||||
const baseurl = "http://localhost:4010"
|
||||
|
@ -33,11 +34,45 @@ function generateRunners(amount: number): Runner[] {
|
|||
return runners;
|
||||
}
|
||||
|
||||
function generateCards(amount: number): RunnerCard[] {
|
||||
let cards: RunnerCard[] = new Array<RunnerCard>();
|
||||
let card = new RunnerCard();
|
||||
for (let runner of generateRunners(amount)) {
|
||||
card.id = runner.id;
|
||||
card.code = idToEan13(card.id);
|
||||
card.runner = runner;
|
||||
cards.push(card);
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
function idToEan13(id): string {
|
||||
const multiply = [1, 3];
|
||||
id = id.toString();
|
||||
|
||||
if (id.length > 12) {
|
||||
throw new Error("id too long");
|
||||
}
|
||||
while (id.length < 12) { id = '0' + id; }
|
||||
|
||||
let total = 0;
|
||||
this.id.split('').forEach((letter, index) => {
|
||||
total += parseInt(letter, 10) * multiply[index % 2];
|
||||
});
|
||||
const checkSum = (Math.ceil(total / 10) * 10) - total;
|
||||
return this.id + checkSum.toString();
|
||||
}
|
||||
|
||||
async function postContracts(runners: Runner[]): Promise<Measurement> {
|
||||
const res = await axios.post(`${baseurl}/contracts`, 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);
|
||||
return new Measurement("card", cards.length, parseInt(res.headers['request-duration']))
|
||||
}
|
||||
|
||||
async function testContracts(sizes): Promise<Measurement[]> {
|
||||
let measurements = new Array<Measurement>();
|
||||
console.log("#### Testing contracts ####");
|
||||
|
@ -50,14 +85,28 @@ async function testContracts(sizes): Promise<Measurement[]> {
|
|||
return measurements;
|
||||
}
|
||||
|
||||
async function testCards(sizes): Promise<Measurement[]> {
|
||||
let measurements = new Array<Measurement>();
|
||||
console.log("#### Testing Cards ####");
|
||||
|
||||
for (let size of sizes) {
|
||||
const m = await postCards(generateCards(size));
|
||||
console.log(m.toString());
|
||||
measurements.push(m);
|
||||
}
|
||||
return measurements;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const sizes = [0, 1, 10, 50, 100, 200, 500, 1000]
|
||||
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);
|
||||
console.log("####### Results #######");
|
||||
console.table(contractResults);
|
||||
console.table(cardResults);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Reference in New Issue