Skip to content

Commit

Permalink
More tests for continue on error
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
  • Loading branch information
zelinh committed Dec 15, 2023
1 parent cbad22f commit a8d01d0
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/build_workflow/build_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def build_incremental(self, args: BuildArgs, input_manifest: InputManifest, comp
builder.export_artifacts(build_recorder_incremental)
logging.info(f"Successfully built {component.name}")
except:
logging.error(f"Error building {component.name}, retry with: {args.component_command(component.name)}")
logging.error(f"Error incremental building {component.name}.")
if args.continue_on_error and component.name not in ['OpenSearch', 'job-scheduler', 'common-utils', 'OpenSearch-Dashboards']:
failed_plugins.append(component.name)
continue
Expand Down
1 change: 0 additions & 1 deletion src/run_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def main() -> int:
console.configure(level=args.logging_level)
manifest = InputManifest.from_file(args.manifest)
failed_plugins = []
components = args.components

if args.ref_manifest:
manifest = manifest.stable()
Expand Down
93 changes: 91 additions & 2 deletions tests/tests_build_workflow/test_build_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import Any, List
from unittest.mock import MagicMock, call, patch

import pytest

from build_workflow.build_incremental import BuildIncremental
from manifests.build_manifest import BuildManifest
from manifests.input_manifest import InputManifest
Expand Down Expand Up @@ -182,8 +184,10 @@ def test_build_incremental_no_prebuild_manifest(self, mock_temp: MagicMock, mock
@patch("build_workflow.build_incremental.Builders.builder_from", return_value=MagicMock())
@patch("build_workflow.build_incremental.BuildRecorder", return_value=MagicMock())
@patch("build_workflow.build_incremental.TemporaryDirectory")
def test_build_incremental_with_prebuild_manifest(self, mock_temp: MagicMock, mock_recorder: MagicMock, mock_builder: MagicMock, mock_build_manifest: MagicMock, mock_path_exist: MagicMock,
mock_build_output_dir: MagicMock, mock_logging_info: MagicMock, *mocks: Any) -> None:
def test_build_incremental_with_prebuild_manifest(self, mock_temp: MagicMock, mock_recorder: MagicMock,
mock_builder: MagicMock, mock_build_manifest: MagicMock,
mock_path_exist: MagicMock, mock_build_output_dir: MagicMock,
mock_logging_info: MagicMock, *mocks: Any) -> None:
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
args = MagicMock()
args.distribution = "tar"
Expand All @@ -208,3 +212,88 @@ def test_build_incremental_with_prebuild_manifest(self, mock_temp: MagicMock, mo

mock_recorder.assert_called_once()
mock_recorder.return_value.write_manifest.assert_called()

@patch("build_workflow.build_incremental.logging.error")
@patch("build_workflow.build_incremental.logging.info")
@patch("paths.build_output_dir")
@patch("os.path.exists")
@patch("manifests.build_manifest.BuildManifest.from_path")
@patch("build_workflow.build_incremental.Builders.builder_from", return_value=MagicMock())
@patch("build_workflow.build_incremental.BuildRecorder", return_value=MagicMock())
@patch("build_workflow.build_incremental.TemporaryDirectory")
def test_build_incremental_continue_on_fail_core(self, mock_temp: MagicMock, mock_recorder: MagicMock,
mock_builder_from: MagicMock, mock_build_manifest: MagicMock,
mock_path_exist: MagicMock, mock_build_output_dir: MagicMock,
mock_logging_info: MagicMock, mock_logging_error: MagicMock,
*mocks: Any) -> None:
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
args = MagicMock()
args.distribution = "tar"
args.keep = False
args.snapshot = None
args.platform = "linux"
args.architecture = "x64"
args.continue_on_error = True
mock_path_exist.return_value = True
mock_build_manifest.return_value = self.BUILD_MANIFEST
mock_builder = MagicMock()
mock_builder.build.side_effect = Exception("Error building")
mock_builder_from.return_value = mock_builder

with pytest.raises(Exception, match="Error building"):
self.buildIncremental.build_incremental(args, self.INPUT_MANIFEST, ["common-utils", "opensearch-observability"])

mock_logging_error.assert_called_with("Error incremental building common-utils.")
mock_build_manifest.assert_called_once()
mock_build_manifest.assert_called_with(os.path.join("tar", "builds", "opensearch", "manifest.yml"))
self.assertTrue(args.platform == "linux")
self.assertNotEqual(mock_builder.build.call_count, 0)
self.assertEqual(mock_builder.build.call_count, 1)

mock_logging_info.assert_has_calls([
call('Rebuilding common-utils')
], any_order=True)

mock_recorder.assert_called_once()
mock_recorder.return_value.write_manifest.assert_not_called()

@patch("build_workflow.build_incremental.logging.error")
@patch("build_workflow.build_incremental.logging.info")
@patch("paths.build_output_dir")
@patch("os.path.exists")
@patch("manifests.build_manifest.BuildManifest.from_path")
@patch("build_workflow.build_incremental.Builders.builder_from", return_value=MagicMock())
@patch("build_workflow.build_incremental.BuildRecorder", return_value=MagicMock())
@patch("build_workflow.build_incremental.TemporaryDirectory")
def test_build_incremental_continue_on_fail_plugin(self, mock_temp: MagicMock, mock_recorder: MagicMock, mock_builder_from: MagicMock, mock_build_manifest: MagicMock, mock_path_exist: MagicMock,
mock_build_output_dir: MagicMock, mock_logging_info: MagicMock, mock_logging_error: MagicMock, *mocks: Any) -> None:
mock_temp.return_value.__enter__.return_value.name = tempfile.gettempdir()
args = MagicMock()
args.distribution = "tar"
args.keep = False
args.snapshot = None
args.platform = "linux"
args.architecture = "x64"
args.continue_on_error = True
mock_path_exist.return_value = True
mock_build_manifest.return_value = self.BUILD_MANIFEST
mock_builder = MagicMock()
mock_builder.build.side_effect = Exception("Error build")
mock_builder_from.return_value = mock_builder

self.buildIncremental.build_incremental(args, self.INPUT_MANIFEST, ["ml-commons", "opensearch-observability"])

mock_logging_error.assert_called_with("Failed plugins are ['ml-commons', 'opensearch-observability']")
mock_build_manifest.assert_called_once()
mock_build_manifest.assert_called_with(os.path.join("tar", "builds", "opensearch", "manifest.yml"))
self.assertTrue(args.platform == "linux")
self.assertNotEqual(mock_builder.build.call_count, 0)
self.assertEqual(mock_builder.build.call_count, 2)

mock_logging_info.assert_has_calls([
call('Rebuilding ml-commons'),
call('Rebuilding opensearch-observability')
], any_order=True)

mock_recorder.assert_called_once()
mock_recorder.return_value.write_manifest.assert_called()

0 comments on commit a8d01d0

Please sign in to comment.