Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,34 @@ def is_running(self):
"""
return self.running.is_set()

def _wait_events(self, events: list[Event], ignored: list[Event], strict: bool):
def _wait_events(self, events: list[Event], strict: bool):
while self.is_running():
msg = self.get_next()
if msg is None:
sleep(0.5)
continue

print(f'Got event: {msg}')
if msg in ignored:
raise ValueError(f'Caught ignored event: {msg}')

if msg in events:
events.remove(msg)
if len(events) == 0:
break
elif strict:
raise ValueError(f'Encountered unexpected event: {msg}')

def wait_events(self, events: list[Event], ignored: list[Event] = [], strict: bool = False):
def wait_events(self, events: list[Event], strict: bool = True):
"""
Continuously checks the server for incoming events until the
specified events are found.

Args:
server: The server instance to retrieve events from.
event (list[Event]): The events to search for.
ignored (list[Event]): List of events that should not happen.
strict (bool): Fail if an unexpected event is detected.

Raises:
TimeoutError: If the required events are not found in 5 seconds.
"""
fs = self.executor.submit(self._wait_events, events, ignored, strict)
print('Waiting for events:', *events, sep='\n')
fs = self.executor.submit(self._wait_events, events, strict)
fs.result(timeout=5)
24 changes: 3 additions & 21 deletions tests/test_config_hotreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def test_output_grpc_address_change(fact, fact_config, monitored_dir, server, al
process = Process.from_proc()
e = Event(process=process, event_type=EventType.CREATION,
file=fut, host_path='')
print(f'Waiting for event: {e}')

server.wait_events([e])

Expand All @@ -114,7 +113,6 @@ def test_output_grpc_address_change(fact, fact_config, monitored_dir, server, al

e = Event(process=process, event_type=EventType.OPEN,
file=fut, host_path='')
print(f'Waiting for event on alternate server: {e}')

alternate_server.wait_events([e])

Expand All @@ -127,20 +125,15 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server):
with open(ignored_file, 'w') as f:
f.write('This is to be ignored')

ignored_event = Event(process=p, event_type=EventType.CREATION,
file=ignored_file, host_path='')
print(f'Ignoring: {ignored_event}')

# File Under Test
fut = os.path.join(monitored_dir, 'test2.txt')
with open(fut, 'w') as f:
f.write('This is a test')

e = Event(process=p, event_type=EventType.CREATION,
file=fut, host_path='')
print(f'Waiting for event: {e}')

server.wait_events([e], ignored=[ignored_event])
server.wait_events([e])

config, config_file = fact_config
config['paths'] = [ignored_dir]
Expand All @@ -153,17 +146,12 @@ def test_paths(fact, fact_config, monitored_dir, ignored_dir, server):

e = Event(process=p, event_type=EventType.OPEN,
file=ignored_file, host_path='')
print(f'Waiting for event: {e}')

# File Under Test
with open(fut, 'w') as f:
f.write('This is another ignored event')

ignored_event = Event(
process=p, event_type=EventType.OPEN, file=fut, host_path='')
print(f'Ignoring: {ignored_event}')

server.wait_events([e], ignored=[ignored_event])
server.wait_events([e])


def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server):
Expand All @@ -174,20 +162,15 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server):
with open(ignored_file, 'w') as f:
f.write('This is to be ignored')

ignored_event = Event(process=p, event_type=EventType.CREATION,
file=ignored_file, host_path='')
print(f'Ignoring: {ignored_event}')

# File Under Test
fut = os.path.join(monitored_dir, 'test2.txt')
with open(fut, 'w') as f:
f.write('This is a test')

e = Event(process=p, event_type=EventType.CREATION,
file=fut, host_path='')
print(f'Waiting for event: {e}')

server.wait_events([e], ignored=[ignored_event])
server.wait_events([e])

config, config_file = fact_config
config['paths'] = [monitored_dir, ignored_dir]
Expand All @@ -205,6 +188,5 @@ def test_paths_addition(fact, fact_config, monitored_dir, ignored_dir, server):
file=ignored_file, host_path=''),
Event(process=p, event_type=EventType.OPEN, file=fut, host_path='')
]
print(f'Waiting for events: {events}')

server.wait_events(events)
12 changes: 0 additions & 12 deletions tests/test_editors/test_nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ def test_new_file(editor_container, server):
file=fut, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -67,9 +64,6 @@ def test_open_file(editor_container, server):
file=f'{fut}~', host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand All @@ -92,9 +86,6 @@ def test_new_file_ovfs(editor_container, server):
file=fut, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -145,7 +136,4 @@ def test_open_file_ovfs(editor_container, server):
file=f'{fut}~', host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)
6 changes: 0 additions & 6 deletions tests/test_editors/test_sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def test_sed(vi_container, server):
file=sed_tmp_file, host_path='', owner_uid=0, owner_gid=0),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -76,7 +73,4 @@ def test_sed_ovfs(vi_container, server):
file=sed_tmp_file, host_path='', owner_uid=0, owner_gid=0),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)
12 changes: 0 additions & 12 deletions tests/test_editors/test_vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def test_new_file(vi_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -82,9 +79,6 @@ def test_new_file_ovfs(vi_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -145,9 +139,6 @@ def test_open_file(vi_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -220,7 +211,4 @@ def test_open_file_ovfs(vi_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)
12 changes: 0 additions & 12 deletions tests/test_editors/test_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def test_new_file(editor_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -78,9 +75,6 @@ def test_new_file_ovfs(editor_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -140,9 +134,6 @@ def test_open_file(editor_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)


Expand Down Expand Up @@ -214,7 +205,4 @@ def test_open_file_ovfs(editor_container, server):
file=swap_file, host_path=''),
]

for e in events:
print(f'Waiting for event: {e}')

server.wait_events(events, strict=True)
Loading
Loading