Skip to content

Commit

Permalink
migrate to tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Feb 2, 2023
1 parent 2580d68 commit d6ec2fe
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ docopt = "1.1"
histogram = "0.6"
quickcheck = "1.0.3"
regex = "1.5"
tempdir = "0.3"
tempfile = "3.3.0"
chrono = "0.4.23"
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ mod test {
use log::trace;
use quickcheck::TestResult;
use std::io::Write;
use tempfile::Builder;

use crate::segment::Segment;
use crate::test_utils::EntryGenerator;
Expand All @@ -614,7 +615,7 @@ mod test {
fn check_wal() {
init_logger();
fn wal(entry_count: u8) -> TestResult {
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::with_options(
dir.path(),
&WalOptions {
Expand Down Expand Up @@ -649,7 +650,7 @@ mod test {
fn check_last_index() {
init_logger();
fn check(entry_count: u8) -> TestResult {
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::with_options(
dir.path(),
&WalOptions {
Expand Down Expand Up @@ -683,7 +684,7 @@ mod test {
fn check_clear() {
init_logger();
fn check(entry_count: u8) -> TestResult {
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::with_options(
dir.path(),
&WalOptions {
Expand Down Expand Up @@ -716,7 +717,7 @@ mod test {
.into_iter()
.take(entry_count as usize)
.collect::<Vec<_>>();
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
{
let mut wal = Wal::with_options(
dir.path(),
Expand Down Expand Up @@ -772,7 +773,7 @@ mod test {
if truncate > entry_count {
return TestResult::discard();
}
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::with_options(
dir.path(),
&WalOptions {
Expand Down Expand Up @@ -820,7 +821,7 @@ mod test {
if until > entry_count {
return TestResult::discard();
}
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::with_options(
dir.path(),
&WalOptions {
Expand Down Expand Up @@ -849,7 +850,7 @@ mod test {
#[test]
fn test_append() {
init_logger();
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let mut wal = Wal::open(dir.path()).unwrap();

let entry: &[u8] = &[42u8; 4096];
Expand All @@ -861,7 +862,7 @@ mod test {
#[test]
fn test_truncate() {
init_logger();
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
// 2 entries should fit in each segment
let mut wal = Wal::with_options(
dir.path(),
Expand Down Expand Up @@ -894,7 +895,7 @@ mod test {
#[test]
fn test_truncate_flush() {
init_logger();
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
// 2 entries should fit in each segment
let mut wal = Wal::with_options(
dir.path(),
Expand Down Expand Up @@ -1003,7 +1004,7 @@ mod test {
#[test]
fn test_exclusive_lock() {
init_logger();
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let wal = Wal::open(dir.path()).unwrap();
assert_eq!(
fs2::lock_contended_error().kind(),
Expand All @@ -1016,7 +1017,7 @@ mod test {
#[test]
fn test_segment_creator() {
init_logger();
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();

let segments = vec![OpenSegment {
id: 3,
Expand All @@ -1033,7 +1034,7 @@ mod test {
fn test_record_id_preserving() {
init_logger();
let entry_count = 55;
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let options = WalOptions {
segment_capacity: 512,
segment_queue_len: 3,
Expand Down Expand Up @@ -1070,7 +1071,7 @@ mod test {
fn test_offset_after_open() {
init_logger();
let entry_count = 55;
let dir = tempdir::TempDir::new("wal").unwrap();
let dir = Builder::new().prefix("wal").tempdir().unwrap();
let options = WalOptions {
segment_capacity: 512,
segment_queue_len: 3,
Expand Down
5 changes: 2 additions & 3 deletions src/mmap_view_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,11 @@ unsafe impl Send for MmapViewSync {}

#[cfg(test)]
mod test {
extern crate tempdir;

use std::fs;
use std::io::{Read, Write};
use std::sync::Arc;
use std::thread;
use tempfile::Builder;

use super::*;

Expand Down Expand Up @@ -223,7 +222,7 @@ mod test {
let len = 131072; // 256KiB
let split = 66560; // 65KiB + 10B

let tempdir = tempdir::TempDir::new("mmap").unwrap();
let tempdir = Builder::new().prefix("mmap").tempdir().unwrap();
let path = tempdir.path().join("mmap");

let mut file = fs::OpenOptions::new()
Expand Down
11 changes: 6 additions & 5 deletions src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ pub fn segment_overhead() -> usize {
#[cfg(test)]
mod test {
use std::io::ErrorKind;
use tempfile::Builder;

use super::{padding, Segment};

Expand Down Expand Up @@ -632,7 +633,7 @@ mod test {
}

fn create_segment(len: usize) -> Segment {
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();
let mut path = dir.path().to_path_buf();
path.push("sync-segment");
Segment::create(path, len).unwrap()
Expand Down Expand Up @@ -678,7 +679,7 @@ mod test {
#[test]
fn test_create_dir_path() {
init_logger();
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();
assert!(Segment::open(dir.path()).is_err());
}

Expand Down Expand Up @@ -712,7 +713,7 @@ mod test {
#[test]
fn test_open() {
init_logger();
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();
let mut path = dir.path().to_path_buf();
path.push("test-open");

Expand Down Expand Up @@ -760,7 +761,7 @@ mod test {
#[test]
fn test_overwrite() {
init_logger();
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();
let mut path = dir.path().to_path_buf();
path.push("test-overwrite");

Expand All @@ -784,7 +785,7 @@ mod test {
#[test]
fn test_open_nonexistent() {
init_logger();
let dir = tempdir::TempDir::new("segment").unwrap();
let dir = Builder::new().prefix("segment").tempdir().unwrap();
let mut path = dir.path().to_path_buf();
path.push("test-open-nonexistent");
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion tests/process_crash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::env;
use std::process;

use rand::RngCore;
use tempfile::Builder;
use wal::test_utils::EntryGenerator;

const SEGMENT_CAPACITY: usize = 32 * 1024 * 1024;
Expand All @@ -34,7 +35,7 @@ fn process_crash() {
}

fn test() {
let tempdir = tempdir::TempDir::new("process-crash").unwrap();
let tempdir = Builder::new().prefix("segment").tempdir().unwrap();
let seed: usize = rand::thread_rng().next_u32() as usize;
let path = tempdir.path().join("segment");

Expand Down

0 comments on commit d6ec2fe

Please sign in to comment.