-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimulateTraffic.ts
41 lines (35 loc) · 1.2 KB
/
simulateTraffic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import axios from "axios";
import v4 from "uuid/v4";
async function call() {
let uuid: string;
try {
const response = await axios.post("http://127.0.0.1:8080/transaction", {
price: {
amount: Math.floor(Math.random() * (40 - 30)) + 30,
currency: "EUR" },
product: "demo",
uuid: uuid = v4(),
});
console.log("Code: ", response.status);
console.log(`http://127.1:8080/transaction/${uuid}`);
setTimeout(async () => {
await Promise.all([
axios.get(`http://127.0.0.1:8080/transaction/${uuid}`),
axios.get(`http://127.0.0.1:8080/transaction/${uuid}`),
axios.get(`http://127.0.0.1:8080/transaction/${uuid}`),
axios.get(`http://127.0.0.1:8080/transaction/${uuid}`),
axios.get(`http://127.0.0.1:8080/transaction/${uuid}`),
])
}, 80);
} catch (err) {
console.log(err.message);
}
}
(function loop(iteration: number) {
setTimeout(async () => {
if (--iteration) {
await call();
loop(iteration);
}
}, 50);
})(500); // Generate 500 transactions