# Copyright (c) 2020 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com


import time

import hypothesis.strategies as st
import pytest
from hypothesis import given, settings

from czc.concurrency import async_map


@pytest.mark.unit
@given(st.lists(st.integers()))
@settings(max_examples=100, deadline=1000.00)
def test_async_map(inputs):
    outputs = async_map(lambda x: x, [[x] for x in inputs])
    assert outputs == inputs


@pytest.mark.unit
@given(st.lists(st.integers(), min_size=6, max_size=6))
@settings(max_examples=1, deadline=3000.00)
def test_async_map_slow_task(inputs):
    def slow_task(x):
        time.sleep(1)
        return x

    outputs = async_map(slow_task, [[x] for x in inputs])
    assert outputs == inputs
