| 1 | // A like storm: a crowd of different people, and every one of them likes once. |
| 2 | import http from 'k6/http'; |
| 3 | import exec from 'k6/execution'; |
| 4 | |
| 5 | export { handleSummary } from './summary.js'; |
| 6 | |
| 7 | export const options = { |
| 8 | vus: Number(__ENV.VUS || 20), |
| 9 | duration: '20s', |
| 10 | summaryTrendStats: ['med', 'p(99)'], |
| 11 | }; |
| 12 | |
| 13 | // POST is the one post that everybody likes. Left unset, everybody likes a different post. |
| 14 | const post = Number(__ENV.POST || 0); |
| 15 | |
| 16 | export default function () { |
| 17 | // A new user every time. Nobody likes twice, so nobody's own rate limit is in the way. |
| 18 | const user = 1 + (exec.scenario.iterationInTest % 100000); |
| 19 | const id = post || 1 + Math.floor(Math.random() * 2000000); |
| 20 | http.post(`${__ENV.BASE_URL}/posts/${id}/like`, null, { |
| 21 | headers: { Authorization: `Bearer seed-token-${user}` }, |
| 22 | tags: { name: 'like' }, // one name for every post, or k6 keeps its numbers per URL |
| 23 | }); |
| 24 | } |