Skip to content

Commit

Permalink
Fix minor test bug. (#49)
Browse files Browse the repository at this point in the history
AsyncInMemoryStorage has a bug in compaction where the first entry is not able to be compacted.

This would not normally be caught, but there's a bug in repo.rs where compaction doesn't happen, and I'm trying to track that down.
  • Loading branch information
issackelly authored Sep 13, 2023
1 parent 7b6a698 commit f95edd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/fs_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl FsStore {
pub fn get(&self, id: &DocumentId) -> Result<Option<Vec<u8>>, Error> {
let chunks = Chunks::load(&self.root, id)?;
let Some(chunks) = chunks else {
return Ok(None)
return Ok(None);
};
let mut result = Vec::new();
result.extend(chunks.snapshots.into_values().flatten());
Expand Down Expand Up @@ -163,7 +163,7 @@ impl FsStore {
// Load all the data we have into a doc
let Some(chunks) = Chunks::load(&self.root, id)? else {
tracing::warn!(doc_id=%id, "attempted to compact non-existent document");
return Ok(())
return Ok(());
};
let mut doc = chunks
.to_doc()
Expand Down Expand Up @@ -382,7 +382,8 @@ impl Chunks {
tracing::warn!(bad_file=%path.display(), "unexpected non-file in level2 path");
continue;
}
let Some(chunk_name) = entry.file_name().to_str().and_then(SavedChunkName::parse) else {
let Some(chunk_name) = entry.file_name().to_str().and_then(SavedChunkName::parse)
else {
tracing::warn!(bad_file=%path.display(), "unexpected non-chunk file in level2 path");
continue;
};
Expand Down
4 changes: 2 additions & 2 deletions test_utils/src/storage_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl AsyncInMemoryStorage {
StorageRequest::Compact(doc_id, data, sender) => {
let _entry = documents
.entry(doc_id)
.and_modify(|entry| *entry = data)
.or_insert_with(Default::default);
.and_modify(|entry| *entry = data.clone())
.or_insert_with(|| data);
let (tx, rx) = oneshot();
results.push_back(tx);
tokio::spawn(async move {
Expand Down

0 comments on commit f95edd1

Please sign in to comment.