diff --git a/tests/primitives/test_semaphore.py b/tests/primitives/test_semaphore.py index 779586b4..936c3f3f 100644 --- a/tests/primitives/test_semaphore.py +++ b/tests/primitives/test_semaphore.py @@ -52,6 +52,7 @@ async def test_semaphore_cached_property(i: int): # We increased the threshold from 1.05 to 1.4 to help tests pass on slow github runners assert i == 1 or duration < 1.4 + @pytest.mark.asyncio_cooperative async def test_semaphore_acquire_release(): semaphore = Semaphore(2) @@ -60,6 +61,7 @@ async def test_semaphore_acquire_release(): semaphore.release() assert semaphore._value == 2 + @pytest.mark.asyncio_cooperative async def test_semaphore_blocking(): semaphore = Semaphore(1) @@ -76,6 +78,7 @@ async def task(): semaphore.release() await task1 + @pytest.mark.asyncio_cooperative async def test_semaphore_multiple_tasks(): semaphore = Semaphore(2) @@ -91,20 +94,22 @@ async def task(index): await asyncio.gather(*tasks) assert results == [0, 1, 2, 3] + @pytest.mark.asyncio_cooperative async def test_semaphore_with_zero_initial_value(): semaphore = Semaphore(0) async def task(): await semaphore.acquire() - return 'done' + return "done" task1 = asyncio.create_task(task()) await asyncio.sleep(0.1) assert not task1.done() semaphore.release() result = await task1 - assert result == 'done' + assert result == "done" + def test_semaphore_negative_initial_value(): with pytest.raises(ValueError): @@ -113,6 +118,8 @@ def test_semaphore_negative_initial_value(): Semaphore(None) with pytest.raises(TypeError): Semaphore("None") + + """ @pytest.mark.asyncio_cooperative async def test_semaphore_releasing_without_acquiring(): @@ -313,4 +320,4 @@ async def task(): task1.cancel() await asyncio.sleep(0.1) assert semaphore._value == 1 -""" \ No newline at end of file +""" diff --git a/tests/test_counter.py b/tests/test_counter.py index 96973d53..e86e8517 100644 --- a/tests/test_counter.py +++ b/tests/test_counter.py @@ -5,34 +5,38 @@ @pytest.mark.asyncio_cooperative async def test_counter_lock(): - counter = CounterLock(name='test') + counter = CounterLock(name="test") assert await counter.wait_for(0) assert counter._name == "test" + @pytest.mark.asyncio_cooperative async def test_counterlock_initialization(): counter = CounterLock(start_value=5) assert counter.value == 5 + @pytest.mark.asyncio_cooperative async def test_counterlock_set(): counter = CounterLock(start_value=0) counter.set(10) assert counter.value == 10 + @pytest.mark.asyncio_cooperative async def test_counterlock_wait_for(): counter = CounterLock(start_value=0) async def waiter(): await counter.wait_for(5) - return 'done' + return "done" waiter_task = asyncio.create_task(waiter()) await asyncio.sleep(0.1) counter.set(5) result = await waiter_task - assert result == 'done' + assert result == "done" + @pytest.mark.asyncio_cooperative async def test_counterlock_concurrent_waiters(): @@ -49,12 +53,14 @@ async def waiter(index): await asyncio.gather(*tasks) assert results == [0, 1, 2] + @pytest.mark.asyncio_cooperative async def test_counterlock_increment_only(): counter = CounterLock(start_value=5) with pytest.raises(ValueError): counter.set(3) + @pytest.mark.asyncio_cooperative async def test_counterlock_large_value(): counter = CounterLock(start_value=0) @@ -62,11 +68,13 @@ async def test_counterlock_large_value(): counter.set(large_value) assert counter.value == large_value + @pytest.mark.asyncio_cooperative async def test_counterlock_zero_value(): counter = CounterLock(start_value=0) assert counter.value == 0 + @pytest.mark.asyncio_cooperative async def test_counterlock_exception_handling(): counter = CounterLock(start_value=0) @@ -82,6 +90,7 @@ async def waiter(): result = await waiter() assert result == "Intentional error" + @pytest.mark.asyncio_cooperative async def test_simultaneous_set_and_wait(): counter = CounterLock(start_value=0) @@ -96,6 +105,7 @@ async def waiter(index): await asyncio.gather(*tasks) assert results == [0, 1, 2, 3, 4] + @pytest.mark.asyncio_cooperative async def test_reentrant_set(): counter = CounterLock(start_value=0) @@ -103,10 +113,12 @@ async def test_reentrant_set(): counter.set(10) # Reentrant set assert counter.value == 10 + def test_counterlock_negative_start_value(): with pytest.raises(ValueError): CounterLock(start_value=-1) + @pytest.mark.asyncio_cooperative async def test_immediate_set_and_wait(): counter = CounterLock(start_value=5) @@ -117,19 +129,21 @@ async def waiter(): result = await waiter() assert result is True + @pytest.mark.asyncio_cooperative async def test_delayed_set(): counter = CounterLock(start_value=0) async def waiter(): await counter.wait_for(5) - return 'done' + return "done" waiter_task = asyncio.create_task(waiter()) await asyncio.sleep(0.5) # Delay before setting the counter counter.set(5) result = await waiter_task - assert result == 'done' + assert result == "done" + @pytest.mark.asyncio_cooperative async def test_multiple_sets(): @@ -146,6 +160,7 @@ async def waiter(index): await asyncio.gather(*tasks) assert results == [0, 1, 2] + @pytest.mark.asyncio_cooperative async def test_custom_error_handling(): counter = CounterLock(start_value=0) @@ -161,16 +176,17 @@ async def waiter(): result = await waiter() assert result == "Custom error" + @pytest.mark.asyncio_cooperative async def test_external_interruptions(): counter = CounterLock(start_value=0) async def waiter(): await counter.wait_for(5) - return 'done' + return "done" waiter_task = asyncio.create_task(waiter()) await asyncio.sleep(0.1) waiter_task.cancel() await asyncio.sleep(0.1) - assert counter.value == 0 \ No newline at end of file + assert counter.value == 0