[ 
https://issues.apache.org/jira/browse/WICKET-7088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Martin Tzvetanov Grigorov resolved WICKET-7088.
-----------------------------------------------
    Fix Version/s: 10.0.0-M3
         Assignee: Martin Tzvetanov Grigorov
       Resolution: Fixed

Merged to 10.x!

I won't backport it to 9.x because it may break someone's application.

> Improve test reliability by resolving nondeterministic order of Set and Map
> ---------------------------------------------------------------------------
>
>                 Key: WICKET-7088
>                 URL: https://issues.apache.org/jira/browse/WICKET-7088
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-core
>    Affects Versions: 10.0.0-M2, 9.16.0
>         Environment: Reproduce
> This error can be reproduced with the NondexTool with the following command 
> (you can try that without modifying the pom, but feel free to use the plugin 
> to protect your project and make it safer 😊 ), and this kind problem is 
> widely documented in International Dataset of Flaky Tests (IDoFT)
> mvn edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -pl 
> ./wicket-core-tests -DnondexRuns=10 
> -Dtest=org.apache.wicket.markup.html.form.CollectionFormComponentTest#getSetUnmodifiableSet
> Most similar Similar issues
> FasterXML/jackson-jaxrs-providers#154
> https://github.com/FasterXML/jackson-annotations/pull/194/files
>            Reporter: huiyang chi
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 10.0.0-M3
>
>
> The related PR had been approved  : 
> [https://github.com/apache/wicket/pull/707] :):):)
> h1. Problem
> In the test getSetUnmodifiableSet and getSetNullList, we use a set to 
> intitialize our choice, and assume it will have the order with 
> getDefaultModelObjectAsString to be [A, B], but this is not necessary true 
> according to [Oracle's official 
> document|https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html#:~:text=It%20makes%20no%20guarantees%20as%20to%20the%20iteration%20order%20of%20the%20set%3B%20in%20particular]
>  
> For the test renderAjaxAttributes, we create the Json string from the 
> AjaxRequestAttributes and assume the order of the fields in tests which is 
> not true because it serialize from extraParameters which was a HashMap, which 
> did not guarantee any order and will cause non-deterministic when we change 
> the environments like JDK version. Also the LinkedHashMap is designed with 
> specification to guarantee the order to resolve this kind of problem
> h1. Solution
> Use LinkedHashMap
> This problem had encountered and solved in wicket the same way before :
> [wicket/wicket-core/src/main/java/org/apache/wicket/ajax/json/README|https://github.com/apache/wicket/blob/b243eca31ab4a0ab78159fd2ccf7337a38b94840/wicket-core/src/main/java/org/apache/wicket/ajax/json/README#L4-L6]
> Lines 4 to 6 in 
> [b243eca|https://github.com/apache/wicket/commit/b243eca31ab4a0ab78159fd2ccf7337a38b94840]
> ||IMPORTANT: JSONObject#map field is manually changed to LinkedHashMap (from 
> HashMap) to keep||
> ||the order of the ajax attributes consistent for WicketTester based unit 
> tests||
>  
>  
> h1. Affected Tests
>  
> [INFO] 
> org.apache.wicket.markup.html.form.CollectionFormComponentTest#getSetUnmodifiableSet
> [INFO] 
> org.apache.wicket.markup.html.form.CollectionFormComponentTest#getSetNullSet
> [INFO] 
> org.apache.wicket.ajax.AbstractDefaultAjaxBehaviorTest#renderAjaxAttributes
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testCallbackFunctionWithConverted
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testCallbackFunctionWithExplicit
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testCallbackFunctionWithAll
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testCallbackFunctionWithContext
> [INFO] org.apache.wicket.ajax.AjaxCallbackFunctionTest#testJQueryUIEvent
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testCallbackFunctionWithResolved
> [INFO] 
> org.apache.wicket.ajax.AjaxCallbackFunctionTest#testDefaultCallbackFunction



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to