BlueGit

ict rusty-teams

fix(test): x11 input test picks a free display and stops waiting after 5 s

- Xvfb picks its own display (-displayfd), no fixed :87
- Server stops with SIGTERM, so no stale /tmp/.X<n>-lock blocks the next run
- A stale lock made the test poll 50 TCP connects: 135 s for app-base, now 5 s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-15 · 6 weeks ago

Hash
224fd423d471b34265bc67298fd85d6660a56158
Parent
d39bdfed
1 file changed +25 −16
crates/app-base/src/notify/platform/x11_input.rs +25 −16
@@ -28,7 +28,9 @@ pub fn make_input_transparent(window: &Window) {
28 28
29 29 #[cfg(test)]
30 30 mod tests {
31 use std::io::{BufRead, BufReader};
31 32 use std::process::{Child, Command, Stdio};
33 use std::sync::mpsc;
32 34 use std::time::Duration;
33 35
34 36 use x11rb::connection::Connection;
@@ -37,38 +39,45 @@ mod tests {
37 39
38 40 use super::*;
39 41
42 const SERVER_START_TIMEOUT: Duration = Duration::from_secs(5);
43
40 44 struct Server(Child);
41 45
42 46 impl Drop for Server {
43 47 fn drop(&mut self) {
44 let _ = self.0.kill();
48 // SIGKILL leaves /tmp/.X<n>-lock behind, and the next run then cannot claim that display.
49 let _ = Command::new("kill").arg(self.0.id().to_string()).status();
50 let _ = self.0.wait();
45 51 }
46 52 }
47 53
48 fn start_server(display: &str) -> Option<Server> {
49 let child = Command::new("Xvfb")
50 .args([display, "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
51 .stdout(Stdio::null())
54 fn start_server() -> Option<(Server, String)> {
55 let mut child = Command::new("Xvfb")
56 .args(["-displayfd", "1", "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
57 .stdout(Stdio::piped())
52 58 .stderr(Stdio::null())
53 59 .spawn()
54 60 .ok()?;
61 let stdout = child.stdout.take()?;
55 62 let server = Server(child);
56 for _ in 0..50 {
57 if RustConnection::connect(Some(display)).is_ok() {
58 return Some(server);
59 }
60 std::thread::sleep(Duration::from_millis(100));
61 }
62 None
63 let (sender, receiver) = mpsc::channel();
64 std::thread::spawn(move || {
65 let mut number = String::new();
66 let _ = BufReader::new(stdout).read_line(&mut number);
67 let _ = sender.send(number);
68 });
69 let number = receiver.recv_timeout(SERVER_START_TIMEOUT).ok()?;
70 let display = format!(":{}", number.trim());
71 RustConnection::connect(Some(&display)).ok()?;
72 Some((server, display))
63 73 }
64 74
65 75 #[test]
66 76 fn the_border_window_gets_an_empty_input_region() {
67 let display = ":87";
68 let Some(_server) = start_server(display) else {
77 let Some((_server, display)) = start_server() else {
69 78 return;
70 79 };
71 let (connection, screen_number) = RustConnection::connect(Some(display)).unwrap();
80 let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();
72 81 let root = connection.setup().roots[screen_number].root;
73 82 let window = connection.generate_id().unwrap();
74 83 connection
@@ -77,7 +86,7 @@ mod tests {
77 86 connection.flush().unwrap();
78 87 let before = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
79 88 assert_eq!(before.rectangles.len(), 1);
80 empty_input_region(Some(display), window).unwrap();
89 empty_input_region(Some(&display), window).unwrap();
81 90 let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
82 91 assert!(after.rectangles.is_empty());
83 92 }
@@ -28,7 +28,9 @@ pub fn make_input_transparent(window: &Window) {
28
28
29#[cfg(test)]
29#[cfg(test)]
30mod tests {
30mod tests {
31 use std::io::{BufRead, BufReader};
31 use std::process::{Child, Command, Stdio};
32 use std::process::{Child, Command, Stdio};
33 use std::sync::mpsc;
32 use std::time::Duration;
34 use std::time::Duration;
33
35
34 use x11rb::connection::Connection;
36 use x11rb::connection::Connection;
@@ -37,38 +39,45 @@ mod tests {
37
39
38 use super::*;
40 use super::*;
39
41
42 const SERVER_START_TIMEOUT: Duration = Duration::from_secs(5);
43
40 struct Server(Child);
44 struct Server(Child);
41
45
42 impl Drop for Server {
46 impl Drop for Server {
43 fn drop(&mut self) {
47 fn drop(&mut self) {
44 let _ = self.0.kill();
48 // SIGKILL leaves /tmp/.X<n>-lock behind, and the next run then cannot claim that display.
49 let _ = Command::new("kill").arg(self.0.id().to_string()).status();
50 let _ = self.0.wait();
45 }
51 }
46 }
52 }
47
53
48 fn start_server(display: &str) -> Option<Server> {
54 fn start_server() -> Option<(Server, String)> {
49 let child = Command::new("Xvfb")
55 let mut child = Command::new("Xvfb")
50 .args([display, "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
56 .args(["-displayfd", "1", "-screen", "0", "320x200x24", "-nolisten", "tcp", "-noreset"])
51 .stdout(Stdio::null())
57 .stdout(Stdio::piped())
52 .stderr(Stdio::null())
58 .stderr(Stdio::null())
53 .spawn()
59 .spawn()
54 .ok()?;
60 .ok()?;
61 let stdout = child.stdout.take()?;
55 let server = Server(child);
62 let server = Server(child);
56 for _ in 0..50 {
63 let (sender, receiver) = mpsc::channel();
57 if RustConnection::connect(Some(display)).is_ok() {
64 std::thread::spawn(move || {
58 return Some(server);
65 let mut number = String::new();
59 }
66 let _ = BufReader::new(stdout).read_line(&mut number);
60 std::thread::sleep(Duration::from_millis(100));
67 let _ = sender.send(number);
61 }
68 });
62 None
69 let number = receiver.recv_timeout(SERVER_START_TIMEOUT).ok()?;
70 let display = format!(":{}", number.trim());
71 RustConnection::connect(Some(&display)).ok()?;
72 Some((server, display))
63 }
73 }
64
74
65 #[test]
75 #[test]
66 fn the_border_window_gets_an_empty_input_region() {
76 fn the_border_window_gets_an_empty_input_region() {
67 let display = ":87";
77 let Some((_server, display)) = start_server() else {
68 let Some(_server) = start_server(display) else {
69 return;
78 return;
70 };
79 };
71 let (connection, screen_number) = RustConnection::connect(Some(display)).unwrap();
80 let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();
72 let root = connection.setup().roots[screen_number].root;
81 let root = connection.setup().roots[screen_number].root;
73 let window = connection.generate_id().unwrap();
82 let window = connection.generate_id().unwrap();
74 connection
83 connection
@@ -77,7 +86,7 @@ mod tests {
77 connection.flush().unwrap();
86 connection.flush().unwrap();
78 let before = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
87 let before = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
79 assert_eq!(before.rectangles.len(), 1);
88 assert_eq!(before.rectangles.len(), 1);
80 empty_input_region(Some(display), window).unwrap();
89 empty_input_region(Some(&display), window).unwrap();
81 let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
90 let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
82 assert!(after.rectangles.is_empty());
91 assert!(after.rectangles.is_empty());
83 }
92 }