-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathk6.js
105 lines (89 loc) · 2.97 KB
/
k6.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import http from "k6/http";
import { check, sleep, group } from "k6";
const ENDPOINT = __ENV.ENDPOINT;
function simulateUserLoginTest() {
let url = `${ENDPOINT}/profile`;
const payload = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
"user_type": "driver"
});
const params = { headers: { 'Content-Type': 'application/json' } };
let response = http.post(url, payload, params);
check(response, { 'Fetch Driver Profile': (r) => r.status === 200 });
sleep(1);
}
function simulateGetPendingTripTest() {
let url = `${ENDPOINT}/trips/get/pending`;
const payload = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
});
const params = { headers: { 'Content-Type': 'application/json' } };
let response = http.post(url, payload, params);
check(response, { 'is status 200': (r) => r.status === 200 });
sleep(1);
}
export const options = {
scenarios: {
studier: {
exec: 'simulateUserLogin',
executor: "ramping-vus",
stages: [
{ duration: "2m", target: 100 },
{ duration: "2m", target: 25 },
{ duration: "2m", target: 0 },
],
},
getPendingTrip: {
exec: 'simulateTripCreation',
executor: "ramping-vus",
stages: [
{ duration: "2m", target: 100 },
{ duration: "2m", target: 25 },
{ duration: "2m", target: 0 },
],
}
},
};
export function setup() {
// Create a driver user
let url = `${ENDPOINT}/driver/create`;
const payload = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
"name": "John Doe",
"phone_number": "1234567890",
"email": "[email protected]",
"max_available_seats": 4,
"licence_plate": "319IRG"
});
const params = { headers: { 'Content-Type': 'application/json' } };
let response = http.post(url, payload, params);
check(response, { 'Sign Up a Driver': (r) => r.status === 201 });
sleep(1);
let url2 = `${ENDPOINT}/trip/create`;
const payload2 = JSON.stringify({
"username": "jDoe11",
"password": "53%32",
"start_time": "2024-05-31T07:38:56Z",
"end_time": "2024-05-31T08:00:00Z",
"start_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "123 street road, Brisbane, QLD"},
"end_location": {"latitude": 37.7749, "longitude": -122.4194, "address": "125 street road, Brisbane, QLD"},
"seats_remaining": 3,
"distance_addition": 4
});
const params2 = { headers: { 'Content-Type': 'application/json' } };
let response2 = http.post(url2, payload2, params2);
check(response2, { 'is status 201': (r) => r.status === 201 });
}
export function simulateUserLogin() {
group('User Actions', function () {
simulateUserLoginTest();
});
}
export function simulateTripCreation() {
group('User Actions', function () {
simulateGetPendingTripTest();
});
}