Gatling使用Gradle插件运行多个模拟

时间:2017-01-20 10:21:48

标签: gradle gatling

Gradle插件(https://github.com/commercehub-oss/gatling-gradle-plugin,v2.1)声称The ability to configure multiple simulations per gradle project

给出以下gradle文件:

apply plugin: 'scala'

group '****'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.commercehub:gatling-gradle-plugin:2.1'
    }

}

repositories {
    jcenter()
}

ext {
    SCALA_VERSION = "2.11.7"
    GATLING_VERSION = "2.2.3"
}

dependencies {
    compile "org.scala-lang:scala-library:${SCALA_VERSION}"

    testCompile 'com.typesafe:config:1.3.1'
    testCompile "io.gatling.highcharts:gatling-charts-highcharts:${GATLING_VERSION}"
    testCompile "io.gatling:gatling-test-framework:${GATLING_VERSION}"
}


apply plugin: 'gatling'

import com.commercehub.gradle.plugin.GatlingTask
task loadTest(type: GatlingTask, dependsOn: ['testClasses']) {
    gatlingSimulation = 'HealthSimulation,PlaceAttributesSimulation'
    jvmOptions {
        jvmArgs = [
            "-Dlogback.configurationFile=${logbackGatlingConfig()}",
            "-Denv=${System.getProperty('env', 'stg')}",
        ]
        minHeapSize = "1024m"
        maxHeapSize = "1024m"
    }
}

def logbackGatlingConfig() {
    return sourceSets.test.resources.find { it.name == 'logback-gatling.xml' }
}

特别是行gatlingSimulation = 'HealthSimulation,PlaceAttributesSimulation',我希望两个模拟都可以运行。为什么?因为查看Gradle插件,gatlingSimulation会传递给Gatling -s标记。

长话短说,Gatling -s不再支持多个模拟了(详情请参阅https://github.com/gatling/gatling/issues/363),所以我想我在gradle插件中缺少一点,我用来启用多个模拟。

两个模拟在单独运行时运行正常,但如果我尝试一起运行它们,Gatling就会问到要执行哪一个。任何建议如何在同一个gradle项目中实现(顺序)运行多个模拟?

编辑:我目前难看的解决方法(建议欢迎使其不那么难看,但仍然是解决方法)是用以下方法修改Gradle构建文件:

task loadTests;
fileTree(dir: 'src/test').include("**/*Simulation.scala").each {target ->

    ext {
        filename = target.toString()
        filename = filename.substring(filename.indexOf("scala") + "scala".length() + 1)
        filename = filename.substring(0, filename.indexOf(".")).replaceAll("/", ".")
    }

    task("loadTest${filename}", type: GatlingTask, dependsOn: 'testClasses', description : "Load test ${filename}s") {
        gatlingSimulation = filename
        jvmOptions {
            jvmArgs = [
                "-Dlogback.configurationFile=${logbackGatlingConfig()}",
                "-Denv=${System.getProperty('env', 'stg')}",
            ]
            minHeapSize = "1024m"
            maxHeapSize = "1024m"
        }
    }
    loadTests.dependsOn("loadTest${filename}")
}

def logbackGatlingConfig() {
    return sourceSets.test.resources.find { it.name == 'logback-gatling.xml' }
}

基本上,我为每个GatlingTask文件(命名约定)创建*Simulation.scala,然后创建一个取决于所有文件的批量loadTests任务。

0 个答案:

没有答案
相关问题