-
-
Save devformatters/2ae0ce4bd66230cc9b0a2e4f73ae0994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http' | |
import { endpoint, getTokens, makeParams, rand, stages } from './shared.js' | |
/** | |
* Payout tests. | |
* | |
* Steps for run the script up: | |
* 0. make sure `k6` installed | |
* 1. sepcify `endpoint` in `shared.js` | |
* 2. assign users | |
* 3. assign shared paymentPassword | |
* 4. execute `k6 run payout.js` | |
*/ | |
const users = [ | |
{ email: '', password: '' }, | |
{ email: '', password: '' }, | |
] | |
const paymentPassword = '' | |
export const options = { | |
stages: [ | |
{ target: 2, duration: '3s' } | |
] | |
} | |
export const setup = () => getTokens(endpoint, users) | |
export default ({ tokens }) => { | |
// make multiple requests randomly | |
const requests = tokens.reduce((params, token) => { | |
[...Array(rand(4, 15)).keys()].map(() => { | |
const amount = (rand(300, 1000)).toFixed(2) | |
const query = ` | |
mutation { | |
payout (input: { amount: ${amount}, password: "${paymentPassword}" }) { | |
id | |
state | |
} | |
} | |
` | |
params.push(makeParams(endpoint, query, token)) | |
}) | |
return params | |
}, []) | |
// send requests in parallel | |
const responses = http.batch(requests) | |
responses.map(response => { | |
if (response.status === 200) { | |
const { data } = JSON.parse(response.body) | |
console.log(JSON.stringify(data)) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment