KNOX-3069 - Fix Flakey Test - TokenServiceResourceTest #938
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
TokenServiceResourceTest - testLimitingTokensPerUser method acquires many tokens within a tight for loop and does not insure that the tokenIds are unique.
This results in test failures for the unlimited tokens per user on certain machines.
This may also point to a larger concurrency problem which needs investigation. Will file a separate JIRA for this. This may be an issue with the test or the UUID use for the tokenID in general. In the meantime, we can't have builds failing on certain machines.
This change interrogates the response and adds an assertion to ensure that the tokenId is unique. It seems the time spent in doing the check "fixes" the failures. The same "fix" was accomplished with a sleep of 1ms between token acquisitions.
How was this patch tested?
Prior to this fix the following test failure was encountered for every run on my local machine:
[ERROR] Tests run: 60, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.113 s <<< FAILURE! - in org.apache.knox.gateway.service.knoxtoken.TokenServiceResourceTest
[ERROR] testUnlimitedTokensPerUser(org.apache.knox.gateway.service.knoxtoken.TokenServiceResourceTest) Time elapsed: 0.118 s <<< FAILURE!
java.lang.AssertionError: expected:<94> but was:<105>
at org.apache.knox.gateway.service.knoxtoken.TokenServiceResourceTest.testLimitingTokensPerUser(TokenServiceResourceTest.java:1145)
at org.apache.knox.gateway.service.knoxtoken.TokenServiceResourceTest.testLimitingTokensPerUser(TokenServiceResourceTest.java:1110)
at org.apache.knox.gateway.service.knoxtoken.TokenServiceResourceTest.testUnlimitedTokensPerUser(TokenServiceResourceTest.java:1046)
This change looks for the root cause of the failure but also introduces a time lag between token acquisitions such that the tokenIDs are indeed unique.