Skip to content

Commit

Permalink
Use reduced database durability during tests (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 5, 2022
1 parent dd2729d commit 975613c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ impl Index {

let tx = database.begin_write()?;

#[cfg(test)]
let tx = {
let mut tx = tx;
tx.set_durability(redb::Durability::None);
tx
};

tx.open_table(HEIGHT_TO_HASH)?;
tx.open_table(ORDINAL_TO_SATPOINT)?;
tx.open_table(OUTPOINT_TO_ORDINAL_RANGES)?;
Expand All @@ -142,7 +149,7 @@ impl Index {
}

pub(crate) fn print_info(&self) -> Result {
let wtx = self.database.begin_write()?;
let wtx = self.begin_write()?;

let blocks_indexed = wtx
.open_table(HEIGHT_TO_HASH)?
Expand Down Expand Up @@ -194,7 +201,7 @@ impl Index {
}

pub(crate) fn index(&self) -> Result {
let mut wtx = self.database.begin_write()?;
let mut wtx = self.begin_write()?;

let height = wtx
.open_table(HEIGHT_TO_HASH)?
Expand All @@ -215,7 +222,7 @@ impl Index {

if i > 0 && i % 1000 == 0 {
wtx.commit()?;
wtx = self.database.begin_write()?;
wtx = self.begin_write()?;
}

if done || INTERRUPTS.load(atomic::Ordering::Relaxed) > 0 {
Expand Down Expand Up @@ -368,6 +375,16 @@ impl Index {
Ok(rtx::Rtx(self.database.begin_read()?))
}

fn begin_write(&self) -> Result<redb::WriteTransaction> {
if cfg!(test) {
let mut tx = self.database.begin_write()?;
tx.set_durability(redb::Durability::None);
Ok(tx)
} else {
Ok(self.database.begin_write()?)
}
}

pub(crate) fn height(&self) -> Result<Height> {
Ok(Height(self.begin_read()?.height()?))
}
Expand Down

0 comments on commit 975613c

Please sign in to comment.