Skip to content

tests/test_file_watcher_integration.py became flaky after using force_polling=True #324

@llucax

Description

@llucax

What happened?

We are having some sporadic failures, specifically in cross-arch tests (both pytest_min and pytest_max), for file watcher integration tests. In particular this test seems to be flaky: tests/test_file_watcher_integration.py::test_file_watcher.

=================================== FAILURES ===================================
______________________________ test_file_watcher _______________________________

tmp_path = PosixPath('/tmp/pytest-of-root/pytest-0/test_file_watcher0')

    @pytest.mark.integration
    async def test_file_watcher(tmp_path: pathlib.Path) -> None:
        """Ensure file watcher is returning paths on file events.
    
        Args:
            tmp_path: A tmp directory to run the file watcher on. Created by pytest.
        """
        filename = tmp_path / "test-file"
    
        number_of_writes = 0
        expected_number_of_writes = 3
    
        file_watcher = FileWatcher(paths=[str(tmp_path)])
        timer = Timer(timedelta(seconds=0.1), SkipMissedAndDrift())
    
        async for selected in select(file_watcher, timer):
            if selected_from(selected, timer):
                filename.write_text(f"{selected.message}")
            elif selected_from(selected, file_watcher):
                event_type = EventType.CREATE if number_of_writes == 0 else EventType.MODIFY
>               assert selected.message == Event(type=event_type, path=filename)
E               AssertionError: assert Event(type=<EventType.MODIFY: <Change.modified: 2>>, path=PosixPath('/tmp/pytest-of-root/pytest-0/test_file_watcher0')) == Event(type=<EventType.CREATE: <Change.added: 1>>, path=PosixPath('/tmp/pytest-of-root/pytest-0/test_file_watcher0/test-file'))
E                 
E                 Differing attributes:
E                 ['type', 'path']
E                 
E                 Drill down into differing attribute type:
E                   type: <EventType.MODIFY: <Change.modified: 2>> != <EventType.CREATE: <Change.added: 1>>
E                 
E                 Drill down into differing attribute path:
E                   path: PosixPath('/tmp/pytest-of-root/pytest-0/test_file_watcher0') != PosixPath('/tmp/pytest-of-root/pytest-0/test_file_watcher0/test-file')

tests/test_file_watcher_integration.py:37: AssertionError

What did you expect instead?

Test to always pass.

Affected version(s)

v1.2.0

Affected part(s)

Unit, integration and performance tests (part:tests)

Extra information

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:testsAffects the unit, integration and performance (benchmarks) testspriority:highAddress this as soon as possibletype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions