From 8d0da8ccfcf1cae3ecc4328e5b8e6b2b20571289 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Sun, 23 Jun 2024 20:37:39 -0500 Subject: [PATCH] Fix keyboard focus tests Wait a bit for each window to spawn fully --- tests/common/mod.rs | 4 ++++ tests/lua_api.rs | 16 ++++++++++++--- tests/rust_api.rs | 50 ++++++++++++++++++++++++++++++--------------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index bfef35d..97ca1c6 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -23,6 +23,10 @@ pub fn sleep_secs(secs: u64) { std::thread::sleep(Duration::from_secs(secs)); } +pub fn sleep_millis(millis: u64) { + std::thread::sleep(Duration::from_millis(millis)); +} + pub fn test_api(test: F) -> anyhow::Result<()> where F: FnOnce(Sender>) -> anyhow::Result<()> diff --git a/tests/lua_api.rs b/tests/lua_api.rs index 10829bf..003df6f 100644 --- a/tests/lua_api.rs +++ b/tests/lua_api.rs @@ -442,6 +442,8 @@ mod output { use super::*; mod handle { + use common::sleep_millis; + use super::*; #[tokio::main] @@ -551,16 +553,24 @@ mod output { run_lua! { |Pinnacle| Pinnacle.process.spawn("foot") + } + sleep_millis(250); + run_lua! { |Pinnacle| Pinnacle.process.spawn("foot") + } + sleep_millis(250); + run_lua! { |Pinnacle| Pinnacle.process.spawn("foot") } - sleep_secs(1); + sleep_millis(250); run_lua! { |Pinnacle| Pinnacle.tag.get("2"):switch_to() - Pinnacle.process.spawn("foot") + } + sleep_millis(250); + run_lua! { |Pinnacle| Pinnacle.process.spawn("foot") } @@ -576,7 +586,7 @@ mod output { print(focus_stack[3].id) print(focus_stack[4].id) print(focus_stack[5].id) - // FIXME: the below statement failed in github CI, idk why + assert(focus_stack[1].id == 0, "focus stack at 1 id != 0") assert(focus_stack[2].id == 1, "focus stack at 2 id != 1") assert(focus_stack[3].id == 2, "focus stack at 3 id != 2") diff --git a/tests/rust_api.rs b/tests/rust_api.rs index 3872865..7b7ca22 100644 --- a/tests/rust_api.rs +++ b/tests/rust_api.rs @@ -318,6 +318,7 @@ mod output { } mod handle { + use common::sleep_millis; use pinnacle::window::window_state::WindowId; use pinnacle_api::output::Transform; @@ -406,15 +407,24 @@ mod output { run_rust(|api| { api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); })?; - sleep_secs(1); + sleep_millis(250); run_rust(|api| { api.tag.get("2").unwrap().switch_to(); api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); })?; @@ -424,12 +434,12 @@ mod output { api.tag.get("1").unwrap().switch_to(); let focus_stack = api.output.get_focused().unwrap().keyboard_focus_stack(); - assert!(dbg!(focus_stack.len()) == 5); - assert!(focus_stack[0].id() == 0); - assert!(focus_stack[1].id() == 1); - assert!(focus_stack[2].id() == 2); - assert!(focus_stack[3].id() == 3); - assert!(focus_stack[4].id() == 4); + assert_eq!(focus_stack.len(), 5); + assert_eq!(focus_stack[0].id(), 0); + assert_eq!(focus_stack[1].id(), 1); + assert_eq!(focus_stack[2].id(), 2); + assert_eq!(focus_stack[3].id(), 3); + assert_eq!(focus_stack[4].id(), 4); })?; // Terminate all windows related to this test @@ -465,17 +475,25 @@ mod output { sleep_secs(1); run_rust(|api| { - api.tag.get("1").unwrap().switch_to(); api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); })?; - sleep_secs(1); + sleep_millis(250); run_rust(|api| { api.tag.get("2").unwrap().switch_to(); api.process.spawn(["foot"]); + })?; + sleep_millis(250); + run_rust(|api| { api.process.spawn(["foot"]); })?; @@ -489,10 +507,10 @@ mod output { .get_focused() .unwrap() .keyboard_focus_stack_visible(); - assert!(focus_stack.len() == 3); - assert!(focus_stack[0].id() == 0); - assert!(focus_stack[1].id() == 1); - assert!(focus_stack[2].id() == 2); + assert_eq!(focus_stack.len(), 3); + assert_eq!(focus_stack[0].id(), 0); + assert_eq!(focus_stack[1].id(), 1); + assert_eq!(focus_stack[2].id(), 2); api.tag.get("2").unwrap().switch_to(); @@ -501,9 +519,9 @@ mod output { .get_focused() .unwrap() .keyboard_focus_stack_visible(); - assert!(focus_stack.len() == 2); - assert!(focus_stack[0].id() == 3); - assert!(focus_stack[1].id() == 4); + assert_eq!(focus_stack.len(), 2); + assert_eq!(focus_stack[0].id(), 3); + assert_eq!(focus_stack[1].id(), 4); })?; // Terminate all windows related to this test