Skip to content

Instantly share code, notes, and snippets.

@itsjohncs
Created November 18, 2012 20:24
Show Gist options
  • Save itsjohncs/4107213 to your computer and use it in GitHub Desktop.
Save itsjohncs/4107213 to your computer and use it in GitHub Desktop.
Gatling Bug
from flask import Flask, session, redirect, url_for, escape, request
import logging
app = Flask(__name__)
@app.route('/')
def index():
if 'username' in session:
app.logger.info('%s has arrived.', escape(session['username']))
return 'Logged in as %s' % escape(session['username'])
app.logger.info('anonymous has arrived')
return 'You are not logged in'
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
session['username'] = request.form['username']
app.logger.info('%s logged in.', request.form['username'])
return redirect(url_for('index'))
return '''
<form action="" method="post">
<p><input type=text name=username>
<p><input type=submit value=Login>
</form>
'''
@app.route('/logout')
def logout():
# remove the username from the session if it's there
session.pop('username', None)
return redirect(url_for('index'))
app.secret_key = "applesauce"
app.debug = True
app.run()
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._
class RecordedSimulation extends Simulation {
def apply = {
val httpConf = httpConfig
.baseURL("http://localhost:5000")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0")
.hostHeader("localhost:5000")
val headers_1 = Map(
"Cache-Control" -> """max-age=0"""
)
val headers_3 = Map(
"Content-Type" -> """application/x-www-form-urlencoded"""
)
val scn = scenario("Scenario Name")
.exec(http("request_1")
.get("/")
.headers(headers_1)
)
.pause(4)
.exec(http("request_2")
.get("/login")
)
.pause(6)
.exec(http("request_3")
.post("/login")
.headers(headers_3)
.param("""username""", """myname""")
.check(
regex("""Logged in as myname""")
)
)
List(scn.configure.users(1).protocolConfig(httpConf))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment