Skip to content

Commit

Permalink
test: fix some test failures due to tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryConrad committed May 25, 2023
1 parent 58837ee commit 3891da5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,11 @@ impl std::fmt::Debug for Database {

#[cfg(test)]
mod test {
use tempfile::NamedTempFile;

use crate::{Database, Durability, Error, ReadableTable, TableDefinition};

#[test]
fn small_pages() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();

let db = Database::builder()
.set_page_size(512)
Expand All @@ -733,7 +731,7 @@ mod test {

#[test]
fn small_pages2() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();

let db = Database::builder()
.set_page_size(512)
Expand Down Expand Up @@ -827,7 +825,7 @@ mod test {

#[test]
fn small_pages3() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();

let db = Database::builder()
.set_page_size(1024)
Expand Down Expand Up @@ -860,7 +858,7 @@ mod test {

#[test]
fn small_pages4() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();

let db = Database::builder()
.set_cache_size(1024 * 1024)
Expand Down Expand Up @@ -897,7 +895,7 @@ mod test {

#[test]
fn crash_regression1() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();

let db = Database::builder()
.set_cache_size(1024 * 1024)
Expand All @@ -920,7 +918,7 @@ mod test {

#[test]
fn dynamic_shrink() {
let tmpfile: NamedTempFile = NamedTempFile::new().unwrap();
let tmpfile = crate::create_tempfile();
let table_definition: TableDefinition<u64, &[u8]> = TableDefinition::new("x");
let big_value = vec![0u8; 1024];

Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ mod transactions;
mod tree_store;
mod tuple_types;
mod types;

#[cfg(test)]
fn create_tempfile() -> tempfile::NamedTempFile {
if cfg!(target_os = "wasi") {
tempfile::NamedTempFile::new_in("").unwrap()
} else {
tempfile::NamedTempFile::new().unwrap()
}
}

0 comments on commit 3891da5

Please sign in to comment.