Skip to content

Instantly share code, notes, and snippets.

@josephwegner
Last active October 23, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephwegner/df72409bc9c54728942f3e57f1f8d1c8 to your computer and use it in GitHub Desktop.
Save josephwegner/df72409bc9c54728942f3e57f1f8d1c8 to your computer and use it in GitHub Desktop.
Traffic Simulation DX
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