Skip to content

Commit 38b917f

Browse files
bmehta001Copilot
andcommitted
Fix Rust clippy for cancellation tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ff753f0 commit 38b917f

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

sdk/rust/src/detail/core_interop.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -235,38 +235,6 @@ impl<'a> StreamingCallbackState<'a> {
235235
}
236236
}
237237

238-
#[cfg(test)]
239-
mod tests {
240-
use super::StreamingCallbackState;
241-
use std::sync::{
242-
atomic::{AtomicBool, Ordering},
243-
Arc,
244-
};
245-
246-
#[test]
247-
fn cancellation_request_after_callback_is_not_observed_until_next_callback() {
248-
let cancel_flag = Arc::new(AtomicBool::new(false));
249-
let mut callback = |_chunk: &str| {};
250-
let mut state =
251-
StreamingCallbackState::with_cancel(&mut callback, Arc::clone(&cancel_flag));
252-
253-
state.push(b"100");
254-
cancel_flag.store(true, Ordering::Relaxed);
255-
256-
assert!(!state.cancellation_observed());
257-
}
258-
259-
#[test]
260-
fn cancellation_is_recorded_when_callback_observes_cancel_flag() {
261-
let cancel_flag = Arc::new(AtomicBool::new(true));
262-
let mut callback = |_chunk: &str| {};
263-
let mut state = StreamingCallbackState::with_cancel(&mut callback, cancel_flag);
264-
265-
assert!(state.mark_cancelled_if_requested());
266-
assert!(state.cancellation_observed());
267-
}
268-
}
269-
270238
///
271239
/// * `data` must be a valid pointer to `length` bytes of UTF-8 (or at least
272240
/// valid memory) allocated by the native core, valid for the duration of
@@ -836,3 +804,35 @@ impl CoreInterop {
836804
Ok(libs)
837805
}
838806
}
807+
808+
#[cfg(test)]
809+
mod tests {
810+
use super::StreamingCallbackState;
811+
use std::sync::{
812+
atomic::{AtomicBool, Ordering},
813+
Arc,
814+
};
815+
816+
#[test]
817+
fn cancellation_request_after_callback_is_not_observed_until_next_callback() {
818+
let cancel_flag = Arc::new(AtomicBool::new(false));
819+
let mut callback = |_chunk: &str| {};
820+
let mut state =
821+
StreamingCallbackState::with_cancel(&mut callback, Arc::clone(&cancel_flag));
822+
823+
state.push(b"100");
824+
cancel_flag.store(true, Ordering::Relaxed);
825+
826+
assert!(!state.cancellation_observed());
827+
}
828+
829+
#[test]
830+
fn cancellation_is_recorded_when_callback_observes_cancel_flag() {
831+
let cancel_flag = Arc::new(AtomicBool::new(true));
832+
let mut callback = |_chunk: &str| {};
833+
let mut state = StreamingCallbackState::with_cancel(&mut callback, cancel_flag);
834+
835+
assert!(state.mark_cancelled_if_requested());
836+
assert!(state.cancellation_observed());
837+
}
838+
}

0 commit comments

Comments
 (0)