File tree Expand file tree Collapse file tree 4 files changed +26
-10
lines changed
Expand file tree Collapse file tree 4 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ args = [
4848 " --" ,
4949 " --test-threads" ,
5050 " 1" ,
51+ " --nocapture" ,
5152]
5253
5354# Test nanocld_client
Original file line number Diff line number Diff line change @@ -81,7 +81,10 @@ mod tests {
8181 "watch events condition"
8282 ) ;
8383 let mut stream = res. into_stream ( ) ;
84- while ( stream. next ( ) . await ) . is_some ( ) { }
84+ while let Some ( Ok ( event) ) = stream. next ( ) . await {
85+ let string = String :: from_utf8_lossy ( & event) ;
86+ log:: info!( "Received event: {string}" ) ;
87+ }
8588 } ) ;
8689 let cargo = CargoSpecPartial {
8790 name : CARGO_NAME . to_owned ( ) ,
Original file line number Diff line number Diff line change @@ -70,11 +70,20 @@ impl TaskManager {
7070
7171 pub async fn remove_task ( & self , key : & str ) {
7272 let mut tasks = self . tasks . lock ( ) . await ;
73- let task = tasks. get ( key) ;
74- if let Some ( task) = task {
75- task. fut . abort ( ) ;
76- log:: debug!( "Removing task: {key} {}" , task. kind) ;
77- tasks. remove ( key) ;
73+ if let Some ( task) = tasks. remove ( key) {
74+ let kind = task. kind . clone ( ) ;
75+ if !task. fut . is_finished ( ) {
76+ log:: debug!( "Cancelling task: {key} {kind}" ) ;
77+ match Arc :: try_unwrap ( task. fut ) {
78+ Ok ( handle) => handle. cancel ( ) ,
79+ Err ( _handle) => {
80+ log:: debug!(
81+ "Task cancellation skipped for {key} {kind} because handle is shared" ,
82+ ) ;
83+ }
84+ }
85+ }
86+ log:: debug!( "Removing task: {key} {kind}" ) ;
7887 }
7988 }
8089
Original file line number Diff line number Diff line change @@ -43,10 +43,13 @@ impl SystemEvent {
4343 }
4444
4545 pub fn handle ( & mut self , _e : SystemEventKind ) {
46- let abort_handle = self . 0 . task . abort_handle ( ) ;
47- if !abort_handle. is_finished ( ) {
48- log:: info!( "system: aborting reload task" ) ;
49- abort_handle. abort ( ) ;
46+ if !self . 0 . task . is_finished ( ) {
47+ log:: info!( "system: canceling reload task" ) ;
48+ let task = std:: mem:: replace (
49+ & mut self . 0 . task ,
50+ rt:: spawn ( async move { Ok :: < _ , IoError > ( ( ) ) } ) ,
51+ ) ;
52+ task. cancel ( ) ;
5053 }
5154 let client = self . 0 . client . clone ( ) ;
5255 self . 0 . task = rt:: spawn ( async move {
You can’t perform that action at this time.
0 commit comments