Batch: Only join running Threads (#7105)

This commit is contained in:
Bert Blommers 2023-12-10 08:22:26 -01:00 committed by GitHub
parent 85156f5939
commit 6bcab282ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -1055,7 +1055,8 @@ class BatchBackend(BaseBackend):
if job.status not in (JobStatus.FAILED, JobStatus.SUCCEEDED):
job.stop = True
# Try to join
job.join(0.2)
if job.is_alive():
job.join(0.2)
super().reset()

View File

@ -1,15 +1,16 @@
import datetime
import time
from unittest import SkipTest
from uuid import uuid4
import botocore.exceptions
import pytest
from moto import mock_batch, mock_ec2, mock_ecs, mock_iam, mock_logs
from moto import mock_batch, mock_ec2, mock_ecs, mock_iam, mock_logs, settings
from tests import DEFAULT_ACCOUNT_ID
from ..markers import requires_docker
from . import _get_clients, _setup
from . import DEFAULT_REGION, _get_clients, _setup
@mock_logs
@ -137,6 +138,39 @@ def test_submit_job_array_size():
assert len(child_job_1["attempts"]) == 1
@mock_ec2
@mock_ecs
@mock_iam
@mock_batch
@pytest.mark.network
@requires_docker
def test_submit_job_array_size__reset_while_job_is_running():
if settings.TEST_SERVER_MODE:
raise SkipTest("No point testing this in ServerMode")
# Setup
job_definition_name = f"echo_{str(uuid4())[0:6]}"
ec2_client, iam_client, _, _, batch_client = _get_clients()
commands = ["echo", "hello"]
_, _, _, iam_arn = _setup(ec2_client, iam_client)
_, queue_arn = prepare_job(batch_client, commands, iam_arn, job_definition_name)
# Execute
batch_client.submit_job(
jobName="test1",
jobQueue=queue_arn,
jobDefinition=job_definition_name,
arrayProperties={"size": 2},
)
from moto.batch import batch_backends
# This method will try to join on (wait for) any created JobThreads
# The parent of the ArrayJobs is created, but never started
# So we need to make sure that we don't join on any Threads that are never started in the first place
batch_backends[DEFAULT_ACCOUNT_ID][DEFAULT_REGION].reset()
@mock_logs
@mock_ec2
@mock_ecs