Example #1
0
    def test_deploy_async(
        self,
        caplog: LogCaptureFixture,
        fx_deployments: YamlLoaderDeployment,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
    ) -> None:
        """Test deploy async."""
        caplog.set_level(logging.INFO, logger="runway")
        mock_futures = mocker.patch(f"{MODULE}.concurrent.futures")
        executor = MagicMock()
        executor.__enter__.return_value = executor
        mock_futures.ProcessPoolExecutor.return_value = executor
        mocker.patch.object(Deployment, "use_async", True)
        mock_mp_context = mocker.patch("multiprocessing.get_context")

        obj = Deployment(
            context=runway_context,
            definition=fx_deployments.load("simple_parallel_regions"),
        )
        assert not obj.deploy()
        assert (
            "unnamed_deployment:processing regions in parallel... (output will be interwoven)"
            in caplog.messages)
        mock_mp_context.assert_called_once_with("fork")
        mock_futures.ProcessPoolExecutor.assert_called_once_with(
            max_workers=runway_context.env.max_concurrent_regions,
            mp_context=mock_mp_context.return_value,
        )
        executor.submit.assert_has_calls([
            call(obj.run, "deploy", "us-east-1"),
            call(obj.run, "deploy", "us-west-2")
        ])
        assert executor.submit.return_value.result.call_count == 2
Example #2
0
    def test_deploy_async(
        self, mock_futures, caplog, fx_deployments, monkeypatch, runway_context
    ):
        """Test deploy async."""
        caplog.set_level(logging.INFO, logger="runway")
        executor = MagicMock()
        mock_futures.ProcessPoolExecutor.return_value = executor
        monkeypatch.setattr(Deployment, "use_async", True)

        obj = Deployment(
            context=runway_context,
            definition=fx_deployments.load("simple_parallel_regions"),
        )
        assert not obj.deploy()
        assert (
            "deployment_1:processing regions in parallel... (output will be interwoven)"
            in caplog.messages
        )
        mock_futures.ProcessPoolExecutor.assert_called_once_with(
            max_workers=runway_context.env.max_concurrent_regions
        )
        executor.submit.assert_has_calls(
            [call(obj.run, "deploy", "us-east-1"), call(obj.run, "deploy", "us-west-2")]
        )
        mock_futures.wait.assert_called_once()
        assert executor.submit.return_value.result.call_count == 2
Example #3
0
 def test_deploy(self, fx_deployments, monkeypatch, runway_context):
     """Test deploy."""
     mock_run = MagicMock()
     monkeypatch.setattr(Deployment, "run", mock_run)
     obj = Deployment(
         context=runway_context, definition=fx_deployments.load("min_required")
     )
     assert not obj.deploy()
     mock_run.assert_called_once_with("deploy", "us-east-1")
Example #4
0
 def test_deploy(
     self,
     fx_deployments: YamlLoaderDeployment,
     mocker: MockerFixture,
     runway_context: MockRunwayContext,
 ) -> None:
     """Test deploy."""
     mock_run = MagicMock()
     mocker.patch.object(Deployment, "run", mock_run)
     obj = Deployment(context=runway_context,
                      definition=fx_deployments.load("min_required"))
     assert not obj.deploy()
     mock_run.assert_called_once_with("deploy", "us-east-1")
Example #5
0
    def test_deploy_sync(self, caplog, fx_deployments, monkeypatch, runway_context):
        """Test deploy sync."""
        caplog.set_level(logging.INFO, logger="runway")
        mock_run = MagicMock()
        monkeypatch.setattr(Deployment, "use_async", False)
        monkeypatch.setattr(Deployment, "run", mock_run)

        obj = Deployment(
            context=runway_context,
            definition=fx_deployments.load("simple_parallel_regions"),
        )
        assert not obj.deploy()
        assert "deployment_1:processing regions sequentially..." in caplog.messages
        mock_run.assert_has_calls(
            [call("deploy", "us-east-1"), call("deploy", "us-west-2")]
        )
Example #6
0
    def test_deploy_sync(
        self,
        caplog: LogCaptureFixture,
        fx_deployments: YamlLoaderDeployment,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
    ) -> None:
        """Test deploy sync."""
        caplog.set_level(logging.INFO, logger="runway")
        mock_run = MagicMock()
        mocker.patch.object(Deployment, "use_async", False)
        mocker.patch.object(Deployment, "run", mock_run)

        obj = Deployment(
            context=runway_context,
            definition=fx_deployments.load("simple_parallel_regions"),
        )
        assert not obj.deploy()
        assert ("unnamed_deployment:processing regions sequentially..."
                in caplog.messages)
        mock_run.assert_has_calls(
            [call("deploy", "us-east-1"),
             call("deploy", "us-west-2")])