使用随机$ {orgId}对Post body的eventId进行随机化,但输入错误为输入无效

问题描述 投票:0回答:1

我试图用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}时才会看到错误,请提示我哪里出错?

gatling scala-gatling
1个回答
0
投票

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

.body(StringBody(session =>

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

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

所以...

.body(StringBody( """
     |{
     |  "eventId": ${orgId},
     ...
     }""".stripMargin)).asJSON
© www.soinside.com 2019 - 2024. All rights reserved.