本文整理汇总了Python中app.master.build.Build.cancel方法的典型用法代码示例。如果您正苦于以下问题:Python Build.cancel方法的具体用法?Python Build.cancel怎么用?Python Build.cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.master.build.Build
的用法示例。
在下文中一共展示了Build.cancel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cancel_exits_early_if_build_not_running
# 需要导入模块: from app.master.build import Build [as 别名]
# 或者: from app.master.build.Build import cancel [as 别名]
def test_cancel_exits_early_if_build_not_running(self):
build = Build(BuildRequest({}))
build._unstarted_subjobs = Queue()
slave_mock = Mock()
build._slaves_allocated = [slave_mock]
build._status = Mock(return_value=BuildStatus.FINISHED)
build.cancel()
self.assertFalse(build._is_canceled, "Build should not be canceled")
self.assertEqual(slave_mock.teardown.call_count, 0, "Teardown should not have been called")
示例2: test_cancel_depletes_queue_and_sets_canceled
# 需要导入模块: from app.master.build import Build [as 别名]
# 或者: from app.master.build.Build import cancel [as 别名]
def test_cancel_depletes_queue_and_sets_canceled(self):
build = Build(BuildRequest({}))
build._unstarted_subjobs = Queue()
build._unstarted_subjobs.put(1)
slave_mock = Mock()
build._slaves_allocated = [slave_mock]
build.cancel()
self.assertTrue(build._is_canceled, "Build should've been canceled")
self.assertTrue(build._unstarted_subjobs.empty(), "Build's unstarted subjobs should've been depleted")
示例3: test_handle_result_reported_from_slave_does_nothing_when_build_is_canceled
# 需要导入模块: from app.master.build import Build [as 别名]
# 或者: from app.master.build.Build import cancel [as 别名]
def test_handle_result_reported_from_slave_does_nothing_when_build_is_canceled(self):
build_id = 1
slave_url = "url"
build = Build(BuildRequest({}))
build.cancel()
self.patch_object(build, '_handle_subjob_payload')
self.patch_object(build, '_mark_subjob_complete')
master = ClusterMaster()
master._all_builds_by_id[build_id] = build
master._all_slaves_by_url[slave_url] = Mock()
mock_scheduler = self.mock_scheduler_pool.get(build)
master.handle_result_reported_from_slave(slave_url, build_id, 1)
self.assertEqual(build._handle_subjob_payload.call_count, 0, "Build is canceled, should not handle payload")
self.assertEqual(build._mark_subjob_complete.call_count, 0, "Build is canceled, should not complete subjobs")
self.assertEqual(mock_scheduler.execute_next_subjob_or_free_executor.call_count, 0,
"Build is canceled, should not do next subjob")
示例4: test_handle_result_reported_from_slave_when_build_is_canceled
# 需要导入模块: from app.master.build import Build [as 别名]
# 或者: from app.master.build.Build import cancel [as 别名]
def test_handle_result_reported_from_slave_when_build_is_canceled(self):
build_id = 1
slave_url = "url"
build = Build(BuildRequest({}))
self.patch('app.master.build.util')
build.generate_project_type()
build.cancel()
self.patch_object(build, '_handle_subjob_payload')
self.patch_object(build, '_mark_subjob_complete')
master = ClusterMaster()
slave_registry = SlaveRegistry.singleton()
BuildStore._all_builds_by_id[build_id] = build
slave_registry._all_slaves_by_url[slave_url] = Mock()
mock_scheduler = self.mock_scheduler_pool.get(build)
master.handle_result_reported_from_slave(slave_url, build_id, 1)
self.assertEqual(build._handle_subjob_payload.call_count, 1, "Canceled builds should "
"handle payload")
self.assertEqual(build._mark_subjob_complete.call_count, 1, "Canceled builds should mark "
"their subjobs complete")
self.assertTrue(mock_scheduler.execute_next_subjob_or_free_executor.called)
示例5: _create_test_build
# 需要导入模块: from app.master.build import Build [as 别名]
# 或者: from app.master.build.Build import cancel [as 别名]
def _create_test_build(
self,
build_status=None,
job_config=None,
num_subjobs=3,
num_atoms_per_subjob=3,
slaves=None,
):
"""
Create a Build instance for testing purposes. The instance will be created and brought to the specified
state similarly to how it would reach that state in actual app execution. Build instances have a huge
amount of internal state with complicated interactions, so this helper method helps us write tests that
are much more consistent and closer to reality. It also helps us avoid modifying a build's private members
directly.
:type build_status: BuildStatus
:rtype: Build
"""
build = Build(BuildRequest(build_parameters={}))
if build_status is None:
return build
# QUEUED: Instantiate a mock project_type instance for the build.
mock_project_type = self._create_mock_project_type()
self.patch('app.master.build.util.create_project_type').return_value = mock_project_type
build.generate_project_type()
if build_status is BuildStatus.QUEUED:
return build
# PREPARED: Create a fake job config and subjobs and hand them off to the build.
job_config = job_config or self._create_job_config()
mock_project_type.job_config.return_value = job_config
subjobs = self._create_subjobs(count=num_subjobs, num_atoms_each=num_atoms_per_subjob, job_config=job_config)
subjob_calculator = self._create_mock_subjob_calc(subjobs)
build.prepare(subjob_calculator)
if build_status is BuildStatus.PREPARED:
return build
# BUILDING: Allocate a slave and begin subjob executions on that slave.
slaves = slaves or [self._create_mock_slave()]
scheduler = self.scheduler_pool.get(build)
for slave in slaves:
scheduler.allocate_slave(slave=slave)
scheduler.begin_subjob_executions_on_slave(slave=slave)
if build_status is BuildStatus.BUILDING:
return build
# ERROR: Mark the in-progress build as failed.
if build_status is BuildStatus.ERROR:
build.mark_failed(failure_reason='Test build was intentionally marked failed.')
return build
# CANCELED: Cancel the in-progress build.
if build_status is BuildStatus.CANCELED:
build.cancel()
return build
# FINISHED: Complete all subjobs and allow all postbuild tasks to execute.
self._finish_test_build(build)
if build_status is BuildStatus.FINISHED:
return build
raise ValueError('Unsupported value for build_status: "{}".'.format(build_status))