Skip to content

Commit

Permalink
feat: State compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Feb 18, 2025
1 parent 9ca7373 commit 5459ed1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
25 changes: 21 additions & 4 deletions pueue/tests/daemon/integration/restore.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
use pueue_lib::{network::message::TaskSelection, state::GroupStatus};
use rstest::rstest;

use crate::{helper::*, internal_prelude::*};

/// The daemon should start in the same state as before shutdown, if no tasks are queued.
/// This function tests for the running state.
#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test]
async fn test_start_running() -> Result<()> {
let (settings, _tempdir) = daemon_base_setup()?;
async fn test_start_running(#[case] compress: bool) -> Result<()> {
let (mut settings, tempdir) = daemon_base_setup()?;
settings.daemon.compress_status_file = compress;
settings
.save(&Some(tempdir.path().join("pueue.yml")))
.context("Couldn't write pueue config to temporary directory")?;

let mut child = standalone_daemon(&settings.shared).await?;
let shared = &settings.shared;

Expand All @@ -31,9 +40,17 @@ async fn test_start_running() -> Result<()> {

/// The daemon should start in the same state as before shutdown, if no tasks are queued.
/// This function tests for the paused state.
#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test]
async fn test_start_paused() -> Result<()> {
let (settings, _tempdir) = daemon_base_setup()?;
async fn test_start_paused(#[case] compress: bool) -> Result<()> {
let (mut settings, tempdir) = daemon_base_setup()?;
settings.daemon.compress_status_file = compress;
settings
.save(&Some(tempdir.path().join("pueue.yml")))
.context("Couldn't write pueue config to temporary directory")?;

let mut child = standalone_daemon(&settings.shared).await?;
let shared = &settings.shared;

Expand Down
10 changes: 6 additions & 4 deletions pueue/tests/daemon/state_backward_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pueue::daemon::internal_state::state::InternalState;
use pueue_lib::settings::Settings;
use tempfile::TempDir;

use crate::internal_prelude::*;
use crate::{helper::enable_logger, internal_prelude::*};

/// 4.0.0 introduced numerous breaking changes.
/// From here on, we now aim to once again have full backward compatibility.
Expand All @@ -17,19 +17,21 @@ use crate::internal_prelude::*;
/// This should be handled as well.
#[test]
fn test_restore_from_old_state() -> Result<()> {
enable_logger();
better_panic::install();
let old_state = include_str!("data/v4.0.0_state.json");

let temp_dir = TempDir::new()?;
let temp_path = temp_dir.path();
let temp_path = temp_dir.path().to_path_buf();

// Open new file and write old state to it.
let temp_state_path = temp_dir.path().join("state.json");
let temp_state_path = temp_path.join("state.json");
let mut file = File::create(temp_state_path)?;
file.write_all(old_state.as_bytes())?;

let mut settings = Settings::default();
settings.shared.pueue_directory = Some(temp_path.to_path_buf());
settings.shared.pueue_directory = Some(temp_path);
debug!("{settings:#?}");

let state =
InternalState::restore_state(&settings).context("Failed to restore state in test")?;
Expand Down
1 change: 1 addition & 0 deletions pueue/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod internal_prelude {
eyre::{bail, eyre, WrapErr},
Result,
};
pub use tracing::debug;
}

#[cfg(unix)]
Expand Down
2 changes: 1 addition & 1 deletion pueue_lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Default for Daemon {
pause_all_on_failure: false,
callback: None,
callback_log_lines: default_callback_log_lines(),
compress_status_file: true,
compress_status_file: false,
shell_command: None,
env_vars: HashMap::new(),
}
Expand Down
2 changes: 1 addition & 1 deletion pueue_lib/tests/settings_backward_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use pueue_lib::settings::Settings;
/// On top of simply having old settings, I also removed a few default fields.
/// This should be handled as well.
#[test]
fn test_restore_from_old_state() -> Result<()> {
fn test_restore_from_old_settings() -> Result<()> {
better_panic::install();
let old_settings_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
Expand Down

0 comments on commit 5459ed1

Please sign in to comment.