Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Reduce post-start command sleep times for faster tests

Maximilian Roosc923421941e2
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index 3b87b4dd2..edef7dc57 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -28,7 +28,7 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
fs::write(
config_dir.join("wt.toml"),
- r#"post-start-command = "sleep 0.5 && echo 'Background task done' > bg_marker.txt""#,
+ r#"post-start-command = "sleep 0.05 && echo 'Background task done' > bg_marker.txt""#,
)
.expect("Failed to write config");
@@ -40,7 +40,7 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
r#"worktree-path = "../{main-worktree}.{branch}"
[projects."test-repo"]
-approved-commands = ["sleep 0.5 && echo 'Background task done' > bg_marker.txt"]
+approved-commands = ["sleep 0.05 && echo 'Background task done' > bg_marker.txt"]
"#,
)
.expect("Failed to write user config");
@@ -71,8 +71,8 @@ approved-commands = ["sleep 0.5 && echo 'Background task done' > bg_marker.txt"]
output
);
- // Wait for background command to complete
- thread::sleep(Duration::from_secs(2));
+ // Wait for background command to complete (command has sleep 0.05 + margin)
+ thread::sleep(Duration::from_millis(150));
// Verify background command actually ran
let worktree_path = repo
@@ -143,8 +143,8 @@ fn test_bash_post_start_multiple_parallel_commands() {
fs::write(
config_dir.join("wt.toml"),
r#"[post-start-command]
-task1 = "sleep 0.5 && echo 'Task 1' > task1.txt"
-task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"
+task1 = "sleep 0.05 && echo 'Task 1' > task1.txt"
+task2 = "sleep 0.05 && echo 'Task 2' > task2.txt"
"#,
)
.expect("Failed to write config");
@@ -158,8 +158,8 @@ task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"
[projects."test-repo"]
approved-commands = [
- "sleep 0.5 && echo 'Task 1' > task1.txt",
- "sleep 0.5 && echo 'Task 2' > task2.txt",
+ "sleep 0.05 && echo 'Task 1' > task1.txt",
+ "sleep 0.05 && echo 'Task 2' > task2.txt",
]
"#,
)
@@ -187,8 +187,8 @@ approved-commands = [
output
);
- // Wait for background commands to complete
- thread::sleep(Duration::from_secs(1));
+ // Wait for background commands to complete (commands have sleep 0.05 + margin)
+ thread::sleep(Duration::from_millis(150));
// Verify both background commands ran
let worktree_path = repo
@@ -290,7 +290,7 @@ fn test_fish_post_start_background() {
fs::write(
config_dir.join("wt.toml"),
r#"[post-start-command]
-fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
+fish_bg = "sleep 0.05 && echo 'Fish background done' > fish_bg.txt"
"#,
)
.expect("Failed to write config");
@@ -303,7 +303,7 @@ fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
r#"worktree-path = "../{main-worktree}.{branch}"
[projects."test-repo"]
-approved-commands = ["sleep 0.5 && echo 'Fish background done' > fish_bg.txt"]
+approved-commands = ["sleep 0.05 && echo 'Fish background done' > fish_bg.txt"]
"#,
)
.expect("Failed to write test config");
@@ -331,8 +331,8 @@ approved-commands = ["sleep 0.5 && echo 'Fish background done' > fish_bg.txt"]
output
);
- // Wait for background command
- thread::sleep(Duration::from_secs(1));
+ // Wait for background command (command has sleep 0.05 + margin)
+ thread::sleep(Duration::from_millis(150));
// Verify background command ran
let worktree_path = repo
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 58d59d422..45e6fdfa8 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -9,13 +9,14 @@ use std::time::Duration;
// These allow time for background processes to complete and write output files
/// Short wait for fast commands (simple echo statements)
-const SLEEP_FAST_COMMAND: Duration = Duration::from_millis(500);
+const SLEEP_FAST_COMMAND: Duration = Duration::from_millis(100);
/// Standard wait for background commands with sleep/processing
-const SLEEP_BACKGROUND_COMMAND: Duration = Duration::from_secs(1);
+const SLEEP_BACKGROUND_COMMAND: Duration = Duration::from_millis(200);
-/// Extended wait for commands that need extra time (e.g., in e2e shell tests)
-const SLEEP_EXTENDED: Duration = Duration::from_secs(2);
+/// Extended wait for commands that include explicit sleep in the command itself
+/// (e.g., "sleep 0.1 && echo ..." requires at least 100ms + margin)
+const SLEEP_EXTENDED: Duration = Duration::from_millis(250);
/// Helper to create snapshot with normalized paths and SHAs
///
@@ -238,7 +239,7 @@ fn test_post_start_single_background_command() {
// Create project config with a background command
repo.write_project_config(
- r#"post-start-command = "sleep 1 && echo 'Background task done' > background.txt""#,
+ r#"post-start-command = "sleep 0.1 && echo 'Background task done' > background.txt""#,
);
repo.commit("Add background command");
@@ -248,7 +249,7 @@ fn test_post_start_single_background_command() {
r#"worktree-path = "../{main-worktree}.{branch}"
[projects."test-repo"]
-approved-commands = ["sleep 1 && echo 'Background task done' > background.txt"]
+approved-commands = ["sleep 0.1 && echo 'Background task done' > background.txt"]
"#,
);
@@ -329,7 +330,7 @@ fn test_both_post_create_and_post_start() {
r#"post-create-command = "echo 'Setup done' > setup.txt"
[post-start-command]
-server = "sleep 0.5 && echo 'Server running' > server.txt"
+server = "sleep 0.05 && echo 'Server running' > server.txt"
"#,
);
@@ -342,7 +343,7 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"
[projects."test-repo"]
approved-commands = [
"echo 'Setup done' > setup.txt",
- "sleep 0.5 && echo 'Server running' > server.txt",
+ "sleep 0.05 && echo 'Server running' > server.txt",
]
"#,
);
@@ -357,8 +358,8 @@ approved-commands = [
"Post-create command should have completed before wt exits"
);
- // Wait for background command
- thread::sleep(SLEEP_BACKGROUND_COMMAND);
+ // Wait for background command (command has sleep 0.05 + margin)
+ thread::sleep(Duration::from_millis(150));
// Server file should exist after background task completes
assert!(
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
index 998c052cb..aa8f3c6b6 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__both_create_and_start.snap
@@ -17,7 +17,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp9MgCyO/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpJGcCK2/test-config.toml
---
success: true
exit_code: 0
@@ -27,7 +27,7 @@ exit_code: 0
βœ… Created new worktree for feature from main at [REPO].feature
πŸ’‘ To enable automatic cd, run: wt config shell
πŸ”„ Running post-start server:
-  sleep 0.5 && echo 'Server running' > server.txt
+  sleep 0.05 && echo 'Server running' > server.txt
----- stderr -----

diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
index c7d3a8eea..1865521d4 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_single_background.snap
@@ -17,7 +17,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpivRQ5w/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpg1VG2v/test-config.toml
---
success: true
exit_code: 0
@@ -25,6 +25,6 @@ exit_code: 0
βœ… Created new worktree for feature from main at [REPO].feature
πŸ’‘ To enable automatic cd, run: wt config shell
πŸ”„ Running post-start:
-  sleep 1 && echo 'Background task done' > background.txt
+  sleep 0.1 && echo 'Background task done' > background.txt
----- stderr -----