|
| 1 | +import { check } from 'k6'; |
| 2 | +import http from 'k6/http'; |
| 3 | + |
| 4 | +// eslint-disable-next-line no-undef |
| 5 | +const STAKE_POOL_PROVIDER_URL = __ENV.PROVIDER_SERVER_URL; |
| 6 | +const MAX_STAKE_POOLS = 500; |
| 7 | +export const options = { |
| 8 | + thresholds: { |
| 9 | + http_req_duration: ['p(95)<500'], |
| 10 | + http_req_failed: ['rate<0.01'] |
| 11 | + } |
| 12 | +}; |
| 13 | + |
| 14 | +export const setup = () => { |
| 15 | + const stakePools = []; |
| 16 | + let idx = 0; |
| 17 | + const limit = 25; |
| 18 | + |
| 19 | + // Get the list of stake pools |
| 20 | + while (stakePools.length < MAX_STAKE_POOLS) { |
| 21 | + const searchResponse = http.post( |
| 22 | + `${STAKE_POOL_PROVIDER_URL}/stake-pool/search`, |
| 23 | + JSON.stringify({ |
| 24 | + pagination: { |
| 25 | + limit, |
| 26 | + startAt: idx * limit |
| 27 | + } |
| 28 | + }), |
| 29 | + { |
| 30 | + headers: { |
| 31 | + 'Content-Type': 'application/json' |
| 32 | + } |
| 33 | + } |
| 34 | + ); |
| 35 | + idx++; |
| 36 | + check(searchResponse, { |
| 37 | + 'Initial query successfull': (r) => r.status === 200 |
| 38 | + }); |
| 39 | + const parsedPageResults = JSON.parse(searchResponse.body.toString()).pageResults; |
| 40 | + stakePools.push(...parsedPageResults); |
| 41 | + if (parsedPageResults.length < 25) break; |
| 42 | + } |
| 43 | + return { stakePools }; |
| 44 | +}; |
| 45 | + |
| 46 | +export default function (data) { |
| 47 | + const randomIndex = Math.floor(Math.random() * data.stakePools.length); |
| 48 | + // Select random stake pool from the list to query by id |
| 49 | + const stakePool = data.stakePools[randomIndex]; |
| 50 | + const requestBody = { |
| 51 | + filters: { |
| 52 | + identifier: { values: [{ id: stakePool.id }] }, |
| 53 | + pledgeMet: true |
| 54 | + }, |
| 55 | + pagination: { limit: 2, startAt: 0 } |
| 56 | + }; |
| 57 | + return http.post(`${STAKE_POOL_PROVIDER_URL}/stake-pool/search`, JSON.stringify(requestBody), { |
| 58 | + headers: { 'Content-Type': 'application/json' } |
| 59 | + }); |
| 60 | +} |
0 commit comments