diff options
author | Alan Somers <asomers@gmail.com> | 2017-02-05 18:21:56 -0700 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2017-02-05 20:53:59 -0700 |
commit | 3aef80e9733ed63040d89ce416d9b37d48389311 (patch) | |
tree | f8a9b7df78b889a4fd8b48c58aeac272a206ac44 /test/sys/test_aio.rs | |
parent | 14608a9280a189ba4772a940bfd0486e7d1ac0af (diff) | |
download | nix-3aef80e9733ed63040d89ce416d9b37d48389311.zip |
Implement Drop for AioCb
If an AioCb has any in-kernel state, AioCb.drop will print a warning and
wait for it to complete.
Diffstat (limited to 'test/sys/test_aio.rs')
-rw-r--r-- | test/sys/test_aio.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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); +} |