Last active
October 23, 2020 13:54
-
-
Save josephwegner/df72409bc9c54728942f3e57f1f8d1c8 to your computer and use it in GitHub Desktop.
Traffic Simulation DX
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
const sim = new Simulation({ | |
home: '/', | |
login: '/login', | |
successfulLogin: { path: 'login', method: 'POST', body: { username: 'joe', password: 'goodpass' } }, | |
failedLogin: { path: 'login', method: 'POST', body: { username: 'joe', password: 'badpass' } }, | |
dash: '/dashboard', | |
billing: '/billing' | |
}) | |
const newUser = sim.actor(5, 'New User') | |
const loggingInUser = sim.actor(2, 'Unauthed User') | |
const loggedInUser = sim.actor(3, 'Authed User', { cookies: { session: 'abcde=' } }) | |
newUser.do(sim.home) | |
.do(sim.login, 5) | |
.become(loggingInUser) | |
.do(sim.dash, 1) | |
.assert({ status: 302, headers: { location: sim.login }) | |
.become(loggingInUser) | |
loggingInUser.do(sim.login) | |
.do(sim.successfulLogin, 9) | |
.become(loggedInUser) | |
.do(sim.failedLogin, 1) | |
.assert({ status: 401 }) | |
.do(sim.successfulLogin) | |
.become(loggedInUser) | |
.do(sim.failedLogin).end() | |
loggedInUser.do(sim.dash) | |
.do(sim.billing, 2) | |
.end(4, { delay: 1000 * 60 * 5 }) | |
sim.run(50, 50000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment