-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (51 loc) · 1.54 KB
/
script.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
import http from 'k6/http';
import { check } from 'k6';
import { Counter } from 'k6/metrics';
let ehSasToken = __ENV.EVENTHUB_ACCESS_TOKEN;
let ehNamespace = __ENV.EVENTHUB_NAMESPACE;
let ehName = __ENV.EVENTHUB_NAME;
console.log(ehName);
let inputStages = JSON.parse('[{"target":10,"duration":"1m"}]')
export let options = {
discardResponseBodies: true,
scenarios: {
contacts: {
executor: 'ramping-arrival-rate',
startRate: 1,
timeUnit: '1s',
preAllocatedVUs: 1000,
maxVUs: 10000,
stages: inputStages
}
}
}
console.log(options)
export function handleSummary(data) {
const med_latency = data.metrics.myCounter;
const latency_message = `The median latency was ${med_latency}\n`;
return {
stdout: latency_message,
};
}
const myCounter = new Counter('my_counter');
export default function () {
const body = {
key: "randomKey1",
value: "randomKey2",
};
var params = {
headers: {
'Content-Type': 'application/atom+xml;type=entry;charset=utf-8',
'Authorization': `SharedAccessSignature ${ehSasToken}`,
'Host': `${ehNamespace}.servicebus.windows.net`
},
};
var uri = `https://${ehNamespace}.servicebus.windows.net/${ehName}/messages`
var url = `${uri}?api-version=2014-01`
let res = http.post(url, JSON.stringify(body), params);
//console.log(res);
check(res, {
"is status 200": r => r.status >= 200 && r.status <= 300
});
myCounter.add(1);
};