| 1 | // Authors post, as fast as the API answers. |
| 2 | import http from 'k6/http'; |
| 3 | |
| 4 | export { handleSummary } from './summary.js'; |
| 5 | |
| 6 | export const options = { |
| 7 | vus: Number(__ENV.VUS || 20), |
| 8 | duration: '20s', |
| 9 | iterations: Number(__ENV.POSTS) || undefined, // POSTS=500 stops after 500 posts |
| 10 | summaryTrendStats: ['med', 'p(99)'], |
| 11 | }; |
| 12 | |
| 13 | // Who posts: the AUTHORS biggest accounts. Left unset, it's anybody. |
| 14 | const authors = Number(__ENV.AUTHORS || 100000); |
| 15 | // FIRST is the biggest of them. FIRST=119 starts just under the line. |
| 16 | const first = Number(__ENV.FIRST || 1); |
| 17 | |
| 18 | export default function () { |
| 19 | const id = first + Math.floor(Math.random() * authors); |
| 20 | http.post(`${__ENV.BASE_URL}/posts`, JSON.stringify({ body: 'a post from the load test' }), { |
| 21 | headers: { Authorization: `Bearer seed-token-${id}`, 'Content-Type': 'application/json' }, |
| 22 | }); |
| 23 | } |