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

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

Closed
llucax opened this issue Sep 25, 2024 · 1 comment · Fixed by #326
Closed

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

llucax opened this issue Sep 25, 2024 · 1 comment · Fixed by #326
Labels
part:tests Affects the unit, integration and performance (benchmarks) tests priority:high Address this as soon as possible type:bug Something isn't working
Milestone

Comments

@llucax
Copy link
Contributor

llucax commented Sep 25, 2024

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

@llucax llucax added part:tests Affects the unit, integration and performance (benchmarks) tests priority:high Address this as soon as possible type:bug Something isn't working labels Sep 25, 2024
@llucax llucax added this to the v1.2.1 milestone Sep 25, 2024
@llucax
Copy link
Contributor Author

llucax commented Sep 25, 2024

Looks like the issue is we are watching the whole test directory.

github-merge-queue bot pushed a commit that referenced this issue Sep 26, 2024
When watching the whole test directory we'll also get some events for
the directory, and those events can come with different order depending
on the OS, so we can't rely on them. We check that if a directory event
comes, it is a modification.

Also when testing for events in a file watcher, we need to set the
`polling_interval` to a value that is small enough to detect the changes
we are expecting, otherwise some events could be "merged" if the changes
happen faster than the polling interval.

Fixes #324.
@shsms shsms modified the milestones: v1.2.1, v1.3.0 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:tests Affects the unit, integration and performance (benchmarks) tests priority:high Address this as soon as possible type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants