You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "qz0610 (via GitHub)" <gi...@apache.org> on 2024/12/01 01:47:50 UTC
Re: [PR] Fix Flaky Tests [commons-jxpath]
qz0610 commented on PR #205:
URL: https://github.com/apache/commons-jxpath/pull/205#issuecomment-2509518686
Hi @garydgregory, thank you very much for the review and feedback. For these two failures,
```
[ERROR] BeanModelTest>BeanModelTestCase.testBooleanPredicate:681->JXPathTestCase.assertXPathValueIterator:152 Evaluating value iterator <//self::node()[name(.) = concat('n', 'a', 'm', 'e')]> expected:<[Name 1, Name 2, Name 3, Name 6, Name 0, Name 5, Name 4]> but was:<[Name 1, Name 2, Name 3, Name 6, Name 0, Name 5]>
[ERROR] BeanModelTest>AbstractBeanModelTest.testBooleanPredicate:681->AbstractJXPathTest.assertXPathValueIterator:151 [hashCode()] Evaluating value iterator <//self::node()[name(.) = concat('n', 'a', 'm', 'e')]>, expected.class class java.util.ArrayList(7): [Name 1, Name 2, Name 3, Name 6, Name 0, Name 5, Name 4], actual.class class java.util.ArrayList(8): [Name 1, Name 2, Name 3, Name 6, Name 0, Name 5, Name 4, Name 4] expected:<948329621> but was:<1659447818>
```
the order of elements in Hashset is not always guaranteed, when each time it's passed to `getValue(Object collection, final int index)`; i.e. an element in Hashset doesn't have an absolute index. For example,
```
getValue(collection: {String 4, 4, Nested: Name 4}, index: 0) -> String 4
getValue(collection: {Nested: Name 4, String 4, 4}, index: 1) -> String 4
getValue(collection: {String 4, Nested: Name 4, 4}, index: 2) -> 4
```
In this case getValue() could not retrieve `Nested: Name 4` correctly, and thus cause the above errors of missing element and changed hashcode in the resulting ArrayList. If we replace Hashset with LinkedHashset, `Nested: Name 4` would always have index 2 and is guaranteed to be retrieved, therefore resolving the failures.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org