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

Updated tests in test_update.py to use mock_update_handler #2552

Merged
merged 5 commits into from
Apr 20, 2022

Conversation

narrieta
Copy link
Member

Updated the tests in TestUpdate to use mock_update_handler.

mock_update_handler does not start the background threads by default (these threads tend to produce random failures in the unit test runs)

@codecov
Copy link

codecov bot commented Apr 13, 2022

Codecov Report

Merging #2552 (1f577e1) into develop (362df3f) will increase coverage by 0.05%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #2552      +/-   ##
===========================================
+ Coverage    71.79%   71.84%   +0.05%     
===========================================
  Files          102      102              
  Lines        15321    15321              
  Branches      2429     2429              
===========================================
+ Hits         11000    11008       +8     
+ Misses        3829     3822       -7     
+ Partials       492      491       -1     
Impacted Files Coverage Δ
azurelinuxagent/ga/update.py 89.23% <0.00%> (+0.56%) ⬆️
azurelinuxagent/common/utils/archive.py 89.85% <0.00%> (+1.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fd0d81...1f577e1. Read the comment docs.

@@ -25,17 +25,29 @@


@contextlib.contextmanager
def mock_update_handler(protocol, iterations=1, on_new_iteration=lambda _: None, exthandlers_handler=None, remote_access_handler=None, enable_agent_updates=False):
def mock_update_handler(protocol,
Copy link
Member Author

Choose a reason for hiding this comment

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

Added new parameters to the mock in order to support more test scenarios

@@ -1294,77 +1294,6 @@ def test_get_latest_agent_should_return_latest_agent_even_on_bad_error_json(self
latest_agent = self.update_handler.get_latest_agent_greater_than_daemon()
self.assertEqual(latest_agent.version, dst_ver, "Latest agent version is invalid")

def _test_run(self, invocations=1, calls=1, enable_updates=False, sleep_interval=(6,)):
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved those tests to a new class UpdateHandlerRunTestCase and updated them to use mock_update_handler

self.assertEqual(0, update_handler.get_iterations_completed())

def test_run_clears_sentinel_on_successful_exit(self):
update_handler = self._test_run()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create the sentinel file before starting the run? Doesn't look like this test is explicitly guaranteeing that run clears the sentinel file, just that it doesn't create one on a successful termination.

Copy link
Member Author

Choose a reason for hiding this comment

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

the only intention of this PR is to migrate those tests to use the mock_update_handler. no other improvements (and these tests need quite a few) were made

@narrieta narrieta merged commit 1da0ef6 into Azure:develop Apr 20, 2022
@narrieta narrieta deleted the test-update branch April 20, 2022 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants