Skip to content
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

Fix flaky tungsten test using comparator #8232

Merged
merged 1 commit into from Nov 14, 2023

Conversation

rRajivramachandran
Copy link
Contributor

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 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 for all tests. The tests listTungstenNetworkTest, listTungstenPolicyTest use the list method of this connector Tungsten API connector call in their respective tests.

The 3rd party library juniper-tungsten-api'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.

image

Fix

The test class already defines a comparator to sort objects of ApiObjectBase here. 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)
  • 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
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • 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

Copy link
Member

@rohityadavcloud rohityadavcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't check it

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm (unit tests only)

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (05b9b6e) 22.99% compared to head (5df12e1) 19.11%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8232      +/-   ##
============================================
- Coverage     22.99%   19.11%   -3.88%     
+ Complexity    23102    18434    -4668     
============================================
  Files          5052     5052              
  Lines        343866   343866              
  Branches      49530    49530              
============================================
- Hits          79055    65737   -13318     
- Misses       253380   268480   +15100     
+ Partials      11431     9649    -1782     
Flag Coverage Δ
simulator-marvin-tests 20.40% <ø> (-4.22%) ⬇️
uitests 4.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DaanHoogland DaanHoogland merged commit 96b07d7 into apache:main Nov 14, 2023
24 of 25 checks passed
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants