Skip to content

Commit

Permalink
Merge pull request #620 from wcampbell0x2a/add-backon-retry-to-tests
Browse files Browse the repository at this point in the history
Add backon retry to tests
  • Loading branch information
wcampbell0x2a authored Oct 22, 2024
2 parents 04af7f2 + 2a2719c commit 141da61
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 10 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backhand-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libdeflater = "1.21.0"
env_logger = "0.11.5"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt"] }
nix = { version = "0.28.0", default-features = false, features = ["fs"] }
backon = "1.2.0"

[lib]
bench = false
Expand Down
4 changes: 2 additions & 2 deletions backhand-test/tests/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn test_add() {
}];
const TEST_PATH: &str = "test-assets/test_01";

test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let image_path = format!("{TEST_PATH}/{FILE_NAME}");

// Add /test dir
Expand Down Expand Up @@ -141,7 +141,7 @@ fn test_dont_emit_compression_options() {
}];
const TEST_PATH: &str = "test-assets/test_add_compression_options";

test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let image_path = format!("{TEST_PATH}/{FILE_NAME}");
let tmp_dir = tempdir().unwrap();

Expand Down
18 changes: 18 additions & 0 deletions backhand-test/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
use std::error::Error;
use std::process::Command;
use std::time::Duration;

use assert_cmd::prelude::*;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;
use tempfile::tempdir;
use tempfile::tempdir_in;
use test_assets::TestAssetDef;

fn download(assets_defs: &[TestAssetDef], test_path: &str) -> Result<(), Box<dyn Error>> {
if test_assets::download_test_files(assets_defs, test_path, true).is_err() {
return Err("falied to download".into());
}
Ok(())
}

pub fn download_backoff(assets_defs: &[TestAssetDef], test_path: &str) {
let strategy = ExponentialBuilder::default().with_max_delay(Duration::from_secs(60));

let _result = (|| download(assets_defs, test_path)).retry(strategy).call().unwrap();
}

/// test the new squashfs vs the original squashfs with squashfs-tool/unsquashfs
/// by extract
Expand Down
2 changes: 1 addition & 1 deletion backhand-test/tests/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn test_add_00() {
let og_path = format!("{TEST_PATH}/out.squashfs");
let new_path = format!("{TEST_PATH}/bytes.squashfs");

test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let file = BufReader::new(File::open(&og_path).unwrap());
let og_filesystem = FilesystemReader::from_reader(file).unwrap();
let mut new_filesystem = FilesystemWriter::from_fs_reader(&og_filesystem).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion backhand-test/tests/non_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn full_test(
kind: &Kind,
pad: Option<u32>,
) {
test_assets::download_test_files(assets_defs, test_path, true).unwrap();
common::download_backoff(&assets_defs, test_path);
let og_path = format!("{test_path}/{filepath}");
let new_path = format!("{test_path}/bytes.squashfs");
{
Expand Down
2 changes: 1 addition & 1 deletion backhand-test/tests/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_raw_00() {
}];
const TEST_PATH: &str = "test-assets/test_raw_00";
let new_path = format!("{TEST_PATH}/bytes.squashfs");
test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);

let header = NodeHeader { permissions: 0o755, uid: 1000, gid: 1000, mtime: 0 };

Expand Down
2 changes: 1 addition & 1 deletion backhand-test/tests/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn test_replace() {
}];
const TEST_PATH: &str = "test-assets/test_05";

test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let image_path = format!("{TEST_PATH}/{FILE_NAME}");

// extract single file
Expand Down
4 changes: 2 additions & 2 deletions backhand-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum Verify {
}

fn only_read(assets_defs: &[TestAssetDef], filepath: &str, test_path: &str, offset: u64) {
test_assets::download_test_files(assets_defs, test_path, true).unwrap();
common::download_backoff(assets_defs, test_path);

let og_path = format!("{test_path}/{filepath}");
let file = BufReader::new(File::open(&og_path).unwrap());
Expand Down Expand Up @@ -63,7 +63,7 @@ fn full_test_inner(
assert_success: bool,
run_squashfs_tools_unsquashfs: bool,
) {
test_assets::download_test_files(assets_defs, test_path, true).unwrap();
common::download_backoff(assets_defs, test_path);

let og_path = format!("{test_path}/{filepath}");
let new_path = format!("{test_path}/bytes.squashfs");
Expand Down
4 changes: 2 additions & 2 deletions backhand-test/tests/unsquashfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_unsquashfs_cli() {
}];
const TEST_PATH: &str = "test-assets/test_re815_xev160";

test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let image_path = format!("{TEST_PATH}/{FILE_NAME}");

// single file
Expand Down Expand Up @@ -119,7 +119,7 @@ fn test_unsquashfs_cli_auto_offset() {
),
}];
const TEST_PATH: &str = "test-assets/test_openwrt_tplink_archera7v5";
test_assets::download_test_files(&asset_defs, TEST_PATH, true).unwrap();
common::download_backoff(&asset_defs, TEST_PATH);
let image_path = format!("{TEST_PATH}/{FILE_NAME}");

let tmp_dir = tempdir().unwrap();
Expand Down

0 comments on commit 141da61

Please sign in to comment.