-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlindas-conformity.js
100 lines (78 loc) · 2.39 KB
/
lindas-conformity.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
import http from 'k6/http';
import { check, group } from 'k6';
import encoding from 'k6/encoding';
import { SharedArray, } from 'k6/data';
import { Trend } from 'k6/metrics';
const endpoint = __ENV.SPARQL_ENDPOINT;
let authorizationHeader = null;
// Define the username and password
const username = __ENV.SPARQL_USERNAME;
const password = __ENV.SPARQL_PASSWORD;
if (username && password) {
// Encode the credentials in base64
const encodedCredentials = encoding.b64encode(`${username}:${password}`);
// Define the headers with the Authorization header
authorizationHeader = `Basic ${encodedCredentials}`;
}
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/n-triples,*/*;q=0.9',
};
if (authorizationHeader) {
headers['Authorization'] = authorizationHeader;
}
const queries = new SharedArray('queries', function () {
const file = open('query-files.json');
const list = JSON.parse(file);
const requests = [];
list.forEach((filePath) => {
const queryData = open(filePath);
requests.push(`# File: ${filePath} (conformity)\n\n${queryData}`);
});
return requests;
});
const queryLength = queries.length;
export function handleSummary (data) {
return {
'./results/summary-conformity.json': JSON.stringify(data, null, 2),
};
}
// Configure options
export let options = {
scenarios: {
'lindas-conformity': {
executor: 'shared-iterations',
vus: 1,
maxDuration: '1d',
},
},
};
// Create a custom metric for each query's execution time
let queryTrends = queries.map((_query, index) => new Trend(`query_${index}_time`));
// Create a custom metric for total execution time
const totalTrend = new Trend('total_execution_time');
export default function () {
const totalStart = new Date();
for (let i = 0; i < queryLength; i++) {
const query = queries[i];
group(`Query ${i}`, function () {
const start = new Date();
console.log(`Query#${i}/${queryLength - 1}: ${query}\n\n`);
const res = http.post(endpoint, {
query,
}, {
headers,
timeout: '5m',
});
const end = new Date();
const duration = end - start;
queryTrends[i].add(duration);
check(res, {
'is status 200': (r) => r.status === 200,
});
});
}
const totalEnd = new Date();
const totalDuration = totalEnd - totalStart;
totalTrend.add(totalDuration);
}