11extern crate zinit;
22
33use anyhow:: Result ;
4+ use std:: env;
45use std:: path:: Path ;
56use tokio:: time:: { sleep, Duration } ;
6- use std:: env;
77
88use zinit:: app:: api:: Client ;
99use zinit:: testapp;
@@ -12,8 +12,16 @@ use zinit::testapp;
1212async fn main ( ) -> Result < ( ) > {
1313 // Define paths for socket and config
1414 let temp_dir = env:: temp_dir ( ) ;
15- let socket_path = temp_dir. join ( "zinit-test.sock" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
16- let config_dir = temp_dir. join ( "zinit-test-config" ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
15+ let socket_path = temp_dir
16+ . join ( "zinit-test.sock" )
17+ . to_str ( )
18+ . unwrap ( )
19+ . to_string ( ) ;
20+ let config_dir = temp_dir
21+ . join ( "zinit-test-config" )
22+ . to_str ( )
23+ . unwrap ( )
24+ . to_string ( ) ;
1725
1826 println ! ( "Starting zinit with socket at: {}" , socket_path) ;
1927 println ! ( "Using config directory: {}" , config_dir) ;
@@ -29,16 +37,22 @@ async fn main() -> Result<()> {
2937
3038 // Create service configurations
3139 println ! ( "Creating service configurations..." ) ;
32-
40+
3341 // Create a find service
34- testapp:: create_service_config ( & config_dir, "find-service" , "find / -name \" *.txt\" -type f" ) . await ?;
35-
42+ testapp:: create_service_config (
43+ & config_dir,
44+ "find-service" ,
45+ "find / -name \" *.txt\" -type f" ,
46+ )
47+ . await ?;
48+
3649 // Create a sleep service with echo
3750 testapp:: create_service_config (
38- & config_dir,
39- "sleep-service" ,
40- "sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'"
41- ) . await ?;
51+ & config_dir,
52+ "sleep-service" ,
53+ "sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'" ,
54+ )
55+ . await ?;
4256
4357 // Wait for zinit to load the configurations
4458 sleep ( Duration :: from_secs ( 1 ) ) . await ;
@@ -58,7 +72,7 @@ async fn main() -> Result<()> {
5872 // Start the find service
5973 println ! ( "\n Starting find-service..." ) ;
6074 client. start ( "find-service" ) . await ?;
61-
75+
6276 // Wait a bit and check status
6377 sleep ( Duration :: from_secs ( 2 ) ) . await ;
6478 let status = client. status ( "find-service" ) . await ?;
@@ -67,7 +81,7 @@ async fn main() -> Result<()> {
6781 // Start the sleep service
6882 println ! ( "\n Starting sleep-service..." ) ;
6983 client. start ( "sleep-service" ) . await ?;
70-
84+
7185 // Wait a bit and check status
7286 sleep ( Duration :: from_secs ( 2 ) ) . await ;
7387 let status = client. status ( "sleep-service" ) . await ?;
@@ -76,7 +90,7 @@ async fn main() -> Result<()> {
7690 // Stop the find service
7791 println ! ( "\n Stopping find-service..." ) ;
7892 client. stop ( "find-service" ) . await ?;
79-
93+
8094 // Wait a bit and check status
8195 sleep ( Duration :: from_secs ( 2 ) ) . await ;
8296 let status = client. status ( "find-service" ) . await ?;
@@ -85,15 +99,16 @@ async fn main() -> Result<()> {
8599 // Kill the sleep service with SIGTERM
86100 println ! ( "\n Killing sleep-service with SIGTERM..." ) ;
87101 client. kill ( "sleep-service" , "SIGTERM" ) . await ?;
88-
102+
89103 // Wait a bit and check status
90104 sleep ( Duration :: from_secs ( 2 ) ) . await ;
91105 let status = client. status ( "sleep-service" ) . await ?;
92106 println ! ( "sleep-service status after killing: {:?}" , status) ;
93107
94108 // Cleanup - forget services
95109 println ! ( "\n Forgetting services..." ) ;
96- if status. pid == 0 { // Only forget if it's not running
110+ if status. pid == 0 {
111+ // Only forget if it's not running
97112 client. forget ( "sleep-service" ) . await ?;
98113 }
99114 client. forget ( "find-service" ) . await ?;
@@ -104,4 +119,4 @@ async fn main() -> Result<()> {
104119
105120 println ! ( "\n Test completed successfully!" ) ;
106121 Ok ( ( ) )
107- }
122+ }
0 commit comments