More work on dnd kitten

This commit is contained in:
Kovid Goyal
2026-04-26 22:55:11 +05:30
parent 9acc16cc44
commit 3e46fa9f81
4 changed files with 77 additions and 45 deletions

View File

@@ -408,8 +408,17 @@ class PTY:
os.close(self.slave_fd)
del self.slave_fd
if self.child_pid > 0 and not self.child_waited_for:
os.waitpid(self.child_pid, 0)
self.child_waited_for = True
st = time.monotonic()
while time.monotonic() - st < 2:
pid, ec = os.waitpid(self.child_pid, os.WNOHANG)
if pid == self.child_pid:
self.child_waited_for = True
break
time.sleep(0.1)
if not self.child_waited_for:
os.kill(self.child_pid, signal.SIGKILL)
os.waitpid(self.child_pid, 0)
self.child_waited_for = True
def write_to_child(self, data, flush=False):
if isinstance(data, str):
@@ -453,7 +462,9 @@ class PTY:
msg = 'The condition was not met'
if timeout_msg is not None:
msg = timeout_msg()
raise TimeoutError(f'Timed out after {timeout} seconds: {msg}. {self.screen_contents_for_error()}')
if not msg.endswith('\n'):
msg += '. '
raise TimeoutError(f'Timed out after {timeout} seconds: {msg}{self.screen_contents_for_error()}')
def wait_till_child_exits(self, timeout=30 if BaseTest.is_ci else 10, require_exit_code=None):
end_time = time.monotonic() + timeout

View File

@@ -129,6 +129,8 @@ class TestDnDKitten(BaseTest):
def reset_kitten(self, remote_client: bool, clear_tdir=True):
if clear_tdir:
self.send_dnd_command_to_kitten('PING')
self.wait_for_responses('PONG')
shutil.rmtree(self.kitten_wd)
os.mkdir(self.kitten_wd)
shutil.rmtree(self.src_data_dir)
@@ -160,7 +162,7 @@ class TestDnDKitten(BaseTest):
def wait_till():
return q == self.messages_from_kitten.strip()
try:
self.pty.wait_till(wait_till, timeout, lambda: f'Responses so far: Expected:\n{q!r}\nActual:\n{self.messages_from_kitten.strip()!r} != {q!r}')
self.pty.wait_till(wait_till, timeout, lambda: f'Responses so far: Expected:\n{q!r}\nActual:\n{self.messages_from_kitten.strip()!r}\n')
finally:
self.messages_from_kitten = ''
@@ -249,16 +251,21 @@ class TestDnDKitten(BaseTest):
dnd_test_fake_drop_data(self.capture.window_id, mime, chunk, 0, True)
dnd_test_fake_drop_data(self.capture.window_id, mime, b'')
self.send_dnd_command_to_kitten('DROP_IS_REMOTE')
self.wait_for_responses(str(remote_client))
with open(os.path.join(self.src_data_dir, 'some-image.png'), 'rb') as f:
send_file_in_chunks(f, 'image/png', 1117)
self.send_dnd_command_to_kitten('DROP_IS_REMOTE')
self.wait_for_responses(str(remote_client))
self.send_dnd_command_to_kitten('DROP_URI_LIST')
self.wait_for_responses('|'.join(path_list))
jn = os.path.join
self.assert_files_have_same_content(jn(self.src_data_dir, 'some-image.png'), jn(self.kitten_wd, img_drop_path))
shutil.rmtree(os.path.dirname(jn(self.kitten_wd, img_drop_path)))
if remote_client:
pass
else:
self.wait_for_state('drop_action', 0)
def assert_files_have_same_content(self, a, b):
with open(a, 'rb') as fa, open(b, 'rb') as fb: