-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdk-heartbeat: Handle execution end_time not string (#750)
Currently, if for some reason the `end_time` field of the execution object is not a string (for example, the value is `None`), the `datetime.fromisoformat()` method throws an exception and fails the heartbeat test. This change introduces an explicit conversion of the value to string and adds logging for what the error is along with indication that the heartbeat will fail. Testing Done: Unit tests added. Signed-off-by: Andon Andonov <[email protected]>
- Loading branch information
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
projects/vdk-heartbeat/tests/vdk/internal/test_job_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from unittest.mock import patch | ||
|
||
from vdk.internal.heartbeat.config import Config | ||
from vdk.internal.heartbeat.job_controller import JobController | ||
|
||
|
||
@patch.object(JobController, "_execute") | ||
def test_check_job_execution_finished(patched_method): | ||
test_config = Config() | ||
test_config.control_api_url = None | ||
test_config.vdkcli_oauth2_uri = None | ||
|
||
patched_method.return_value = ( | ||
'[{"status": "finished", "end_time": ' '"2022-03-01"}]' | ||
) | ||
|
||
test_controller = JobController(test_config) | ||
test_controller.config.RUN_TEST_TIMEOUT_SECONDS = 10 | ||
|
||
res = test_controller.check_job_execution_finished() | ||
assert res == "finished" | ||
|
||
|
||
@patch.object(JobController, "_execute") | ||
def test_check_job_execution_finished_no_exceptions_for_value_errors(patched_method): | ||
test_config = Config() | ||
test_config.control_api_url = None | ||
test_config.vdkcli_oauth2_uri = None | ||
|
||
patched_method.return_value = '[{"status": "finished", "end_time": "None"}]' | ||
|
||
test_controller = JobController(test_config) | ||
test_controller.config.RUN_TEST_TIMEOUT_SECONDS = 10 | ||
|
||
res = test_controller.check_job_execution_finished() | ||
assert res == "finished" | ||
|
||
patched_method.return_value = '[{"status": "finished", "end_time": ' "12345}]" | ||
|
||
res = test_controller.check_job_execution_finished() | ||
assert res == "finished" |