-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud.js
109 lines (91 loc) · 3.83 KB
/
crud.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
106
107
108
109
import { check } from "k6";
import { openKv } from "k6/x/kv";
import exec from 'k6/execution';
import ptResource from './seed/patient.js';
import { auth, base_url, normalize, make_id, take_id, get, post, put, del} from './utils.js';
const kv = openKv();
const stages = [{ duration: '30s', target: 300 },
{ duration: '1m', target: 300 },
{ duration: '30s', target: 500 },
{ duration: '30s', target: 300 },
{ duration: '1m', target: 300 },
{ duration: '30s', target: 0 },
{ duration: '30s', target: 0 }
];
const scenarios = normalize({
create: {
stages: stages,
},
read: {
stages: stages,
dependsOn: "create"
},
update: {
stages: stages,
dependsOn: "read"
},
del_: {
stages: stages,
dependsOn: "update"
},
full: {
stages: stages,
dependsOn: "del_"
},
});
export const options = {
scenarios: scenarios,
thresholds: {'http_req_duration': ['p(99)<10000']}
};
export function setup() {
return {
id_prefix: make_id(10),
resource: ptResource
};
}
export function create({resource, id_prefix}) {
const iteration = exec.scenario.iterationInInstance;
const body = Object.assign({}, resource, { id: `${id_prefix[0]}-${iteration}` });
const resp = post(`${base_url}/Patient`, JSON.stringify(body), auth);
check(resp, { 'Created status': ({ status }) => status == 201 });
kv.set('create-iteration', iteration);
};
export function read({resource, id_prefix}) {
const id = take_id(id_prefix, kv);
const params = Object.assign({}, auth, { tags: { name: `${base_url}/Patient/?`,
pathname: '/Patient/?'}});
const resp = get(`${base_url}/Patient/${id}`, params);
check(resp, { 'Read status': ({ status }) => status == 200 });
};
export function update({resource, id_prefix}) {
const id = take_id(id_prefix, kv);
const body = Object.assign({}, resource, {name: [{use: "official", text: make_id(10)}]});
const resp = put(`${base_url}/Patient/${id}`,
JSON.stringify(body),
Object.assign({}, auth, { tags: { name: `${base_url}/Patient/?`,
pathname: '/Patient/?'} }));
check(resp, { 'Update status': ({ status }) => status == 200 || status == 201});
};
export function del_({resource, id_prefix}) {
const id = take_id(id_prefix, kv);
const resp = del(`${base_url}/Patient/${id}`,
null,
Object.assign({}, auth, { tags: { name: `${base_url}/Patient/?`,
pathname: '/Patient/?'} }));
check(resp, { 'Delete status': ({ status }) => status == 200 || status == 204 || status == 410 });
};
export function full({resource}) {
const id = make_id(10);
const body = Object.assign({}, resource, {id: id});
const createdPatient = put(`${base_url}/Patient`, JSON.stringify(body), auth);
check(createdPatient, { 'Created status': ({ status }) => status == 201 });
const params = Object.assign({}, auth, { tags: { name: `${base_url}/Patient/?`,
pathname: '/Patient/?'} });
const readPatient = get(`${base_url}/Patient/${id}`, params);
check(readPatient, { 'Get status': ({ status }) => status == 200 });
const updated = Object.assign({}, body, { gender: 'female' });
const updatedPatient = put(`${base_url}/Patient/${id}`, JSON.stringify(updated), params);
check(updatedPatient, { 'Update status': ({ status }) => status == 200 });
const deletedPatient = del(`${base_url}/Patient/${id}`, null, params);
check(deletedPatient, { 'Delete status': ({ status }) => status == 200 });
};