dazza-codes / aio-aws

Asyncio utils for AWS Services
Apache License 2.0
3 stars 1 forks source link

Update tests for moto 2.x #63

Closed dazza-codes closed 3 years ago

dazza-codes commented 3 years ago

Fix #60

Consider whether there is some way to add a pause to a job queue.

Completing this depends on https://github.com/spulec/moto/issues/4423

    # We need to be able to cancel a job that has not been started yet
    # Locally, our jobs start so fast that we can't cancel them in time
    # So delay our job, by letting it depend on a slow-running job
    commands = ["sleep", "1"]
    job_def_arn, queue_arn = prepare_job(batch_client, commands, iam_arn, "deptest")

    resp = batch_client.submit_job(
        jobName="test1", jobQueue=queue_arn, jobDefinition=job_def_arn
    )
    delayed_job = resp["jobId"]

    depends_on = [{"jobId": delayed_job, "type": "SEQUENTIAL"}]
    resp = batch_client.submit_job(
        jobName="test_job_name",
        jobQueue=queue_arn,
        jobDefinition=job_def_arn,
        dependsOn=depends_on,
    )
    job_id = resp["jobId"]

    batch_client.cancel_job(jobId=job_id, reason="test_cancel")
    _wait_for_job_status(batch_client, job_id, "FAILED", seconds_to_wait=30)

    resp = batch_client.describe_jobs(jobs=[job_id])
    resp["jobs"][0]["jobName"].should.equal("test_job_name")
    resp["jobs"][0]["statusReason"].should.equal("test_cancel")
dazza-codes commented 3 years ago

Everything is passing now.

---------- coverage: platform linux, python 3.7.10-final-0 -----------
Name                          Stmts   Miss  Cover
-------------------------------------------------
aio_aws/__init__.py               2      0   100%
aio_aws/aio_aws_batch.py        396    110    72%
aio_aws/aio_aws_batch_db.py     497     68    86%
aio_aws/aio_aws_config.py        90      7    92%
aio_aws/aio_aws_lambda.py       194     85    56%
aio_aws/aio_aws_s3.py           228    116    49%
aio_aws/async_executor.py       152     64    58%
aio_aws/async_main.py            13     13     0%
aio_aws/aws_batch_db.py         105     22    79%
aio_aws/aws_batch_models.py     161     13    92%
aio_aws/logger.py                19      0   100%
aio_aws/s3_aio.py               233     22    91%
aio_aws/s3_io.py                178     16    91%
aio_aws/s3_uri.py               181     27    85%
aio_aws/utils.py                 48     10    79%
aio_aws/uuid_utils.py            29      0   100%
aio_aws/version.py                3      0   100%
-------------------------------------------------
TOTAL                          2529    573    77%
Coverage HTML written to dir htmlcov