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

Convert Async unit tests from unittest.TestCase to unittest.IsolatedAsyncioTestCase #711

Open
christophertubbs opened this issue Sep 4, 2024 · 0 comments
Labels
good first issue Good for newcomers Low Hanging Fruit This should not take a lot of time Low Priority This should not take the place of more important work refactor Code Cleanup and Restructuring

Comments

@christophertubbs
Copy link
Contributor

We have several unit tests floating about that test async functionality by manually handling an event loop. These tests should be run via async functions within IsolatedAsyncioTestCase classes rather than the standard TestCase that we're defaulting to.

There's a function I've got locally that's failure when called locally. The unit test looks like:

    def test_can_be_fulfilled_0_a(self):
        """ Test function against first job requirement for example 0 (requires all datasets, no preset fulfills). """
        ex_num = 0
        requirement_index = 0

        job = self.example_jobs[ex_num]
        result = self.loop.run_until_complete(
            self.data_inquery_util.can_be_fulfilled(job.data_requirements[requirement_index]))

        self.assertTrue(result[0])

If an IsolatedAsyncioTestCase were used, it could just be:

    def test_can_be_fulfilled_0_a(self):
        """ Test function against first job requirement for example 0 (requires all datasets, no preset fulfills). """
        ex_num = 0
        requirement_index = 0

        job = self.example_jobs[ex_num]
        result = await self.data_inquery_util.can_be_fulfilled(job.data_requirements[requirement_index])

        self.assertTrue(result[0])

There are other places where tests fail due to event loops being closed. Letting the unit tests handle this behavior natively rather than relying on our own implementations would help prevent/fix issues involved with just running the tests in the first place.

@christophertubbs christophertubbs added good first issue Good for newcomers refactor Code Cleanup and Restructuring Low Priority This should not take the place of more important work Low Hanging Fruit This should not take a lot of time labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers Low Hanging Fruit This should not take a lot of time Low Priority This should not take the place of more important work refactor Code Cleanup and Restructuring
Projects
None yet
Development

No branches or pull requests

1 participant