mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 15:48:43 +00:00
Add daemonized watcher with control socket
This commit is contained in:
@@ -2,8 +2,6 @@ use std::thread;
|
||||
use std::time::Duration;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use libc;
|
||||
use libmarlin::watcher::WatcherState;
|
||||
use libmarlin::{self as marlin, db};
|
||||
use marlin_cli::cli::watch::WatchCmd;
|
||||
use marlin_cli::cli::{watch, Format};
|
||||
@@ -11,12 +9,10 @@ use marlin_cli::cli::{watch, Format};
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn watch_start_and_stop_quickly() {
|
||||
// TODO: Use a Windows console control handler and enable this test on Windows.
|
||||
let tmp = tempdir().unwrap();
|
||||
let db_path = tmp.path().join("index.db");
|
||||
std::env::set_var("MARLIN_DB_PATH", &db_path);
|
||||
|
||||
// create database
|
||||
let _m = marlin::Marlin::open_default().unwrap();
|
||||
|
||||
let mut conn = db::open(&db_path).unwrap();
|
||||
@@ -27,14 +23,13 @@ fn watch_start_and_stop_quickly() {
|
||||
debounce_ms: 50,
|
||||
};
|
||||
|
||||
// send SIGINT shortly after watcher starts
|
||||
let t = thread::spawn(|| {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
unsafe { libc::raise(libc::SIGINT) };
|
||||
});
|
||||
|
||||
watch::run(&cmd, &mut conn, Format::Text).unwrap();
|
||||
t.join().unwrap();
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
|
||||
assert_eq!(watch::last_watcher_state(), Some(WatcherState::Stopped));
|
||||
watch::run(&WatchCmd::Status, &mut conn, Format::Text).unwrap();
|
||||
watch::run(&WatchCmd::Stop, &mut conn, Format::Text).unwrap();
|
||||
|
||||
let cfg = libmarlin::config::Config::load().unwrap();
|
||||
let control = cfg.db_path.with_extension("watch.json");
|
||||
assert!(!control.exists());
|
||||
}
|
||||
|
Reference in New Issue
Block a user