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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
var http = require('k6/http');
var k6 = require('k6');
var metrics = require('k6/metrics');
var check = k6.check;
var sleep = k6.sleep;
var group = k6.group;
var Rate = metrics.Rate;
var Trend = metrics.Trend;
var Counter = metrics.Counter;
var errorRate = new Rate('git_errors');
var uploadPackRefs = new Trend('upload_pack_refs_duration');
var receivePackRefs = new Trend('receive_pack_refs_duration');
var uploadPackPost = new Trend('upload_pack_post_duration');
var gitRequests = new Counter('git_requests_total');
module.exports.options = {
stages: [
{ duration: '20s', target: 50 },
{ duration: '1m', target: 50 },
{ duration: '20s', target: 150 },
{ duration: '30s', target: 150 },
{ duration: '30s', target: 0 },
],
thresholds: {
upload_pack_refs_duration: ['p(95)<300', 'p(99)<800'],
receive_pack_refs_duration: ['p(95)<400', 'p(99)<1000'],
upload_pack_post_duration: ['p(95)<1000', 'p(99)<3000'],
http_req_failed: ['rate<0.01'],
git_errors: ['rate<0.02'],
},
};
var BASE_URL = (typeof __ENV !== 'undefined' && __ENV.BASE_URL) || 'http://localhost:3000';
var GIT_OWNER = (typeof __ENV !== 'undefined' && __ENV.GIT_OWNER) || 'testowner';
var GIT_REPO = (typeof __ENV !== 'undefined' && __ENV.GIT_REPO) || 'testrepo';
var GIT_PAT = (typeof __ENV !== 'undefined' && __ENV.GIT_PAT) || '';
var REPO_PATH = '/' + GIT_OWNER + '/' + GIT_REPO + '.git';
var authHeaders = GIT_PAT
? { Authorization: 'Basic ' + btoa('token:' + GIT_PAT) }
: {};
var GIT_UPLOAD_PACK_BODY = [
'0014command=ls-refs\n',
'0000',
'0000',
].join('');
module.exports.setup = function () {
console.log('[load-test-git] Target: ' + BASE_URL + REPO_PATH);
console.log('[load-test-git] Auth: ' + (GIT_PAT ? 'PAT set (POST tests enabled)' : 'no PAT (read-only tests)'));
return { baseUrl: BASE_URL, repo: REPO_PATH };
};
module.exports.default = function () {
group('upload-pack info/refs', function () {
var url = BASE_URL + REPO_PATH + '/info/refs?service=git-upload-pack';
var headers = {};
Object.assign(headers, authHeaders, {
'Git-Protocol': 'version=2',
'User-Agent': 'git/2.44.0',
});
var r = http.get(url, { headers: headers });
gitRequests.add(1);
var ok = check(r, {
'upload-pack refs: 200 or 401': function (res) {
return res.status === 200 || res.status === 401;
},
'upload-pack refs: correct content-type': function (res) {
return res.status === 401 ||
(res.headers['Content-Type'] || '').indexOf(
'application/x-git-upload-pack-advertisement'
) !== -1;
},
});
errorRate.add(!ok);
uploadPackRefs.add(r.timings.duration);
});
sleep(0.2);
group('receive-pack info/refs', function () {
var url = BASE_URL + REPO_PATH + '/info/refs?service=git-receive-pack';
var headers = {};
Object.assign(headers, authHeaders, {
'Git-Protocol': 'version=2',
'User-Agent': 'git/2.44.0',
});
var r = http.get(url, { headers: headers });
gitRequests.add(1);
var ok = check(r, {
'receive-pack refs: 200 or 401': function (res) {
return res.status === 200 || res.status === 401;
},
'receive-pack refs: not 500': function (res) { return res.status !== 500; },
});
errorRate.add(!ok);
receivePackRefs.add(r.timings.duration);
});
sleep(0.3);
if (GIT_PAT) {
group('upload-pack POST (ls-refs)', function () {
var url = BASE_URL + REPO_PATH + '/git-upload-pack';
var headers = {};
Object.assign(headers, authHeaders, {
'Content-Type': 'application/x-git-upload-pack-request',
'Accept': 'application/x-git-upload-pack-result',
'Git-Protocol': 'version=2',
'User-Agent': 'git/2.44.0',
});
var r = http.post(url, GIT_UPLOAD_PACK_BODY, { headers: headers });
gitRequests.add(1);
var ok = check(r, {
'upload-pack POST: 200': function (res) { return res.status === 200; },
'upload-pack POST: git content-type': function (res) {
return (res.headers['Content-Type'] || '').indexOf(
'application/x-git-upload-pack-result'
) !== -1;
},
'upload-pack POST: not empty': function (res) {
return res.body !== null && res.body.length > 0;
},
});
errorRate.add(!ok);
uploadPackPost.add(r.timings.duration);
});
}
group('raw file fetch (HEAD README)', function () {
var url = BASE_URL + '/' + GIT_OWNER + '/' + GIT_REPO + '/raw/HEAD/README.md';
var r = http.get(url, { headers: authHeaders });
gitRequests.add(1);
var ok = check(r, {
'raw: 200 or 404': function (res) { return res.status === 200 || res.status === 404; },
'raw: not 500': function (res) { return res.status !== 500; },
});
errorRate.add(!ok);
});
sleep(1);
};
|