Очень часто в различных проектах присутствует необходимость в создании тестов на проверку производительности системы. Как правило, для реализации подобной задачи, специалистам необходимо создавать и описывать правила работы с приложением с нуля. В своем докладе я расскажу, как это можно упростить эту задачу, на примере использования инструмента для нагрузочного тестирования Gatling
2. 2
Email: anton_shapin@epam.com
Skype: anton_shapin
GIT: http://github.com/kirlionik
Shapin Anton
Lead Software Test Automation Engineer.
Areas of my competency: manual, test
automation, performance and etc.
#
11+ years in IT.#
QA trainer at Epam.
6. 6
GATLING
Gatling is a highly capable load testing tool. It
is designed for ease of use, maintainability and
high performance. It supports HTTP/S, JMS,
and JDBC protocols.
Gatling’s architecture is asynchronous as long as the underlying
protocol, such as HTTP, can be implemented in a non blocking way. This
kind of architecture lets us implement virtual users as messages instead
of dedicated threads, making them very resource cheap. Thus, running
thousands of concurrent virtual users is not an issue.
16. 16
General structure of Gatling tests
Load profile
Section setUp of Simulation class.
Test logic /Business logic
Scenario object. It describes user
actions.
Test data generation
Java or Scala classes.
Http protocol configuration
Section HttpConf of Simulation
class.
17. 17
General structure of Gatling tests
Test data generation
Java or Scala classes.
@Component @Lazy
class VoucherCode @Autowired()(voucherSteps: VoucherTokensSteps, baseInfo: GeneralSteps) {
private val logger: Logger = LoggerFactory.getLogger(classOf[VoucherCode])
private val path: String = voucherSteps.getVoucherService.getPathVoucher
private val jsonListVouchers: List[String] = {
logger.info(s"Get list of json files with voucher codes")
val vouchers = voucherSteps.getJsonsForVoucherCodes(700, baseInfo.getDefaultUser)
JavaConverters.asScalaBufferConverter(vouchers).asScala.toList
}
18. 18
General structure of Gatling tests
Test logic /Business logic
Scenario object. It describes users
actions.
val scenarioVouchers = {
scenario("Applying voucher сodes")
.feed(buildFeeder(jsonListVouchers))
.exec(http("Applying voucher сodes")
.post(path)
.body(StringBody("${body}")).asJSON
.check(status.is(201))
)
}
private def buildFeeder(jsons:
List[String]) = {
(for (json <- jsons) yield Map("body" ->
json))
.toArray
.shuffle
}
19. 19
General structure of Gatling tests
Load profile
Section setUp of Simulation
class.
class TestSimulation extends Simulation {
setUp(
appValidVoucherCodes.scenarioValidVoucherCodes.inject(constantUsersPerSec(1)
during (2 minutes)),
appInvalidVoucherCode. scenarioInValidVoucherCodes.inject(constantUsersPerSec(1)
during (2 minutes))
).protocols(httpConf)
}
20. 20
Summary
1. This approach was tested on 3 projects and has
established itself as an effective one.
2. It’s a great tool for learning about performance testing.
3. This approach reduces the time to create and support
performance tests.
4. Enables easy integration of performance testing with CI
process.
21. 21
Thank you for attention!
Email: anton_shapin@epam.com
Skype: anton_shapin
GIT: http://github.com/kirlionik