New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make authentication request parameter order to be deterministic #8185
Make authentication request parameter order to be deterministic #8185
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clgtm, but I think the nicira code needs to be phased out (out of scope for this PR).
Nicira is likely not support, unmaintained - are you a Nicira user @rRajivramachandran - could you advise if there's a reason around the PR? |
@rohityadavcloud I am not a user of the tool directly. I am a UIUC(University of Illinois Urbana Champaign) student who is working on improving flaky tests in different open source projects. Would it be possible to merge this contribution |
@blueorangutan package |
@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report
@@ Coverage Diff @@
## main #8185 +/- ##
============================================
- Coverage 29.19% 29.15% -0.05%
+ Complexity 31015 30970 -45
============================================
Files 5181 5181
Lines 365255 365255
Branches 53427 53427
============================================
- Hits 106646 106491 -155
- Misses 243988 244153 +165
+ Partials 14621 14611 -10
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 33 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
@blueorangutan package |
@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
we could remove the plugin in the near future this PR is not useful, but we can merge. |
If it helps @rRajivramachandran , ... I think this is not bothering anyone else |
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7643 |
…ic (apache#8185)" This reverts commit a974300.
Description
This PR is to fix a few tests whose results are non deterministic/flaky in the module plugins/network-elements/nicira-nvp.
Setup:
Java version: 11.0.20.1
Maven version: 3.8.8
Test failure reproduction:
The test
com.cloud.network.nicira.NiciraRestClientTest#testExecuteLiveLockWhenControllerAllowsLoginAndFollowsWithUnauthorizedButDoesNotRediect
assumes the order of keys to be maintained by aHashMap
. This issue was verified using the NonDex plugin.Steps:
Root cause and fix:
Test failure in NonDex mode:
The NullPointerException occurs at the following location
cloudstack/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
Line 87 in fcbf540
because the
mockResponse
created in the test, does not get returned for theexecute
method.The
HttpRequestMatcher
serializes the request object to a stringcloudstack/utils/src/test/java/com/cloud/utils/rest/HttpRequestMatcher.java
Line 68 in fcbf540
To verify that the issue was due to the HttpRequestMatcher used by mockito, the following line:
cloudstack/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
Line 190 in fcbf540
was modfied to read
when(httpClient.execute(eq(HTTP_HOST), any(HttpUriRequest.class), eq(httpClientContext)))
.This allows matching any request class object. The test passed with this change when run on the NonDex tool confirming that the issue was here.
On adding logs to the
HttpRequestMatcher
class, it was deduced that the test fails when the order of keys returned by the login parameters is not the same as that configured in the test class.Failing case(ordered shuffled):
Passing case(order not shuffled):
The test class configures login parameters here:
cloudstack/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java
Lines 82 to 93 in fcbf540
and the source code builds them here:
cloudstack/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
Lines 122 to 131 in fcbf540
Fix
To make the map ordered for ensuring deterministic results during serialization/deserialization, changes were done at the source code and test by converting the
HashMap
to aLinkedHashMap
.Additional fixes
The change also fixed following tests in the same class which were flaky due to the same reason:
Types of changes
Feature/Enhancement Scale or Bug Severity
The fix is backward compatible as it merely changes an unordered map implementation to an ordered one for ensuring that when string serialization of the map is done, results are deterministic.
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
mvn -pl plugins/network-elements/nicira-nvp edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.cloud.network.nicira.NiciraRestClientTest#testExecuteLiveLockWhenControllerAllowsLoginAndFollowsWithUnauthorizedButDoesNotRediect
).mvn -pl plugins/network-elements/nicira-nvp test
).How did you try to break this feature and the system with this change?
The change does not affect any feature as it only makes an unordered data structured as ordered. This does not enforce any constraints on source code and is an internal implementation detail. However it makes the code more deterministic in cases where serialization to strings is done directly, which is the case for some tests