Skip to content

Commit 2bd6f26

Browse files
update code samples for consistency
1 parent ee07f84 commit 2bd6f26

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/200 Test for performance.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Thresholds are set in options.
2929

3030
```javascript
3131
export const options = {
32-
//define thresholds
32+
// define thresholds
3333
thresholds: {
3434
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
3535
http_req_duration: ['p(99)<1000'], // 99% of requests should be below 1s
@@ -44,13 +44,13 @@ Add this [`options`](/using-k6/k6-options/) object with thresholds to your scrip
4444
heightTogglers={[true]}>
4545

4646
```javascript
47-
// Import necessary modules
47+
// import necessary modules
4848
import { check } from "k6";
4949
import http from "k6/http";
5050

51-
//define configuration
51+
// define configuration
5252
export const options = {
53-
//define thresholds
53+
// define thresholds
5454
thresholds: {
5555
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
5656
http_req_duration: ["p(99)<1000"], // 99% of requests should be below 1s
@@ -75,7 +75,7 @@ export default function () {
7575

7676
// check that response is 200
7777
check(res, {
78-
"login response was 200": (res) => res.status == 200,
78+
"response code was 200": (res) => res.status == 200,
7979
});
8080
}
8181

@@ -133,9 +133,16 @@ Since this is a learning environment, the stages are still quite short.
133133
Add the following _scenario_ to your options `object` and rerun the test.
134134
Where the smoke test defined the load in terms of iterations, this configuration uses the [`ramping-vus` executor](/using-k6/scenarios/executors/ramping-vus/) to express load through virtual users and duration.
135135

136-
```json
136+
```javascript
137+
export const options = {
138+
// define thresholds
139+
thresholds: {
140+
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
141+
http_req_duration: ['p(99)<1000'], // 99% of requests should be below 1s
142+
},
143+
// define scenarios
137144
scenarios: {
138-
//arbitrary name of scenario
145+
// arbitrary name of scenario
139146
average_load: {
140147
executor: "ramping-vus",
141148
stages: [
@@ -148,6 +155,7 @@ Where the smoke test defined the load in terms of iterations, this configuration
148155
],
149156
},
150157
}
158+
};
151159
```
152160

153161
Run the test with no command-line flags:
@@ -191,7 +199,7 @@ To do this:
191199
http_req_duration: ['p(99)<1000'],
192200
},
193201
scenarios: {
194-
//arbitrary name of scenario:
202+
// define scenarios
195203
breaking: {
196204
executor: "ramping-vus",
197205
stages: [
@@ -217,14 +225,19 @@ Copy and run it with `k6 run api-test.js`.
217225
heightTogglers={[true]}>
218226

219227
```javascript
220-
// Import necessary modules
228+
// import necessary modules
221229
import { check } from "k6";
222230
import http from "k6/http";
223231

224-
//define configuration
232+
// define configuration
225233
export const options = {
234+
// define thresholds
235+
thresholds: {
236+
http_req_failed: [{ threshold: "rate<0.01", abortOnFail: true }], // availability threshold for error rate
237+
http_req_duration: ["p(99)<1000"], // Latency threshold for percentile
238+
},
239+
// define scenarios
226240
scenarios: {
227-
//arbitrary name of scenario:
228241
breaking: {
229242
executor: "ramping-vus",
230243
stages: [
@@ -240,11 +253,6 @@ export const options = {
240253
],
241254
},
242255
},
243-
//define thresholds
244-
thresholds: {
245-
http_req_failed: [{ threshold: "rate<0.01", abortOnFail: true }], // availability threshold for error rate
246-
http_req_duration: ["p(99)<1000"], // Latency threshold for percentile
247-
},
248256
};
249257

250258
export default function () {
@@ -265,7 +273,7 @@ export default function () {
265273

266274
// check that response is 200
267275
check(res, {
268-
"login response was 200": (res) => res.status == 200,
276+
"response code was 200": (res) => res.status == 200,
269277
});
270278
}
271279

0 commit comments

Comments
 (0)