Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function to TestBase to await registered tasks #1275

Closed
qstokkink opened this issue Feb 21, 2024 · 1 comment · Fixed by #1293
Closed

Add a helper function to TestBase to await registered tasks #1275

qstokkink opened this issue Feb 21, 2024 · 1 comment · Fixed by #1293
Assignees
Labels
priority: low Should be addressed at some point in the future

Comments

@qstokkink
Copy link
Collaborator

While writing tests, I often use the following pattern to await a registered task:

async def test_something(self) -> None:
    task_manager.user_logic_registers_tasks()
    
    await sleep(0)
    for task in task_manager.get_tasks():
        if task.get_name() == "task name":
            await task

    # assert something ...

Ideally, I would not like to repeat myself this much. Instead, I'd like TestBase to offer this functionality. Something like this:

async def test_something(self) -> None:
    task_manager.user_logic_registers_tasks()

    await self.tm_task("task name", task_manager)

    # assert something ...
@qstokkink qstokkink added the priority: low Should be addressed at some point in the future label Feb 21, 2024
@qstokkink
Copy link
Collaborator Author

qstokkink commented Apr 11, 2024

I'll update this issue with a superior suggestion by @egbertbouman. The TaskManager can support a get_task(task_name: str) -> Future.

Perhaps we can also add get_anonymous_tasks(base_name: str) -> list[Future].

This would change the envisioned functionality to be the following:

async def test_something(self) -> None:
    task_manager.user_logic_registers_tasks()
    await sleep(0)

    await task_manager.get_task("task name")

    # assert something ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low Should be addressed at some point in the future
Development

Successfully merging a pull request may close this issue.

1 participant