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

Flaky Python tests #8255

Open
rtibbles opened this issue Aug 2, 2021 · 6 comments
Open

Flaky Python tests #8255

rtibbles opened this issue Aug 2, 2021 · 6 comments

Comments

@rtibbles
Copy link
Member

rtibbles commented Aug 2, 2021

Observed behavior

This is a tracking issue to keep track of a few different Python tests that occasionally fail:

  • In kolibri/core/tasks/test/taskrunner/test_job_running.py test_can_cancel_a_job
  • In kolibri/core/tasks/test/taskrunner/test_worker.py test_high_tasks_dont_wait_when_regular_workers_busy can sometimes fail with the fetched job being None - this test seems to specifically only fail on MacOS test runners, when multiprocessing is being used.
  • In kolibri/core/content/test/test_content_app.py for Postgres tests only, anything using _assert_nodes - can seemingly fall victim to inconsistent ordering on occasion (not fixed by Sort data to prevent flaky postgres tests. #8711) - it seems that the ordering did not go far enough, most recent failures suggest that this is actually a result of inconsistent ordering of the files! Fixing that should fix the issue.
  • In kolibri/core/device/test/test_syncqueue.py for Windows test_position_in_queue can occasionally fail with the position being 4 instead of 5 - I think this was resolved by adding time.sleep into tests to ensure proper ordering by time.
  • kolibri/core/test/test_key_urls /api/auth/portal/validate_token/ request is sensitive to Internet connectivity and will give a 500 when unable to connect - this should be updated to give a more semantic error. Fixed in Catch connection errors when validating tokens with KDP. #8559
  • Import export test appears to actually be trying to connect to Studio? Run with no Internet connection to try to replicate: kolibri/core/content/test/test_import_export.py
@vkWeb
Copy link
Member

vkWeb commented Aug 2, 2021

Will look into the first one!

@rtibbles
Copy link
Member Author

rtibbles commented Aug 2, 2021

Will look into the first one!

I suspect, but am not certain, that it is happening during the multiprocessing run of the tests.

@vkWeb
Copy link
Member

vkWeb commented Aug 2, 2021

I suspect, but am not certain, that it is happening during the multiprocessing run of the tests.

Will need to look into why that's the case.

@marcellamaki
Copy link
Member

Closed in error -- only partially fixed

@dbnicholson
Copy link
Contributor

I ran into the last one and it comes from a lack of consistent request mocking. That was exacerbated by 8e64e45 since it now does a HEAD request before any GET requests. I've used requests-mock in another project and it makes it a lot harder to screw up since you'll immediately get errors for any URLs that haven't been registered for mocking.

@rtibbles
Copy link
Member Author

More details for the MacOS worker test failure:

_____ TestWorker.test_high_tasks_dont_wait_when_regular_workers_busy[True] _____

self = <kolibri.core.tasks.test.taskrunner.test_worker.TestWorker object at 0x11d78cc70>
worker = <kolibri.core.tasks.worker.Worker object at 0x119d76560>

    def test_high_tasks_dont_wait_when_regular_workers_busy(self, worker):
        # We have one task running right now.
        worker.future_job_mapping = {"job_id": "future"}
    
        job = Job(id, args=(10,))
        worker.storage.enqueue_job(job, QUEUE, Priority.HIGH)
    
        job = worker.get_next_job()
        worker.future_job_mapping.clear()
    
        # Worker must get this job since its a 'high' priority job.
>       assert isinstance(job, Job) is True
E       assert False is True
E        +  where False = isinstance(None, Job)

kolibri/core/tasks/test/taskrunner/test_worker.py:202: AssertionError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants