def test_start_task(mock_ecs_client, mock_ecs_cluster, mock_ecs_task_definition, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, client=mock_ecs_client, subnets=mock_subnets) task_arn = client.start_task(mock_ecs_task_definition) assert client.start_task(mock_ecs_task_definition) != task_arn
def test_run_task(mock_ecs_client, mock_ecs_cluster, mock_ecs_task_definition, mock_subnets, expected_statuses): client = FakeECSClient(cluster=mock_ecs_cluster, client=mock_ecs_client, subnets=mock_subnets) client.run_task(mock_ecs_task_definition, expected_statuses=expected_statuses)
def test_stop_task_timeout(mock_ecs_client, mock_ecs_cluster, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, client=mock_ecs_client, subnets=mock_subnets, max_polls=1) with pytest.raises(ECSTimeout): client.stop_task("task arn", expected_statuses=["RUNNING", "RUNNING"])
def test_stop_task(mock_ecs_client, mock_ecs_cluster, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, subnets=mock_subnets, client=mock_ecs_client) assert client.stop_task("running task arn") assert not client.stop_task("already stopped task arn", expected_statuses=["STOPPED"])
def test_run_task_fails(mock_ecs_client, mock_ecs_cluster, mock_ecs_task_definition, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, subnets=mock_subnets, client=mock_ecs_client) with pytest.raises(ECSError, match="OutOfMemoryError"): client.run_task(mock_ecs_task_definition, expected_stop_code="OutOfMemoryError")
def test_run_task_timeout(mock_ecs_client, mock_ecs_cluster, mock_ecs_task_definition, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, client=mock_ecs_client, subnets=mock_subnets, max_polls=1) with pytest.raises(ECSTimeout): client.run_task(mock_ecs_task_definition)
def test_set_task(mock_ecs_client, mock_ecs_cluster, mock_subnets): client = FakeECSClient(cluster=mock_ecs_cluster, client=mock_ecs_client, subnets=mock_subnets) definition = dict( family="dagster", requiresCompatibilities=["FARGATE"], containerDefinitions=[ { "name": "HelloWorld", "image": "hello-world:latest", "cpu": 256 }, ], networkMode="awsvpc", cpu="256", memory="512", ) assert not mock_ecs_client.list_task_definitions()["taskDefinitionArns"] task_definition_arn = client.set_task(**definition) assert mock_ecs_client.list_task_definitions()["taskDefinitionArns"] == [ task_definition_arn ]