11extern crate zinit;
22
33use anyhow:: Result ;
4- use std:: path:: Path ;
5- use tokio:: time:: { sleep, Duration } ;
64use std:: env;
5+ use tokio:: time:: { sleep, Duration } ;
76
87use zinit:: app:: api:: Client ;
98use zinit:: testapp;
@@ -12,8 +11,16 @@ use zinit::testapp;
1211async fn main ( ) -> Result < ( ) > {
1312 // Define paths for socket and config
1413 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 ( ) ;
14+ let socket_path = temp_dir
15+ . join ( "zinit-test.sock" )
16+ . to_str ( )
17+ . unwrap ( )
18+ . to_string ( ) ;
19+ let config_dir = temp_dir
20+ . join ( "zinit-test-config" )
21+ . to_str ( )
22+ . unwrap ( )
23+ . to_string ( ) ;
1724
1825 println ! ( "Starting zinit with socket at: {}" , socket_path) ;
1926 println ! ( "Using config directory: {}" , config_dir) ;
@@ -29,16 +36,22 @@ async fn main() -> Result<()> {
2936
3037 // Create service configurations
3138 println ! ( "Creating service configurations..." ) ;
32-
39+
3340 // Create a find service
34- testapp:: create_service_config ( & config_dir, "find-service" , "find / -name \" *.txt\" -type f" ) . await ?;
35-
41+ testapp:: create_service_config (
42+ & config_dir,
43+ "find-service" ,
44+ "find / -name \" *.txt\" -type f" ,
45+ )
46+ . await ?;
47+
3648 // Create a sleep service with echo
3749 testapp:: create_service_config (
38- & config_dir,
39- "sleep-service" ,
40- "sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'"
41- ) . await ?;
50+ & config_dir,
51+ "sleep-service" ,
52+ "sh -c 'echo Starting sleep; sleep 30; echo Finished sleep'" ,
53+ )
54+ . await ?;
4255
4356 // Wait for zinit to load the configurations
4457 sleep ( Duration :: from_secs ( 1 ) ) . await ;
@@ -58,7 +71,7 @@ async fn main() -> Result<()> {
5871 // Start the find service
5972 println ! ( "\n Starting find-service..." ) ;
6073 client. start ( "find-service" ) . await ?;
61-
74+
6275 // Wait a bit and check status
6376 sleep ( Duration :: from_secs ( 2 ) ) . await ;
6477 let status = client. status ( "find-service" ) . await ?;
@@ -67,7 +80,7 @@ async fn main() -> Result<()> {
6780 // Start the sleep service
6881 println ! ( "\n Starting sleep-service..." ) ;
6982 client. start ( "sleep-service" ) . await ?;
70-
83+
7184 // Wait a bit and check status
7285 sleep ( Duration :: from_secs ( 2 ) ) . await ;
7386 let status = client. status ( "sleep-service" ) . await ?;
@@ -76,7 +89,7 @@ async fn main() -> Result<()> {
7689 // Stop the find service
7790 println ! ( "\n Stopping find-service..." ) ;
7891 client. stop ( "find-service" ) . await ?;
79-
92+
8093 // Wait a bit and check status
8194 sleep ( Duration :: from_secs ( 2 ) ) . await ;
8295 let status = client. status ( "find-service" ) . await ?;
@@ -85,15 +98,16 @@ async fn main() -> Result<()> {
8598 // Kill the sleep service with SIGTERM
8699 println ! ( "\n Killing sleep-service with SIGTERM..." ) ;
87100 client. kill ( "sleep-service" , "SIGTERM" ) . await ?;
88-
101+
89102 // Wait a bit and check status
90103 sleep ( Duration :: from_secs ( 2 ) ) . await ;
91104 let status = client. status ( "sleep-service" ) . await ?;
92105 println ! ( "sleep-service status after killing: {:?}" , status) ;
93106
94107 // Cleanup - forget services
95108 println ! ( "\n Forgetting services..." ) ;
96- if status. pid == 0 { // Only forget if it's not running
109+ if status. pid == 0 {
110+ // Only forget if it's not running
97111 client. forget ( "sleep-service" ) . await ?;
98112 }
99113 client. forget ( "find-service" ) . await ?;
@@ -104,4 +118,4 @@ async fn main() -> Result<()> {
104118
105119 println ! ( "\n Test completed successfully!" ) ;
106120 Ok ( ( ) )
107- }
121+ }
0 commit comments