Example #1
0
def test_run_computational_sidecar_dask(dask_client: Client,
                                        ubuntu_task: ServiceExampleParam,
                                        mocker: MockerFixture):
    mocker.patch(
        "simcore_service_dask_sidecar.computational_sidecar.core.get_integration_version",
        autospec=True,
        return_value=ubuntu_task.integration_version,
    )
    future = dask_client.submit(
        run_computational_sidecar,
        ubuntu_task.docker_basic_auth,
        ubuntu_task.service_key,
        ubuntu_task.service_version,
        ubuntu_task.input_data,
        ubuntu_task.output_data_keys,
        ubuntu_task.log_file_url,
        ubuntu_task.command,
        resources={},
    )

    worker_name = next(iter(dask_client.scheduler_info()["workers"]))

    output_data = future.result()

    # check that the task produces expected logs
    worker_logs = [
        log for _, log in dask_client.get_worker_logs()[worker_name]
    ]  # type: ignore
    for log in ubuntu_task.expected_logs:
        r = re.compile(
            rf"\[{ubuntu_task.service_key}:{ubuntu_task.service_version} - .+\/.+ - .+\]: ({log})"
        )
        search_results = list(filter(r.search, worker_logs))
        assert (
            len(search_results) > 0
        ), f"Could not find {log} in worker_logs:\n {pformat(worker_logs, width=240)}"

    # check that the task produce the expected data, not less not more
    for k, v in ubuntu_task.expected_output_data.items():
        assert k in output_data
        assert output_data[k] == v

    for k, v in output_data.items():
        assert k in ubuntu_task.expected_output_data
        assert v == ubuntu_task.expected_output_data[k]

        # if there are file urls in the output, check they exist
        if isinstance(v, FileUrl):
            with fsspec.open(f"{v.url}") as fp:
                assert fp.details.get("size") > 0