Skip to content

Commit

Permalink
Add a unit-test to ensure that we can handle file descriptors >1024.
Browse files Browse the repository at this point in the history
  • Loading branch information
g-pichler committed Oct 10, 2024
1 parent 9ddfdd4 commit e10dff8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_inotify_c.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from contextlib import ExitStack

import pytest

from watchdog.utils import platform
Expand Down Expand Up @@ -187,3 +189,23 @@ def test_event_equality(p: P) -> None:
assert event1 == event2
assert event1 != event3
assert event2 != event3


def test_select_fd(p: P, event_queue: TestEventQueue, start_watching: StartWatching) -> None:
# We open a file 2048 times to ensure that we exhaust 1024 file
# descriptors, the limit of a select() call.
path = p("new_file")
with open(path, "a"):
pass
with ExitStack() as stack:
for _i in range(2048):
stack.enter_context(open(path))

# Watch this file for deletion (copied from `test_watch_file`)
path = p("this_is_a_file")
with open(path, "a"):
pass
start_watching(path=path)
os.remove(path)
event, _ = event_queue.get(timeout=5)
assert repr(event)

0 comments on commit e10dff8

Please sign in to comment.