mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 17:05:36 +01:00
Add basic test for buffer pool initialization and basic use
This commit is contained in:
@@ -513,3 +513,86 @@ mod arena {
|
||||
unsafe { std::alloc::dealloc(ptr, layout) };
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
const TEST_SIZE: usize = 4096 * 50;
|
||||
|
||||
#[test]
|
||||
fn test_init_pool() {
|
||||
let io: Arc<dyn crate::IO> = Arc::new(crate::MemoryIO::new());
|
||||
let pool = BufferPool::begin_init(&io, TEST_SIZE);
|
||||
pool.finalize_with_page_size(BufferPool::DEFAULT_PAGE_SIZE)
|
||||
.expect("pool to initialize");
|
||||
assert_eq!(pool.get_page().len(), BufferPool::DEFAULT_PAGE_SIZE);
|
||||
assert_eq!(
|
||||
pool.get_wal_frame().len(),
|
||||
BufferPool::DEFAULT_ARENA_SIZE + WAL_FRAME_HEADER_SIZE,
|
||||
"get_wal_frame should return page_size + WAL_FRAME_HEADER_SIZE"
|
||||
);
|
||||
assert!(
|
||||
pool.inner_mut().page_arena.is_some(),
|
||||
"page arena should be initialized"
|
||||
);
|
||||
assert!(
|
||||
pool.inner_mut().wal_frame_arena.is_some(),
|
||||
"wal frame arena should be initialized"
|
||||
);
|
||||
let inner = pool.inner_mut();
|
||||
assert!(
|
||||
inner
|
||||
.page_arena
|
||||
.as_ref()
|
||||
.is_some_and(|a| a.id >= UNREGISTERED_START),
|
||||
"page arena should not have ID in registered range with MemoryIO"
|
||||
);
|
||||
assert!(
|
||||
inner
|
||||
.wal_frame_arena
|
||||
.as_ref()
|
||||
.is_some_and(|a| a.id >= UNREGISTERED_START),
|
||||
"wal frame arena should not have ID in registered range with MemoryIO"
|
||||
);
|
||||
let page = inner.get_page();
|
||||
assert_eq!(
|
||||
inner
|
||||
.page_arena
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allocated_pages
|
||||
.load(Ordering::Relaxed),
|
||||
1
|
||||
);
|
||||
drop(page);
|
||||
let frame = inner.get_frame();
|
||||
assert_eq!(
|
||||
inner
|
||||
.wal_frame_arena
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allocated_pages
|
||||
.load(Ordering::Relaxed),
|
||||
1
|
||||
);
|
||||
drop(frame);
|
||||
assert_eq!(
|
||||
inner
|
||||
.wal_frame_arena
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allocated_pages
|
||||
.load(Ordering::Relaxed),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
inner
|
||||
.page_arena
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.allocated_pages
|
||||
.load(Ordering::Relaxed),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user