make transaction test actually free memory before writing
This commit is contained in:
parent
53441e014e
commit
d501962881
28
src/lib.rs
28
src/lib.rs
@ -826,9 +826,9 @@ mod tests {
|
||||
&[size_of::<DataHeader>() as u32, size_of::<DataList>() as u32],
|
||||
);
|
||||
|
||||
let mut snapshots = Vec::new();
|
||||
let mut snapshots = VecDeque::new();
|
||||
|
||||
for i in 0..10 {
|
||||
for i in 0..20 {
|
||||
db.transaction(|transaction| {
|
||||
let root = transaction.root();
|
||||
|
||||
@ -845,7 +845,7 @@ mod tests {
|
||||
root
|
||||
};
|
||||
|
||||
let &data = transaction.read::<DataHeader>(root);
|
||||
let &data = transaction.read(root);
|
||||
|
||||
assert_eq!(data.generation.get(), i);
|
||||
|
||||
@ -853,14 +853,14 @@ mod tests {
|
||||
let mut next = data.list;
|
||||
let mut n = 0;
|
||||
while !next.is_null() {
|
||||
next = transaction.read::<DataList>(next).next;
|
||||
next = transaction.read(next).next;
|
||||
n += 1;
|
||||
}
|
||||
n
|
||||
};
|
||||
|
||||
let next = if n >= 5 {
|
||||
transaction.read::<DataList>(data.list).next
|
||||
transaction.read(data.list).next
|
||||
} else {
|
||||
data.list
|
||||
};
|
||||
@ -870,34 +870,38 @@ mod tests {
|
||||
element.next = next;
|
||||
element.data = i.into();
|
||||
|
||||
let (root, data) = transaction.modify::<DataHeader>(root);
|
||||
let (root, data) = transaction.modify(root);
|
||||
data.list = elem_ptr;
|
||||
data.generation = (i + 1).into();
|
||||
|
||||
root
|
||||
});
|
||||
|
||||
snapshots.push(db.create_reader().state.get());
|
||||
snapshots.push_back(db.create_reader().state.get());
|
||||
if snapshots.len() > 10 {
|
||||
drop(snapshots.pop_front());
|
||||
db.free_old_epochs()
|
||||
}
|
||||
}
|
||||
|
||||
for (i, snapshot) in snapshots.iter().enumerate() {
|
||||
let root = snapshot.read::<DataHeader>(snapshot.root);
|
||||
let root = snapshot.read(snapshot.root);
|
||||
|
||||
assert_eq!(root.generation.get(), i as u64 + 1);
|
||||
assert_eq!(root.generation.get(), 1 + 10 + i as u64);
|
||||
|
||||
let mut items = Vec::new();
|
||||
|
||||
let mut ptr = root.list;
|
||||
|
||||
while !ptr.is_null() {
|
||||
let element = snapshot.read::<DataList>(ptr);
|
||||
let element = snapshot.read(ptr);
|
||||
|
||||
items.push(element.data.get());
|
||||
ptr = element.next;
|
||||
}
|
||||
|
||||
assert_eq!(items.len(), (i + 1).min(5));
|
||||
assert_eq!(items[0], i as u64);
|
||||
assert_eq!(items.len(), 5);
|
||||
assert_eq!(items[0], 10 + i as u64);
|
||||
|
||||
for (expected, &is) in items.iter().skip(1).rev().enumerate() {
|
||||
assert_eq!(expected as u64, is);
|
||||
|
Loading…
Reference in New Issue
Block a user