Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-7088

Improve test reliability by resolving nondeterministic order of Set and Map

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 10.0.0-M2, 9.16.0
    • 10.0.0
    • wicket-core

    Description

      The related PR had been approved  : https://github.com/apache/wicket/pull/707

      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

       

      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

      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

      Lines 4 to 6 in b243eca

      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

       

       

      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

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              hannahchi huiyang chi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: