Skip to content

Commit

Permalink
abb gc test
Browse files Browse the repository at this point in the history
  • Loading branch information
aiudirog committed Jul 4, 2024
1 parent 475439a commit e508145
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_async_background_batcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

import asyncio as aio
import gc
import weakref
from typing import Iterable, Tuple

from aiuti.typing import AYields
from aiuti.asyncio import AsyncBackgroundBatcher


async def batch_things() -> weakref.ref[AsyncBackgroundBatcher[int, int]]:
@AsyncBackgroundBatcher
async def batcher(
batch: Iterable[Tuple[str, int]],
) -> AYields[Tuple[str, int]]:
for key, value in batch:
await aio.sleep(0)
yield key, value + 1

await aio.gather(*map(batcher, range(30)))

return weakref.ref(batcher)


def test_gc() -> None:
ref = aio.run(batch_things())
gc.collect()
assert ref() is None

0 comments on commit e508145

Please sign in to comment.