-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Test] Refactored test to use utility function to get annotation instead of array indexing #1149
Conversation
support/cdi/src/test/java/org/apache/shiro/cdi/AnnotatedTypeWrapperTest.java
Outdated
Show resolved
Hide resolved
@wang3820 Can you please squash the commits? Thank you! |
@wang3820 I have looked a little deeper into this. I believe it's a false positive actually. Let me know if you still want me to merge this PR or just close it. |
Let me look deeper into this too. Nondex should never shuffle order of elements in a LinkedHashMap |
Even so, your change makes it obvious what is going on (e.g. looking for a specific annotation class vs just grabbing one by index) |
The other issue is that the test uses indexes in the whole code, not just this piece. Do we want to change the whole test to be consistent? |
It appears that the test is no longer flaky. I think I was testing on a older version. |
I think it's a good idea to change the whole test. This way the test is more readable. |
@wang3820 are you willing to take that on? |
Yes. |
@wang3820 Awesome job! Thank you! |
…ead of array indexing
Thanks @wang3820! |
Following this checklist to help us incorporate your contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a GitHub issue. Your pull request should address just this issue, without pulling in other changes.
[#XXX] - Fixes bug in SessionManager
,where you replace
#XXX
with the appropriate GitHub issue. Best practiceis to use the GitHub issue title in the pull request title and in the first line of the commit message.
fixes #XXX
if merging the PR should close a related issue.mvn verify
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.git rebase -i
.Trivial changes like typos do not require a GitHub issue (javadoc, comments...).
In this case, just format the pull request title like
[DOC] - Add javadoc in SessionManager
.If this is your first contribution, you have to read the Contribution Guidelines
If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement
if you are unsure please ask on the developers list.
To make clear that you license your contribution under the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
Flakiness
Nondex was used to check and locate the flakiness in the test. The test can be reproduced using the following command:
mvn install -pl support/cdi -am -DskipTests mvn -pl support/cdi test -Dtest=org.apache.shiro.cdi.AnnotatedTypeWrapperTest#removeAnnotations mvn -pl support/cdi edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.shiro.cdi.AnnotatedTypeWrapperTest#removeAnnotations
Issue
The test checks that if there is no
Annotation
in theRequiresGuest
class and there isAnnotation
inSessionScoped
class. It retrieves these classes by callinggetDeclaredAnnotations
method and fix indexing on the array returned. This creates the problem. Here is the implementation ofgetDeclaredAnnotations
:Since the array is created from a hashmap, the order of elements in the output of
getDeclaredAnnotations
is not determinstic. Therefore, the fix indexing creates flakiness.Fix
Since only
SessionScoped
andRequiresGuest
are tested, those 2 classes are specificly extracted from the array instead of using indexing.