Skip to content

Commit

Permalink
fix: make Store::spawn async to ensure a runtime is set
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead committed Sep 13, 2024
1 parent 677745a commit aafa84c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod tests {
#[tokio::test]
async fn test_serve_stateless() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let pool = ThreadPool::new(4);
let engine = nu::Engine::new(store.clone()).unwrap();

Expand Down Expand Up @@ -362,7 +362,7 @@ mod tests {
#[tokio::test]
async fn test_serve_stateful() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let pool = ThreadPool::new(4);
let engine = nu::Engine::new(store.clone()).unwrap();

Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {
#[tokio::test]
async fn test_handler_update() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let pool = ThreadPool::new(4);
let engine = nu::Engine::new(store.clone()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
xs::trace::init();

let args = Args::parse();
let store = Store::spawn(args.path);
let store = Store::spawn(args.path).await;
let pool = ThreadPool::new(10);
let engine = nu::Engine::new(store.clone())?;

Expand Down
12 changes: 6 additions & 6 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum Command {
}

impl Store {
pub fn spawn(path: PathBuf) -> Store {
pub async fn spawn(path: PathBuf) -> Store {
let config = Config::new(path.join("fjall"));
let keyspace = config.open().unwrap();

Expand Down Expand Up @@ -464,7 +464,7 @@ mod tests_store {
#[tokio::test]
async fn test_get() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let meta = serde_json::json!({"key": "value"});
let frame = store.append("stream", None, Some(meta)).await;
let got = store.get(&frame.id);
Expand All @@ -474,7 +474,7 @@ mod tests_store {
#[tokio::test]
async fn test_follow() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;

// Append two initial clips
let f1 = store.append("stream", None, None).await;
Expand Down Expand Up @@ -523,7 +523,7 @@ mod tests_store {
#[tokio::test]
async fn test_stream_basics() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;

let f1 = store.append("/stream", None, None).await;
let f2 = store.append("/stream", None, None).await;
Expand Down Expand Up @@ -552,7 +552,7 @@ mod tests_store {
#[tokio::test]
async fn test_read_limit_nofollow() {
let temp_dir = tempfile::tempdir().unwrap();
let mut store = Store::spawn(temp_dir.path().to_path_buf());
let mut store = Store::spawn(temp_dir.path().to_path_buf()).await;

// Add 3 items
let frame1 = store.append("test", None, None).await;
Expand All @@ -574,7 +574,7 @@ mod tests_store {
#[tokio::test]
async fn test_read_limit_follow() {
let temp_dir = tempfile::tempdir().unwrap();
let mut store = Store::spawn(temp_dir.path().to_path_buf());
let mut store = Store::spawn(temp_dir.path().to_path_buf()).await;

// Add 1 item
let frame1 = store.append("test", None, None).await;
Expand Down
6 changes: 3 additions & 3 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mod tests {
#[tokio::test]
async fn test_serve_basic() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let engine = nu::Engine::new(store.clone()).unwrap();

{
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
#[tokio::test]
async fn test_serve_duplex() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let engine = nu::Engine::new(store.clone()).unwrap();

{
Expand Down Expand Up @@ -352,7 +352,7 @@ mod tests {
#[tokio::test]
async fn test_serve_compact() {
let temp_dir = TempDir::new().unwrap();
let mut store = Store::spawn(temp_dir.into_path());
let mut store = Store::spawn(temp_dir.into_path()).await;
let engine = nu::Engine::new(store.clone()).unwrap();

let _ = store
Expand Down

0 comments on commit aafa84c

Please sign in to comment.