Skip to content

Commit

Permalink
test when the buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
jauhararifin committed Aug 30, 2024
1 parent b4053da commit 4983ced
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ jobs:
run: cargo build --verbose
- name: Run unit tests
run: cargo test --lib --verbose
# Miri is disabled for now since we use raw syscall for file
# locking and it's not supported by Miri.
# - name: Run unit tests with miri
# env:
# MIRIFLAGS: "-Zmiri-disable-isolation"
# run: cargo miri test --lib --verbose
- name: Run unit tests with miri
env:
MIRIFLAGS: "-Zmiri-disable-isolation"
run: cargo miri test --lib pager::buffer --verbose
- name: Run basic integration tests
run: cargo test --test basic_tests --verbose
61 changes: 61 additions & 0 deletions src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,67 @@ mod tests {
Ok(())
}

#[test]
fn test_flush_buffer_full() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
let entry = WalEntry {
clr: None,
kind: WalKind::Begin {
txid: TxId::new(1).unwrap(),
},
};
assert!(BUFFER_SIZE % entry.size() == 0);
let n = BUFFER_SIZE as u64 / entry.size() as u64;

{
let wal = recover(dir.path(), |_, _| Ok(()))?;

for i in 0u64..3 * n {
wal.append_log(WalEntry {
clr: None,
kind: WalKind::Begin {
txid: TxId::new(i + 1).unwrap(),
},
})?;
}
wal.append_log(WalEntry {
clr: None,
kind: WalKind::LeafDeleteForUndo {
txid: TxId::new(99999999999999999).unwrap(),
pgid: PageId::new(99999999999999999).unwrap(),
index: 10,
},
})?;
wal.trigger_flush()?;
}

let mut i = 0;
recover(dir.path(), |_, entry| {
if i < 3 * n {
assert_eq!(
WalKind::Begin {
txid: TxId::new(i + 1).unwrap()
},
entry.kind
);
} else {
assert_eq!(
WalKind::LeafDeleteForUndo {
txid: TxId::new(99999999999999999).unwrap(),
pgid: PageId::new(99999999999999999).unwrap(),
index: 10,
},
entry.kind
);
}
i += 1;
Ok(())
})?;
assert_eq!(3 * n + 1, i);

Ok(())
}

#[test]
fn test_million_logs() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
Expand Down

0 comments on commit 4983ced

Please sign in to comment.