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 model tests #1429

Merged
merged 4 commits into from
Jan 29, 2024

Conversation

ryanbogan
Copy link
Member

Description

Since ModelDaoTests extends KNNSingleNodeTestCase, a node is started at the beginning of each test and stopped at the end of each test. The TrainingJobClusterStateListenerClass contains a clusterChanged method that is called each time a new cluster is started. Within this method, a separate thread runs through all existing models and marks any that are stuck in training as failed. This can result in a scenario that causes flaky tests.

In this scenario, a node is started at the beginning of a test, calling the clusterChanged method. The test creates a model (or multiple), verifies the expected behavior, and then stops the node. Meanwhile, the other thread is in the process of looping through any existing models and potentially updating their model state parameter. If the node stops before this process is complete, an exception will be thrown saying that the model index (.opensearch-knn-models) does not exist.

To fix the flaky test situation, the TrainingJobClusterStateListener class has been mocked to no-op the clusterChanged method in the setup for the class. This means that there will be no separate thread accessing the models for the entire ModelDaoTests class. In the teardown after the class, the mocked static is closed so it will not affect any other test classes.

Issues Resolved

#1376
#1413

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Ryan Bogan <rbogan@amazon.com>
Signed-off-by: Ryan Bogan <rbogan@amazon.com>
Signed-off-by: Ryan Bogan <rbogan@amazon.com>
Signed-off-by: Ryan Bogan <rbogan@amazon.com>
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2b963b4) 84.92% compared to head (c23a1e7) 84.84%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1429      +/-   ##
============================================
- Coverage     84.92%   84.84%   -0.08%     
+ Complexity     1274     1273       -1     
============================================
  Files           167      167              
  Lines          5186     5186              
  Branches        491      491              
============================================
- Hits           4404     4400       -4     
- Misses          574      577       +3     
- Partials        208      209       +1     

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

@ryanbogan ryanbogan merged commit 9e4251e into opensearch-project:main Jan 29, 2024
64 checks passed
@ryanbogan ryanbogan deleted the fix_flaky_model_tests branch January 29, 2024 22:40
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 29, 2024
* Fix flaky model tests in k-NN

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Remove * imports

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Minor change

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Add changelog entry

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

---------

Signed-off-by: Ryan Bogan <rbogan@amazon.com>
(cherry picked from commit 9e4251e)
ryanbogan added a commit that referenced this pull request Jan 30, 2024
* Fix flaky model tests in k-NN

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Remove * imports

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Minor change

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

* Add changelog entry

Signed-off-by: Ryan Bogan <rbogan@amazon.com>

---------

Signed-off-by: Ryan Bogan <rbogan@amazon.com>
(cherry picked from commit 9e4251e)

Co-authored-by: Ryan Bogan <rbogan@amazon.com>
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.

3 participants