parent
a30600943d
commit
e3a45a61ac
|
@ -0,0 +1,45 @@
|
|||
import axios from "axios"
|
||||
import { Runner } from '../models/Runner'
|
||||
|
||||
const baseurl = "http://localhost:4010"
|
||||
|
||||
axios.interceptors.request.use((config) => {
|
||||
config.headers['request-startTime'] = process.hrtime()
|
||||
return config
|
||||
})
|
||||
|
||||
axios.interceptors.response.use((response) => {
|
||||
const start = response.config.headers['request-startTime']
|
||||
const end = process.hrtime(start)
|
||||
const milliseconds = Math.round((end[0] * 1000) + (end[1] / 1000000))
|
||||
response.headers['request-duration'] = milliseconds
|
||||
return response
|
||||
})
|
||||
|
||||
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 main() {
|
||||
console.log((await axios.get("http://localhost:4010/version")).data)
|
||||
console.log((await postContracts([])).toString())
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
class Measurement {
|
||||
public type: string;
|
||||
public inputcount: number;
|
||||
public responsetime: number;
|
||||
|
||||
constructor(type: string, input: number, time: number) {
|
||||
this.type = type;
|
||||
this.inputcount = input;
|
||||
this.responsetime = time;
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `It took ${this.responsetime}ms to generate ${this.inputcount} pdfs for the type ${this.type}.`
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue