From 3aef80e9733ed63040d89ce416d9b37d48389311 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 5 Feb 2017 18:21:56 -0700 Subject: Implement Drop for AioCb If an AioCb has any in-kernel state, AioCb.drop will print a warning and wait for it to complete. --- test/sys/test_aio.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/sys/test_aio.rs') diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index a9e29b44..9b736c4b 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -393,3 +393,30 @@ fn test_lio_listio_read_immutable() { LioOpcode::LIO_READ); let _ = lio_listio(LioMode::LIO_NOWAIT, &[&mut rcb], SigevNotify::SigevNone); } + +// Test dropping an AioCb that hasn't yet finished. Behind the scenes, the +// library should wait for the AioCb's completion. +#[test] +fn test_drop() { + const INITIAL: &'static [u8] = b"abcdef123456"; + const WBUF: &'static [u8] = b"CDEF"; //"CDEF".to_string().into_bytes(); + let mut rbuf = Vec::new(); + const EXPECT: &'static [u8] = b"abCDEF123456"; + + let mut f = tempfile().unwrap(); + f.write(INITIAL).unwrap(); + { + let mut aiocb = AioCb::from_slice( f.as_raw_fd(), + 2, //offset + &WBUF, + 0, //priority + SigevNotify::SigevNone, + LioOpcode::LIO_NOP); + aiocb.write().unwrap(); + } + + f.seek(SeekFrom::Start(0)).unwrap(); + let len = f.read_to_end(&mut rbuf).unwrap(); + assert!(len == EXPECT.len()); + assert!(rbuf == EXPECT); +} -- cgit v1.2.3