Uploaded image for project: 'Apache Curator'
  1. Apache Curator
  2. CURATOR-694

Improve test reliability by resolving nondeterministic order by sorting

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.5.0
    • 5.6.0
    • Framework

    Description

      The related PR has been opened : https://github.com/apache/curator/pull/491

       

      1. Problem

      For these tests:

      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testAdd
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testNewMembersWithEmptyList
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testAddAsync
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testAddAndRemove
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testAddAndRemoveWithEmptyList
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testBasicGetConfig
      [INFO] org.apache.curator.framework.imps.TestReconfiguration#testRemoveWithChroot

      They assume the order of the QuorumServer was same, but this is not necessary the case because QuorumMaj aggressively use Map to store it's data

      ```
          private Map<Long, QuorumPeer.QuorumServer> allMembers = new HashMap();
          private HashMap<Long, QuorumPeer.QuorumServer> votingMembers = new HashMap();
          private HashMap<Long, QuorumPeer.QuorumServer> observingMembers = new HashMap();
      ```
      so because the order of the Map is indeterministic according to the [Oracle's official document](https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html#:~:text=This%20class%20makes%20no%20guarantees%20as%20to%20the%20order%20of%20the%20map), so this might trigger error message in different environments:

      ```
      [ERROR] org.apache.curator.framework.imps.TestReconfiguration.testAdd  Time elapsed: 0.641 s  <<< FAILURE!
      org.opentest4j.AssertionFailedError: expected: <127.0.0.1:55254,127.0.0.1:55251,127.0.0.1:55248,0.0.0.0:55268> but was: <0.0.0.0:55268,127.0.0.1:55251,127.0.0.1:55248,127.0.0.1:55254>
              at org.apache.curator.framework.imps.TestReconfiguration.testAdd(TestReconfiguration.java:281)

      ```

      1. Solution

      So the most precise way to deal with that would be change the configToConnectionString method to make sure when we serialize the configurations, we always get the same result, so that the tests will be safe in different environment (because the order of the map is undefined)

      Attachments

        Issue Links

          Activity

            People

              tison Zili Chen
              hannahchi huiyang chi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: