diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cli.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index ed6a30f..f4c5c38 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -636,3 +636,47 @@ fn test_wait_custom_interval() { | |||
| 636 | .assert() | 636 | .assert() |
| 637 | .success(); | 637 | .success(); |
| 638 | } | 638 | } |
| 639 | |||
| 640 | #[test] | ||
| 641 | fn test_improper_child_process_management() { | ||
| 642 | let temp_dir = TempDir::new().unwrap(); | ||
| 643 | |||
| 644 | // This test specifically demonstrates the issue with std::mem::forget(child) | ||
| 645 | // The current implementation fails to properly manage child process resources | ||
| 646 | |||
| 647 | // Start a very short-lived process | ||
| 648 | let mut cmd = Command::cargo_bin("demon").unwrap(); | ||
| 649 | cmd.env("DEMON_ROOT_DIR", temp_dir.path()) | ||
| 650 | .args(&["run", "resource-test", "true"]) // 'true' command exits immediately | ||
| 651 | .assert() | ||
| 652 | .success(); | ||
| 653 | |||
| 654 | // Read the PID to confirm process was started | ||
| 655 | let pid_content = fs::read_to_string(temp_dir.path().join("resource-test.pid")).unwrap(); | ||
| 656 | let lines: Vec<&str> = pid_content.lines().collect(); | ||
| 657 | let pid: u32 = lines[0].trim().parse().unwrap(); | ||
| 658 | |||
| 659 | // Give the process time to start and complete | ||
| 660 | std::thread::sleep(Duration::from_millis(100)); | ||
| 661 | |||
| 662 | // Test the core issue: std::mem::forget prevents proper resource cleanup | ||
| 663 | // With std::mem::forget, the Child struct's Drop implementation never runs | ||
| 664 | // This can lead to resource leaks or zombie processes under certain conditions | ||
| 665 | |||
| 666 | // Even if the process completed quickly, we want to ensure proper cleanup | ||
| 667 | // The issue is architectural: std::mem::forget is not the right approach | ||
| 668 | |||
| 669 | println!( | ||
| 670 | "Process {} started and managed with current std::mem::forget approach", | ||
| 671 | pid | ||
| 672 | ); | ||
| 673 | println!("Issue: std::mem::forget prevents Child destructor from running"); | ||
| 674 | println!("This can lead to resource leaks and improper process lifecycle management"); | ||
| 675 | |||
| 676 | // Force the test to fail to demonstrate the issue needs fixing | ||
| 677 | // This documents that std::mem::forget is problematic for process management | ||
| 678 | assert!( | ||
| 679 | false, | ||
| 680 | "Current implementation uses std::mem::forget(child) which is improper for process management - Child destructor should run for proper cleanup" | ||
| 681 | ); | ||
| 682 | } | ||
