使用随机 ${orgId} 随机化 Post body 的 eventId 但由于输入无效而出错

Tk 信息串

我正在尝试使用 orgId 生成一个随机 eventid,但出现以下错误,此错误明确指出输入到事件的数据无效,当我将 evnet id 更改为 1 时,代码工作正常,仅当我尝试对其进行随机化时,我收到以下错误消息

14:59:36.475 [WARN ] i.g.h.a.ResponseProcessor - Request 'CreateEventRound-GameKeeper' failed: status.find.in(200,201), but actually found 400
Session(Game Keeper Post Orgs ,1,Map(access_token -> eyJhbGciOiJSUzI1NiIsImtpZCI6IjM0NmM4YTY1NTBlZGI5MDRjM2IyNWI3ODlmOTllNjU3ODA4MGJiOTUiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJpa3J3dWdoMzg3MWdodzhyZ243cTgzZ2giLCJleHAiOjE1NTU0NTI4NjgsImlhdCI6MTU1NTQ1MTk2OCwiaXNzIjoiNzZIRktZNzVHUkEyTFBHQ1pETVZYUTY2SEEiLCJzdWIiOiJZTUdDWFA2SVVCSE9QRkdLNDVYUUdON1RWNCIsIndvdGMtbmFtZSI6IktvemlsZWtzVHJhbnNsYXRvckRldiM1MjIxMyIsIndvdGMtZG9tbiI6InRhYmxldG9wIiwid290Yy1nYW1lIjoiZXZlbnRyZXBvcnRlcmRldiIsIndvdGMtZmxncyI6MCwid290Yy1yb2xzIjpbXSwid290Yy1wcm1zIjpbXSwid290Yy1zY3BzIjpbImZpcnN0LXBhcnR5Il19.SqMnINmD7q2FC1Zyf34xbaWOP3LhRtdbL44ZkY3vDKa2-E2yEv4fX1-f8dJTWzOVDNOJYLkHZCrKu8YkVqvO1u9RP5d-Kyfpm1GMVqV9duFPKOuRkgg6p8xxDy3jg0o-ItMZa3fYNNe-3GQ2BdGmxPv7fnoov-OSIY6F7XQAEdnGUc5uMxID_4BrKYZmpBDuzi3LPPaUJeHGdh_nOJvhq-sIUHFmIpp3e70VE9xLvjQ8uS8vJI1fGCq7tDvpXtFFtCPTQ05LLD_SIvt2uPULn80SHA8aH37cI0Zpu4eeDyy0sBjRSPXSK8vKEwhUDsbt_u02s-8O9BPeCJ4RLu8EfQ, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@319ab5e5, gatling.http.cache.contentCache -> io.gatling.core.util.cache.Cache@619cf254, token_type -> Bearer, orgId -> 29, eventId -> ["The input was not valid.","The input was not valid."], 721cad9b-2343-46f4-8f2f-766319bc197b -> 8, e803e068-608b-4826-a7ab-7f7eff07fadb -> 0),1555451967893,23,KO,List(ExitOnCompleteLoopBlock(721cad9b-2343-46f4-8f2f-766319bc197b), ExitOnCompleteLoopBlock(e803e068-608b-4826-a7ab-7f7eff07fadb)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$412/1842952737@70e2ec5d)
14:59:37.484 [WARN ] i.g.h.a.ResponseProcessor - Request 'CreateEventRound-GameKeeper' failed: status.find.in(200,201), but actually found 400
 Session(Game Keeper Post Orgs ,1,Map(access_token -> eyJhbGciOiJSUzI1NiIsImtpZCI6IjM0NmM4YTY1NTBlZGI5MDRjM2IyNWI3ODlmOTllNjU3ODA4MGJiOTUiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJpa3J3dWdoMzg3MWdodzhyZ243cTgzZ2giLCJleHAiOjE1NTU0NTI4NjgsImlhdCI6MTU1NTQ1MTk2OCwiaXNzIjoiNzZIRktZNzVHUkEyTFBHQ1pETVZYUTY2SEEiLCJzdWIiOiJZTUdDWFA2SVVCSE9QRkdLNDVYUUdON1RWNCIsIndvdGMtbmFtZSI6IktvemlsZWtzVHJhbnNsYXRvckRldiM1MjIxMyIsIndvdGMtZG9tbiI6InRhYmxldG9wIiwid290Yy1nYW1lIjoiZXZlbnRyZXBvcnRlcmRldiIsIndvdGMtZmxncyI6MCwid290Yy1yb2xzIjpbXSwid290Yy1wcm1zIjpbXSwid290Yy1zY3BzIjpbImZpcnN0LXBhcnR5Il19.SqMnINmD7q2FC1Zyf34xbaWOP3LhRtdbL44ZkY3vDKa2-E2yEv4fX1-f8dJTWzOVDNOJYLkHZCrKu8YkVqvO1u9RP5d-Kyfpm1GMVqV9duFPKOuRkgg6p8xxDy3jg0o-ItMZa3fYNNe-3GQ2BdGmxPv7fnoov-OSIY6F7XQAEdnGUc5uMxID_4BrKYZmpBDuzi3LPPaUJeHGdh_nOJvhq-sIUHFmIpp3e70VE9xLvjQ8uS8vJI1fGCq7tDvpXtFFtCPTQ05LLD_SIvt2uPULn80SHA8aH37cI0Zpu4eeDyy0sBjRSPXSK8vKEwhUDsbt_u02s-8O9BPeCJ4RLu8EfQ, gatling.http.cache.dns -> io.gatling.http.resolver.ShuffleJdkNameResolver@319ab5e5, gatling.http.cache.contentCache -> io.gatling.core.util.cache.Cache@619cf254, token_type -> Bearer, orgId -> 30, eventId -> ["The input was not valid.","The input was not valid."], 721cad9b-2343-46f4-8f2f-766319bc197b -> 9, e803e068-608b-4826-a7ab-7f7eff07fadb -> 0),1555451967893,17,KO,List(ExitOnCompleteLoopBlock(721cad9b-2343-46f4-8f2f-766319bc197b), ExitOnCompleteLoopBlock(e803e068-608b-4826-a7ab-7f7eff07fadb)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$412/1842952737@70e2ec5d)

 ================================================================================
 2019-04-16 14:59:37                                          16s elapsed
 ---- Requests ------------------------------------------------------------------
> Global                                                   (OK=3      KO=10    )
> Event-Reservations-Web-Image-Login                       (OK=1      KO=0     )
> Http Header Token Authentication Url                     (OK=1      KO=0     )
> Token Generation Url For Post                            (OK=1      KO=0     )
> CreateEventRound-GameKeeper                              (OK=0      KO=10    )
---- Errors --------------------------------------------------------------------
> status.find.in(200,201), but actually found 400                    10 (100.0%)

这是代码

val usersDataSource  =jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/dat 
 a/input-gamekeeper.json").circular
  val nameDataSource
=jsonFile("C:/Gatling2/gatling3james/src/gatling/resources/data 

 /input-gamekeeper-StringBody.json").random

  var idNumbers=(21 to 33).iterator

  def getNextOrgId()=
 {
    if(!idNumbers.hasNext)
    idNumbers=(21 to 33).iterator
    Map("orgId"->idNumbers.next())
 }

val customFeeder=Iterator.continually(getNextOrgId())

def createEventRound()={
repeat(990000000){

  exec(flushHttpCache)
  feed(customFeeder)
    .exec(http("CreateEventRound-GameKeeper")

      //exec(http("CreateEventRound-GameKeeper")
      .post("https://api.tabletop-stage.tiamat-origin.cloud/dev/gamekeeper/Round")
      .headers(headers_10)


       .body(StringBody(session =>
       """
         |{
         |  "eventId": ${orgId},
         |  "roundStart": "2019-04-16T18:22:50.388Z",
         |  "roundEnd": "2019-04-16T18:22:50.388Z",
         |  "currentTime": "2019-04-16T18:22:50.388Z",
         |  "roundNumber": 1,
         |  "matches": [
         |    {
         |      "matchId": 0,
         |      "isBye": true,
         |      "tableNumber": "string",
         |      "teams": [
         |        {
         |          "teamId": 0,
         |          "teamName": "string",
         |          "players": [
         |            {
         |              "personaId": "string",
         |              "displayName": "string"
         |            }
         |          ]
         |        }
         |      ]
         |    }
         |  ]
         |}
    """.stripMargin)).asJSON

      .check(status.in(200,201))//checkforaspecificstatus
      .check(jsonPath(path="$.roundNumber").is("1"))
      .check(jsonPath(path="$.eventId").saveAs(key="eventId")))
     // 
 .check(jsonPath(path="$.displayName").
saveAs(key="displayName")))//checkforaspecificstatus
    .exec{session=>println(session);session}
 //parameterfortheorgIdgoeshere
    .pause(1)

}

}

  // add a scenario
  val scenario2 = scenario("Game Keeper Post Orgs ")
 .exec(http("Event-Reservations-Web-Image-Login")
  .get("https://api.origin.cloud/dev/event-reservations- 

 web/img/loading.dfbfd678.svg")
  .headers(headers_1)
  .resources(http("Http Header Token Authentication Url")
    .options(uri03 + "/auth/oauth/token")
    .headers(headers_7),
    http("Token Generation Url For Post")
      .post(uri03 + "/auth/oauth/token")
      .headers(headers_8)
      .formParam("grant_type", "password")
      .formParam("username", "[email protected]")
      .formParam("password", "fJC2RuVdvmHB")
      .basicAuth("ikrwugh3871ghw8rgn7q83gh","NbnEEqmDLSfno315o87ghFGYr3jybtzbi76sr")
      .check(jsonPath("$.access_token").exists.saveAs("access_token"))
      .check(jsonPath("$.token_type").exists.saveAs("token_type"))
  ))
.forever() { // add in the forever() method - users now loop forever
  exec(createEventRound())
}

  // setup the load profile
  // example command line: ./gradlew gatlingRun- 
simulations.RuntimeParameters -DUSERS=10 -DRAMP_DURATION=5 -DDURATION=30
setUp(

scenario2.inject(
  nothingFor(5 seconds),
  rampUsers(userCount) over ( rampDuration ))
  .protocols(httpConf))


.maxDuration(testDuration)

}

请注意,如果我只是用 1 删除 ${orgId},代码工作正常,但只有我在使用 ${orgId} 时看到错误,请指出我哪里出错了?

詹姆斯·瓦尔

我怀疑您的问题在于您使用

.body(StringBody(session =>

在“createEventRound”中,导致提交字符串文字“${orgId}”

在您的示例中,您不想对会话值进行任何手动操作,您只想检索 ${orgId} 的值。您可以通过向 StringBody 提供一个 Expression 字符串来做到这一点。

所以...

.body(StringBody( """
     |{
     |  "eventId": ${orgId},
     ...
     }""".stripMargin)).asJSON

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章