You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "rRajivramachandran (via GitHub)" <gi...@apache.org> on 2023/11/14 04:50:42 UTC

[PR] Fix flaky tungsten test using comparator [cloudstack]

rRajivramachandran opened a new pull request, #8232:
URL: https://github.com/apache/cloudstack/pull/8232

   ### Description
   
   This PR fixes the non deterministic behaviour of 2 tests. This happens as the tests assume the return value of an API to be ordered when it is actually not guaranteed. This has been detected using [NonDex](https://github.com/TestingResearchIllinois/NonDex) tool.
   
   ### Reproduction of issue
   1. `mvn install -pl plugins/network-elements/tungsten`
   2. `mvn -pl plugins/network-elements/tungsten edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.cloudstack.network.tungsten.service.TungstenApiTest#listTungstenNetworkTest -DnondexMode=ONE`
   
   Failure log:
   ```
   [INFO] Running org.apache.cloudstack.network.tungsten.service.TungstenApiTest
   [ERROR] Tests run: 77, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.35 s <<< FAILURE! - in org.apache.cloudstack.network.tungsten.service.TungstenApiTest
   [ERROR] listTungstenNetworkTest(org.apache.cloudstack.network.tungsten.service.TungstenApiTest)  Time elapsed: 0.007 s  <<< FAILURE!
   java.lang.AssertionError: expected:<[net.juniper.tungsten.api.types.VirtualNetwork@6bab2585, net.juniper.tungsten.api.types.VirtualNetwork@74bdc168]> but was:<[net.juniper.tungsten.api.types.VirtualNetwork@74bdc168, net.juniper.tungsten.api.types.VirtualNetwork@6bab2585]>
   	at org.apache.cloudstack.network.tungsten.service.TungstenApiTest.listTungstenNetworkTest(TungstenApiTest.java:1387)
   
   [ERROR] listTungstenPolicyTest(org.apache.cloudstack.network.tungsten.service.TungstenApiTest)  Time elapsed: 0.002 s  <<< FAILURE!
   java.lang.AssertionError: expected:<[net.juniper.tungsten.api.types.NetworkPolicy@59aa20b3, net.juniper.tungsten.api.types.NetworkPolicy@363f6148]> but was:<[net.juniper.tungsten.api.types.NetworkPolicy@363f6148, net.juniper.tungsten.api.types.NetworkPolicy@59aa20b3]>
   	at org.apache.cloudstack.network.tungsten.service.TungstenApiTest.listTungstenPolicyTest(TungstenApiTest.java:1363)
   ```
   
   ### Root cause
   The test class `org.apache.cloudstack.network.tungsten.service.TungstenApiTest` uses [ApiConnectorMock](https://github.com/apache/cloudstack/blob/05b9b6e2e77b9b633f0fe22aff5f9f3c047b2303/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java#L98) for all tests. The tests `listTungstenNetworkTest`, `listTungstenPolicyTest` use the `list` method of this connector [Tungsten API connector call](https://github.com/apache/cloudstack/blob/main/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenApi.java#L2065) in their respective [tests](https://github.com/apache/cloudstack/blob/05b9b6e2e77b9b633f0fe22aff5f9f3c047b2303/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java#L1362-L1385).
    
   The 3rd party library [juniper-tungsten-api](https://github.com/radu-todirica/tungsten-api/tree/master/net/juniper/tungsten/juniper-tungsten-api/2.0)'s `net.juniper.tungsten.api.ApiConnectorMock`'s `list` method does guarantee the ordering of results. Unfortunately, the source code is not on github for direct inspection. Upon downloading and decompiling the `juniper-tungsten-api-2.0.jar`, it can be seen that this method uses `HashMap.values()` which is unordered, for the population of the returned list. A screenshot has been added below. Decompilation was done using [Java-decompiler](http://www.javadecompilers.com). 
   
   ![image](https://github.com/rRajivramachandran/cloudstack/assets/22187598/a3d2e4dc-fead-4d29-aa10-b6adfbea9eb4)
   
   
   ### Fix
   The test class already defines a comparator to sort objects of `ApiObjectBase` [here](https://github.com/apache/cloudstack/blob/main/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java#L93). This has been used to ensure consistent test behaviour.
   
   
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] build/CI
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [x] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [x] Minor
   - [ ] Trivial
   
   
   ### Screenshots (if appropriate):
   
   
   ### How Has This Been Tested?
   - All tests in the test class pass(`mvn -pl plugins/network-elements/tungsten test -Dtest=org.apache.cloudstack.network.tungsten.service.TungstenApiTest`)
   - All tests in test class pass when run with nondex(`mvn -pl plugins/network-elements/tungsten edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.cloudstack.network.tungsten.service.TungstenApiTest`)
   
   #### How did you try to break this feature and the system with this change?
   
   The change only touches test files and not source code. Hence it will not affect production. Test behavior consistency has also been verified 
   


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix flaky tungsten test using comparator [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #8232:
URL: https://github.com/apache/cloudstack/pull/8232#issuecomment-1809762700

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/8232?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Comparison is base [(`05b9b6e`)](https://app.codecov.io/gh/apache/cloudstack/commit/05b9b6e2e77b9b633f0fe22aff5f9f3c047b2303?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 22.99% compared to head [(`5df12e1`)](https://app.codecov.io/gh/apache/cloudstack/pull/8232?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 4.49%.
   > Report is 1 commits behind head on main.
   
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main   #8232       +/-   ##
   ============================================
   - Coverage     22.99%   4.49%   -18.50%     
   ============================================
     Files          5052     354     -4698     
     Lines        343866   27889   -315977     
     Branches      49530    4873    -44657     
   ============================================
   - Hits          79055    1255    -77800     
   + Misses       253380   26496   -226884     
   + Partials      11431     138    -11293     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/8232/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [simulator-marvin-tests](https://app.codecov.io/gh/apache/cloudstack/pull/8232/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/8232/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.49% <ø> (ø)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/cloudstack/pull/8232?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix flaky tungsten test using comparator [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland merged PR #8232:
URL: https://github.com/apache/cloudstack/pull/8232


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org