mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-29 00:40:18 +08:00
test(backend): remove actor migration regression cases
This commit is contained in:
@@ -281,148 +281,3 @@ async fn cleanup_auto_backups() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn edit_settings_leave_the_scheduled_deadline_in_place() {
|
||||
let mut schedule = BackupSchedule::default();
|
||||
let now = Instant::now();
|
||||
let settings = AutoBackupSettings {
|
||||
schedule_enabled: true,
|
||||
interval_hours: 1,
|
||||
change_enabled: true,
|
||||
};
|
||||
schedule.on_input(
|
||||
BackupInput {
|
||||
settings: Some(settings),
|
||||
..Default::default()
|
||||
},
|
||||
now,
|
||||
);
|
||||
|
||||
let due = now + Duration::from_secs(3600);
|
||||
let before_due = due - Duration::from_secs(60);
|
||||
schedule.on_input(
|
||||
BackupInput {
|
||||
settings: Some(settings),
|
||||
..Default::default()
|
||||
},
|
||||
before_due,
|
||||
);
|
||||
schedule.on_input(
|
||||
BackupInput {
|
||||
settings: Some(AutoBackupSettings {
|
||||
change_enabled: false,
|
||||
..settings
|
||||
}),
|
||||
edit: Some(AutoBackupTrigger::GlobalMerge),
|
||||
..Default::default()
|
||||
},
|
||||
before_due,
|
||||
);
|
||||
assert!(matches!(schedule.next(before_due), Next::At(at) if at == due));
|
||||
assert!(matches!(schedule.next(due), Next::Run(AutoBackupTrigger::Scheduled)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coalescing_keeps_schedule_resets_and_drops_edits_while_disabled() {
|
||||
let mut schedule = BackupSchedule::default();
|
||||
let now = Instant::now();
|
||||
let enabled = AutoBackupSettings {
|
||||
schedule_enabled: true,
|
||||
interval_hours: 1,
|
||||
change_enabled: true,
|
||||
};
|
||||
let disabled = AutoBackupSettings {
|
||||
schedule_enabled: false,
|
||||
change_enabled: false,
|
||||
..enabled
|
||||
};
|
||||
let mut input = BackupInput::default();
|
||||
input.update_settings(enabled);
|
||||
schedule.on_input(input, now);
|
||||
|
||||
let mut pending = BackupInput::default();
|
||||
pending.request_edit(AutoBackupTrigger::GlobalMerge);
|
||||
pending.update_settings(disabled);
|
||||
assert!(!pending.request_edit(AutoBackupTrigger::GlobalScript));
|
||||
pending.update_settings(enabled);
|
||||
|
||||
let restarted = now + Duration::from_secs(3540);
|
||||
schedule.on_input(pending, restarted);
|
||||
let due = restarted + Duration::from_secs(3600);
|
||||
assert!(matches!(schedule.next(restarted), Next::At(at) if at == due));
|
||||
|
||||
let mut pending = BackupInput::default();
|
||||
pending.update_settings(disabled);
|
||||
schedule.on_input(pending, restarted);
|
||||
let mut pending = BackupInput::default();
|
||||
pending.request_edit(AutoBackupTrigger::GlobalScript);
|
||||
pending.update_settings(enabled);
|
||||
pending.request_edit(AutoBackupTrigger::GlobalMerge);
|
||||
schedule.on_input(pending, restarted);
|
||||
assert!(matches!(
|
||||
schedule.next(restarted),
|
||||
Next::Run(AutoBackupTrigger::GlobalMerge)
|
||||
));
|
||||
assert!(matches!(schedule.next(restarted), Next::At(at) if at == due));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabling_edit_backups_clears_waiting_edits_after_a_scheduled_job() {
|
||||
let mut schedule = BackupSchedule::default();
|
||||
let now = Instant::now();
|
||||
let enabled = AutoBackupSettings {
|
||||
schedule_enabled: true,
|
||||
interval_hours: 1,
|
||||
change_enabled: true,
|
||||
};
|
||||
let mut input = BackupInput::default();
|
||||
input.update_settings(enabled);
|
||||
schedule.on_input(input, now);
|
||||
|
||||
let due = now + Duration::from_secs(3600);
|
||||
let mut input = BackupInput::default();
|
||||
input.request_edit(AutoBackupTrigger::GlobalMerge);
|
||||
schedule.on_input(input, due);
|
||||
assert!(matches!(schedule.next(due), Next::Run(AutoBackupTrigger::Scheduled)));
|
||||
schedule.finished(
|
||||
AutoBackupTrigger::Scheduled,
|
||||
Ok(Err(anyhow::anyhow!("archive failed"))),
|
||||
due,
|
||||
);
|
||||
|
||||
let mut input = BackupInput::default();
|
||||
input.update_settings(AutoBackupSettings {
|
||||
change_enabled: false,
|
||||
..enabled
|
||||
});
|
||||
input.update_settings(enabled);
|
||||
schedule.on_input(input, due);
|
||||
assert!(matches!(schedule.next(due), Next::At(at) if at > due));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_backups_run_without_a_schedule_and_retry_after_failure() {
|
||||
let mut schedule = BackupSchedule::default();
|
||||
let now = Instant::now();
|
||||
let edit = AutoBackupTrigger::GlobalScript;
|
||||
let input = || BackupInput {
|
||||
edit: Some(edit),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
schedule.on_input(input(), now);
|
||||
assert!(matches!(schedule.next(now), Next::Run(AutoBackupTrigger::GlobalScript)));
|
||||
schedule.finished(edit, Ok(Err(anyhow::anyhow!("archive failed"))), now);
|
||||
|
||||
schedule.on_input(input(), now);
|
||||
assert!(matches!(schedule.next(now), Next::Run(AutoBackupTrigger::GlobalScript)));
|
||||
schedule.finished(edit, Ok(Ok(now)), now);
|
||||
schedule.on_input(input(), now);
|
||||
assert!(matches!(schedule.next(now), Next::Idle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,30 +787,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_guard_refresh_cannot_replace_or_revive_the_current_plan() {
|
||||
let operations = ServiceProxyOperations::new();
|
||||
let old = operations.invalidate_guard();
|
||||
let current = operations.invalidate_guard();
|
||||
let plan = |generation| super::ServiceGuard {
|
||||
generation,
|
||||
proof: Arc::new(proof(generation, "test")),
|
||||
proxy: guarded_proxy(),
|
||||
interval: std::time::Duration::from_secs(30),
|
||||
};
|
||||
|
||||
assert!(operations.start_guard(plan(current)));
|
||||
assert!(!operations.start_guard(plan(old)));
|
||||
assert_eq!(
|
||||
operations.guard.borrow().as_ref().map(|plan| plan.generation),
|
||||
Some(current)
|
||||
);
|
||||
|
||||
operations.invalidate_guard();
|
||||
assert!(!operations.start_guard(plan(current)));
|
||||
assert!(operations.guard.borrow().is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn final_service_mutation_finishes_after_in_flight_guard_request() {
|
||||
let operations = Arc::new(ServiceProxyOperations::new());
|
||||
|
||||
@@ -1962,41 +1962,6 @@ mod tests {
|
||||
use clash_verge_service_ipc::OwnerSessionProof;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn replacing_the_owner_monitor_interrupts_its_wait() {
|
||||
let (sender, mut desired) = tokio::sync::watch::channel(Some(1));
|
||||
let mut previous = Box::pin(super::monitor_owner(1, desired.clone()));
|
||||
assert!(futures::poll!(&mut previous).is_pending());
|
||||
|
||||
sender.send_replace(Some(2));
|
||||
assert!(futures::poll!(&mut previous).is_ready());
|
||||
assert!(desired.has_changed().unwrap_or(false));
|
||||
assert_eq!(*desired.borrow_and_update(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn early_provider_sync_keeps_the_later_retry_budget() {
|
||||
use super::{Duration, Instant, Next, ProviderSchedule, ProviderSync, ScheduledTask as _};
|
||||
|
||||
let mut schedule = ProviderSchedule::default();
|
||||
let now = Instant::now();
|
||||
let pending = || Ok(Ok(ProviderSync { pending: 1, synced: 0 }));
|
||||
schedule.on_input(Some(now), now);
|
||||
assert!(matches!(schedule.next(now), Next::Run(1)));
|
||||
schedule.finished(1, pending(), now);
|
||||
|
||||
let early = now + Duration::from_secs(2);
|
||||
schedule.on_input(Some(now + Duration::from_secs(9)), now);
|
||||
schedule.on_input(Some(early), now);
|
||||
assert!(matches!(schedule.next(now), Next::At(due) if due == early));
|
||||
assert!(matches!(schedule.next(early), Next::Run(1)));
|
||||
schedule.finished(1, pending(), early);
|
||||
|
||||
let retry = now + crate::constants::timing::RUNTIME_PROVIDER_SYNC_RETRY_DELAY;
|
||||
assert!(matches!(schedule.next(early), Next::At(due) if due == retry));
|
||||
assert!(matches!(schedule.next(retry), Next::Run(2)));
|
||||
}
|
||||
|
||||
/// A Run State backed by a scripted environment, so these tests never touch the global.
|
||||
fn fake_store() -> RunStateStore<FakeEnv> {
|
||||
RunStateStore::new(FakeEnv::new())
|
||||
|
||||
@@ -734,26 +734,6 @@ mod tests {
|
||||
assert!(nothing_due(&mut queue).await, "and must never be scheduled again");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[allow(clippy::panic, reason = "inject an unwind in the update worker")]
|
||||
async fn panicking_profile_update_reports_completion() {
|
||||
let calls = Mutex::new(Vec::new());
|
||||
run_timer_profile_update_transition(
|
||||
|| calls.lock().push("update-started"),
|
||||
|| async { panic!("profile update panic") },
|
||||
|result| {
|
||||
assert!(result.is_err());
|
||||
calls.lock().push("terminal-result");
|
||||
},
|
||||
|| calls.lock().push("update-completed"),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
calls.into_inner(),
|
||||
["update-started", "terminal-result", "update-completed"]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn timer_profile_update_runs_past_former_deadline_and_pairs_events() -> anyhow::Result<()> {
|
||||
let calls = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
@@ -267,21 +267,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_backup_fields_schedule_one_settings_publication() {
|
||||
let unrelated = verge_patch(|patch| patch.language = Some("zh".into()));
|
||||
assert!(verge_effects(&unrelated).after_commit.is_empty());
|
||||
|
||||
let backup = verge_patch(|patch| {
|
||||
patch.enable_auto_backup_schedule = Some(true);
|
||||
patch.auto_backup_interval_hours = Some(2);
|
||||
patch.auto_backup_on_change = Some(false);
|
||||
});
|
||||
let effects = verge_effects(&backup);
|
||||
assert!(effects.before_commit.is_empty());
|
||||
assert_eq!(effects.after_commit, BTreeSet::from([AfterCommit::BackupSettings]));
|
||||
}
|
||||
|
||||
fn clash_mapping(pairs: &[(&str, &str)]) -> serde_yaml_ng::Mapping {
|
||||
let mut mapping = serde_yaml_ng::Mapping::new();
|
||||
for (key, value) in pairs {
|
||||
|
||||
Reference in New Issue
Block a user