Authorisation token expires too soon
- 4 years ago
The acquisition of a new access token is very slow so I can't afford to have it inside the loop. As you can see from the code snippet below I request for a new token and then wait in a loop till I have one:
def oldToken = oAuthProfile.getAccessToken();
def oAuthClientFacade = new OltuOAuth2AzureClientFacade (TokenType.ACCESS);
oAuthClientFacade.requestAccessToken(oAuthProfile, true,true);while(oldToken == oAuthProfile.getAccessToken())
{
sleep(100);
}I'm pretty happy with what I've got now:
I get the access token in the TestRunListener.beforeRun event which also sets a test case property "Duration" to the time I want to wait till I need another token.
Inside the test loop, in my groovy asserts script, I check if the test has been running for a time exceeding the Duration property, and if yes, I get a new access token and increment the Duration property