如何循环加注注入?

时间:2017-01-20 23:02:48

标签: gatling

我已经建模了一些我希望针对我们的网络应用运行的使用模式,而我想要做的是将这种模式一遍又一遍地循环。尽管如此,我还没有找到合适的组合。

val scn: ScenarioBuilder = scenario("Issue Cert Request")
    .exec(http("enroll_child_actor").post("/v1/actor/enroll")
        .body(StringBody(session => createRequestActorBody(getActorId(session.userId))))
        .header("Content-Type","text/plain")
        .header("Authorization", jwt => "ID " + TokenGenerator.get().generateOneTimeUseToken(uberActorSubjectName, Array("ots"), "http://localhost",
          uberActorPrivateKey, uberActorIdentityCert).getEncoded)
        .check(jsonPath("$.identityCertificate").saveAs("childIdCert"),
          jsonPath("$.secureEndpointCertificate").saveAs("childEndpointCert")
        )
    ).exec(http("request_secure_endpoint_certificate").post("/v1/cert/issue")
    .body(StringBody(createRequestCertBodySecureEndpoint))
    .header("Content-Type","text/plain")
    .header("Authorization", session => "ID " + TokenGenerator.get.generateTokenForActor(s"CN=http://localhost,UID=ots:${getActorId(session.userId)}", actorSecureEndpointKeyPair.getPrivate, CaCryptoUtils.certFromPemText(session.get("childEndpointCert")
      .as[String])).getEncoded)
  ).exec(http("request_identity_certificate").post("/v1/cert/issue")
    .body(StringBody(createRequestCertBodySecureEndpoint))
    .header("Content-Type","text/plain")
    .header("Authorization", session => "ID " + TokenGenerator.get.generateTokenForActor(s"CN=http://localhost,UID=ots:${getActorId(session.userId)}", actorIdentityKeyPair.getPrivate, CaCryptoUtils.certFromPemText(session.get("childIdCert").as[String]))
      .getEncoded)
  )

这是我的测试运行的地方,这些步骤是我想重复的。我已尝试对场景本身进行重复(上图),但看起来它会重复会话,以便session.userId在我测试的应用程序中复制和出错(我在其中使用它的字段)必须是独一无二的。)

setUp {
  scn.inject(nothingFor(4 seconds),
    rampUsersPerSec(2) to usersMax during(durationAtMaxInSecs seconds),
    constantUsersPerSec(usersConstant) during(durationAtLowerInSecs seconds),
    nothingFor(3000 seconds)
  ).protocols(httpConf)
}

如果不能一次又一次地复制和粘贴注射,我怎样才能让这些步骤重复指定的次数?

1 个答案:

答案 0 :(得分:1)

与您正在寻找的相似,希望下面有所帮助,我已删除了一些信息: -

val vrScn = scenario("Requests").feed(orderRefs).group("Groups") {
//See this logic how to Short Circuit              
asLongAs(session => jobsQue.length > 0) { 
  exec { session =>
    var requestIdValue = new scala.util.Random().nextInt(Integer.MAX_VALUE).toString();
    var length = jobsQue.length
    try {
      var reportElement = jobsQue.pop()
    //Other variables
    } catch {
      case e: NoSuchElementException => print("Erorr")
    }

    //Set what you want to set 
    session.setAll(
      "reportsRuntimeInfos" -> "FIRST_REQUEST",
      "xmlRequest" -> xml)
  }

    .group("${requestedPageSize} Page Report") {
      group("${requestIdValue}") {
        exec(
          http("Request Report")
            .put(Configuration.URL + "/endpoint1")
            .header("Content-Type", "application/xml")
            .body(StringBody("${xmlRequest}"))
            .check(status.is(200)))
          .pause(Configuration.THINK_TIME_AFTER_PUT second)
          //See this logic how to Short Circuit
          .asLongAs(session => (!ALL_STOP_STATUS.contains(session.attributes("responseStatus")) && session.attributes("statusCode") == 200 && session.attributes("reportsRuntimeInfos") != "")) {
            exec(
              http("Poll")
                .get(Configuration.URL + "/endpoint2") ))
          }

      }
    }
}

  setUp(scn.inject(atOnceUsers(Configuration.NO_OF_USERS))).maxDuration(Configuration.MAX_DURATION minutes);
相关问题