2
votes

I'm trying to mimic a periodic token refresh. We have javascript code in our frontend that periodically checks if a token refresh needs to occur, and if so, issues a call to refresh the token. This is ran every couple minutes or so as long as anyone is using the application.

The typical user of our application will leave the app open without doing anything on it for time greater than the token lifetime. So I can't simply check and perform a token refresh on each call without adjusting the script to not mimic real life usage (because calls would need to occur more frequently).

Any ideas if, or how, this could be possible?

1

1 Answers

1
votes

Okay, the best solution I could come up with was essentially to create my own "Pause" class, that breaks long pauses down into small pauses, and between each checks to see if the token needs refreshed. Looks roughly like this:

//new RefreshADToken().create() creates a ChainBuilder that refreshes the token if it's necessary
object PauseHelpers {

  val tooBigOfPauseThreshold = 150 //300 seconds = 5 minutes, so anything over 150 is too big

  def adPause(duration: Int): ChainBuilder = {
    doIfOrElse(duration > tooBigOfPauseThreshold) {
      val iterations = duration / tooBigOfPauseThreshold
      repeat(iterations, "pause_counter") {
        pause(tooBigOfPauseThreshold)
          .exec(new RefreshADToken().create())

      }.pause(duration % tooBigOfPauseThreshold).exec(new RefreshADToken().create())
    } {
      pause(duration).exec(new RefreshADToken().create())
    }
  }
}
//... then
import orhub.modules.actions._

class POC extends Simulation {
//some stuff
  var scn = scenario("poc")
    .feed(hospitalUsersFeeder)
    .exec(session => {
        session.set("env", environment)
    })
    .exec(new ADPause(120 * 60).create())