add unit test test_env_retry_on_deployment_fail

This commit is contained in:
Lili Deng 2024-09-14 13:20:12 +08:00 коммит произвёл LiliDeng
Родитель a87bba5021
Коммит cf99e697a8
3 изменённых файлов: 48 добавлений и 1 удалений

Просмотреть файл

@ -368,6 +368,7 @@ class AzurePrepareTestCase(TestCase):
def load_environment(
self,
node_req_count: int = 2,
retry: int = 0,
) -> Environment:
runbook = schema.Environment()
if node_req_count > 0:
@ -381,7 +382,7 @@ class AzurePrepareTestCase(TestCase):
warn_as_error=False,
id_=0,
runbook=runbook,
retry=0,
retry=retry,
)
return environment

Просмотреть файл

@ -616,6 +616,51 @@ class RunnerTestCase(TestCase):
test_results=test_results,
)
def test_env_retry_on_deployment_fail(self) -> None:
# retry when fail to deploy
platform_schema = test_platform.MockPlatformSchema(deploy_success=False)
test_testsuite.generate_cases_metadata()
env_runbook = generate_env_runbook()
env_runbook.retry = 2
runner = generate_runner(env_runbook, platform_schema=platform_schema)
test_result_messages = self._run_all_tests(runner)
deployment_failure = "deployment failed. LisaException: mock deploy failed"
self.verify_env_results(
expected_prepared=[
"generated_0",
"generated_1",
"generated_2",
"generated_0",
"generated_0",
"generated_1",
"generated_1",
"generated_2",
"generated_2",
],
expected_deployed_envs=[],
expected_deleted_envs=[
"generated_0",
"generated_1",
"generated_2",
],
runner=runner,
)
self.verify_test_results(
expected_test_order=["mock_ut1", "mock_ut2", "mock_ut3"],
expected_envs=["generated_0", "generated_1", "generated_2"],
expected_status=[
TestStatus.FAILED,
TestStatus.FAILED,
TestStatus.FAILED,
],
expected_message=[
deployment_failure,
deployment_failure,
deployment_failure,
],
test_results=test_result_messages,
)
def verify_test_results(
self,
expected_test_order: List[str],

Просмотреть файл

@ -198,6 +198,7 @@ class EnvironmentTestCase(TestCase):
envs = load_environments(None)
self.assertEqual(0, len(envs))
self.assertEqual(False, envs.warn_as_error)
self.assertEqual(0, envs.retry)
def test_create_from_runbook_split(self) -> None:
runbook = generate_runbook(local=True, remote=True)