Refresh Access Token

I am unable to refresh token. below is my code. After the 2nd minute the proxyToken variable is refreshed and the new value is printed. However the same is not getting passed into the ‘Proxy Service’ header. This works fine for the first time but i am facing issue only from the second call onwards when i need to refresh the token. Please help…

Edit, More info : The print statement prints the new token at the 120th sec(2nd run after the pause) but this new token does not transfer to the api call like it does in the first one(0th second)

var proxyToken = "proxy"

val apiCallSmall = exec( http("Accounts API")
    .get(authzUri.toString)
    .headers(Map(
      "Resource-Scope" -> "Managed",
      "Proxy-Service" -> "${proxyToken}",
      "accept" -> "application/json"
    ))
    .check(status.is(200))
  )

  val smallScenario = scenario("Small Partner scenario")
    .exec(_.set("proxyToken", proxyToken))
    .exec(apiCallSmall)

  val getProxyScenario = scenario("Get proxy token scenario")
.exec(_.set("access_token", generateSSAV2Token()))
.exec(session => {
      proxyToken = session("access_token").as[String]
      println(s"Response body Proxy Scenario is:::::::::::: :::> \n$proxyToken")
      session
    })
    .pause(2.minutes)

Simulation code

setUp(
    getProxyScenario.inject(
        constantConcurrentUsers(1).during(totalDuration.minutes)
      )
      .protocols(httpProtocol),
    getUATScenario.inject(
        constantConcurrentUsers(1).during(totalDuration.minutes)
      )
      .protocols(httpProtocol),
    smallScenario.inject(
        nothingFor(40.seconds),
        atOnceUsers(10)
      )
      .throttle(
        reachRps(1).in(5.seconds),holdFor(5.minutes),
        jumpToRps(1),holdFor(15.minutes)
      )

I have also tried with var and def for all the methods above but still the same

you may want to check here

Shout out to @GeMi

Thank you for replying. I believe i am doing something similar in my code but its not working…

Please provide a full sample. Just reading your partial sample, I can’t spot anything wrong but some pieces are missing.

Thank you for responding. May i know which part you want more clarity on - the parts not shown here are working fine so i didnt share that.

Several persons hava had a look at your code extracts and can’t see the issue.
At this point, we absolutely need a reproducer we can run on our side as described here so we can investigate.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.