前提
- Yosemite
- Rails 4.1.4
- Railsのログイン認証はDevise
- Gatling 2.0.0
準備
GatlingのサイトからLatest releaseのGatling bundleをダウンロード
テスト用のコード作成し、user-files以下に配置
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class Test1 extends Simulation {
val basicAuthUser = "basic認証のユーザ"
val basicAuthPassword = "basic認証のパスワード"
val authUser = "ログインメールアドレス"
val authPassword = "password0001"
val baseUrl = "https://example.com/"
val paramNameLogin = "user[email]"
val paramNamePassword = "user[password]"
object Login {
val login = exec(http("request_0")
.get("""/admin/login""")
.basicAuth(basicAuthUser, basicAuthPassword)
.check(regex("""<meta content="(.*?)" name="csrf-token" />""")
.saveAs("auth_token")))
.exec(http("request_1")
.post("""/admin/login""")
.header("X-CSRF-Token", "${auth_token}")
.formParam(paramNameLogin, authUser)
.formParam(paramNamePassword, authPassword)
.basicAuth(basicAuthUser, basicAuthPassword)
.check(status.is(200)))
}
object Shop {
val headers_0 = Map(
"""Accept""" -> """text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8""",
"""Cache-Control""" -> """max-age=0""")
val headers_1 = Map("""Cache-Control""" -> """max-age=0""")
val shops = exec(http("request_2")
.get("""/admin/shops""")
.basicAuth(basicAuthUser, basicAuthPassword)
.check(status.is(200)))
}
val httpProtocol = http
.baseURL(baseUrl)
.inferHtmlResources()
.acceptHeader("""image/webp,*/*;q=0.8""")
.acceptEncodingHeader("""gzip, deflate, sdch""")
.acceptLanguageHeader("""en-US,en;q=0.8,ja;q=0.6""")
.userAgentHeader("""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36""")
val scn = scenario("Login").exec(Login.login)
val scn2 = scenario("Shop").exec(Shop.shops)
setUp(
scn.inject(atOnceUsers(1)),
scn2.inject(atOnceUsers(5))
).protocols(httpProtocol)
}
実行
bin/gatling.sh -sf user-files/ -s Test1