Stream update badges during content index validation
Publish the fingerprinted inventory before the validating save pass so checks start while validation continues, and keep streamed badges through the final save without duplicate scans. Deduplicate running scans by exact inventory, guard retired workers from overwriting successors, and cancel scoped checks on forget/reset. Rename the long phase to Validating content files.
This commit is contained in:
1 parent
ce0bb34401
commit
65edd0b31b
7 files changed
+555
-53
No files matched your search
@@ -1529,4 +1529,4 @@ fn planned_install(
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../tests/content/dependencies.rs"]
|
||||
mod tests;
|
||||
pub(crate) mod tests;
|
||||
@@ -20,6 +20,7 @@ pub struct ReconcileResult {
|
||||
pub instance_name: String,
|
||||
pub instance_created: chrono::DateTime<chrono::Utc>,
|
||||
pub manifest: ContentManifest,
|
||||
pub complete: bool,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
@@ -118,14 +119,15 @@ async fn reconcile_worker() {
|
||||
};
|
||||
let instance = (job.instance.name.clone(), job.instance.created);
|
||||
let rerun_job = job.clone();
|
||||
let result = reconcile(job, &task).await;
|
||||
if let Ok(mut results) = PENDING_RECONCILIATIONS.lock() {
|
||||
results.retain(|pending| {
|
||||
(pending.instance_name.as_str(), pending.instance_created)
|
||||
!= (instance.0.as_str(), instance.1)
|
||||
});
|
||||
results.push(result);
|
||||
}
|
||||
let result = reconcile(
|
||||
job.instance,
|
||||
job.instances_dir,
|
||||
job.client,
|
||||
&task,
|
||||
publish_reconciliation,
|
||||
)
|
||||
.await;
|
||||
publish_reconciliation(result);
|
||||
if let Ok(mut coordinator) = RECONCILE_COORDINATOR.lock() {
|
||||
if coordinator.rerun.remove(&instance) {
|
||||
coordinator.queue.push_back(rerun_job);
|
||||
@@ -133,16 +135,27 @@ async fn reconcile_worker() {
|
||||
coordinator.scheduled.remove(&instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn publish_reconciliation(result: ReconcileResult) {
|
||||
if let Ok(mut results) = PENDING_RECONCILIATIONS.lock() {
|
||||
results.retain(|pending| {
|
||||
pending.instance_name != result.instance_name
|
||||
|| pending.instance_created != result.instance_created
|
||||
});
|
||||
results.push(result);
|
||||
crate::feedback::request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
let ReconcileJob {
|
||||
instance,
|
||||
instances_dir,
|
||||
client,
|
||||
} = job;
|
||||
pub(crate) async fn reconcile(
|
||||
instance: InstanceConfig,
|
||||
instances_dir: PathBuf,
|
||||
client: crate::net::HttpClient,
|
||||
task: &ProgressTask,
|
||||
mut publish: impl FnMut(ReconcileResult),
|
||||
) -> ReconcileResult {
|
||||
let instance_name = instance.name;
|
||||
let instance_created = instance.created;
|
||||
task.set_action("Checking content");
|
||||
@@ -187,9 +200,16 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
)
|
||||
.await
|
||||
};
|
||||
task.set_action("Saving content index");
|
||||
task.set_sub_action("Validating content files");
|
||||
task.set_action("Validating content files");
|
||||
task.set_sub_action("Rechecking local files");
|
||||
task.set_progress(0, inventory.manifest.files.len() as u64);
|
||||
publish(ReconcileResult {
|
||||
instance_name: instance_name.clone(),
|
||||
instance_created,
|
||||
manifest: inventory.manifest.clone(),
|
||||
complete: false,
|
||||
error: None,
|
||||
});
|
||||
let save_progress = task.handle();
|
||||
let saved = tokio::task::spawn_blocking(move || {
|
||||
save_reconciled_manifest(
|
||||
@@ -216,6 +236,7 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
instance_name,
|
||||
instance_created,
|
||||
manifest: saved.unwrap_or_default(),
|
||||
complete: true,
|
||||
error,
|
||||
}
|
||||
}
|
||||
@@ -223,12 +244,14 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
instance_name,
|
||||
instance_created,
|
||||
manifest: ContentManifest::default(),
|
||||
complete: true,
|
||||
error: Some(error.to_string()),
|
||||
},
|
||||
Err(error) => ReconcileResult {
|
||||
instance_name,
|
||||
instance_created,
|
||||
manifest: ContentManifest::default(),
|
||||
complete: true,
|
||||
error: Some(error.to_string()),
|
||||
},
|
||||
}
|
||||
|
||||
+122
-12
@@ -83,6 +83,24 @@ pub struct BulkUpdatePlan {
|
||||
pub static PENDING_UPDATE_SNAPSHOTS: LazyLock<Arc<Mutex<Vec<PendingUpdateSnapshot>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
|
||||
struct RunningCheck {
|
||||
instance: InstanceConfig,
|
||||
inventory: Vec<ProviderProject>,
|
||||
task: tokio::task::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl RunningCheck {
|
||||
fn matches(&self, instance: &InstanceConfig, manifest: &ContentManifest) -> bool {
|
||||
self.instance.created == instance.created
|
||||
&& self.instance.game_version == instance.game_version
|
||||
&& self.instance.loader == instance.loader
|
||||
&& self.inventory == resolved_inventory(manifest)
|
||||
}
|
||||
}
|
||||
|
||||
static RUNNING_CHECKS: LazyLock<Mutex<HashMap<std::path::PathBuf, RunningCheck>>> =
|
||||
LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
impl UpdateSnapshot {
|
||||
pub fn load(path: &std::path::Path) -> Option<Self> {
|
||||
std::fs::read(path)
|
||||
@@ -124,29 +142,121 @@ pub fn spawn(
|
||||
manifest: ContentManifest,
|
||||
path: std::path::PathBuf,
|
||||
priority: Vec<ProviderProject>,
|
||||
previous: Option<UpdateSnapshot>,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
let previous =
|
||||
UpdateSnapshot::load(&path).filter(|previous| previous.applies_to(&instance));
|
||||
let registry = Arc::new(super::provider::ProviderRegistry::configured(
|
||||
spawn_with_registry(
|
||||
instance,
|
||||
manifest,
|
||||
path,
|
||||
priority,
|
||||
previous,
|
||||
Arc::new(super::provider::ProviderRegistry::configured(
|
||||
crate::net::HttpClient::new(),
|
||||
));
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn is_running(
|
||||
instance: &InstanceConfig,
|
||||
manifest: &ContentManifest,
|
||||
path: &std::path::Path,
|
||||
) -> bool {
|
||||
RUNNING_CHECKS.lock().is_ok_and(|checks| {
|
||||
checks
|
||||
.get(path)
|
||||
.is_some_and(|check| !check.task.is_finished() && check.matches(instance, manifest))
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn cancel(path: Option<&std::path::Path>) {
|
||||
if let Ok(mut checks) = RUNNING_CHECKS.lock() {
|
||||
checks.retain(|check_path, check| {
|
||||
if path.is_none_or(|path| path == check_path) {
|
||||
check.task.abort();
|
||||
if let Ok(mut pending) = PENDING_UPDATE_SNAPSHOTS.lock() {
|
||||
pending.retain(|pending| {
|
||||
pending.instance_name != check.instance.name
|
||||
|| pending.instance_created != check.instance.created
|
||||
});
|
||||
}
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn spawn_with_registry(
|
||||
instance: InstanceConfig,
|
||||
manifest: ContentManifest,
|
||||
path: std::path::PathBuf,
|
||||
priority: Vec<ProviderProject>,
|
||||
previous: Option<UpdateSnapshot>,
|
||||
registry: Arc<super::provider::ProviderRegistry>,
|
||||
) -> bool {
|
||||
let Ok(mut checks) = RUNNING_CHECKS.lock() else {
|
||||
return false;
|
||||
};
|
||||
if let Some(check) = checks.get(&path) {
|
||||
if !check.task.is_finished() && check.matches(&instance, &manifest) {
|
||||
return false;
|
||||
}
|
||||
check.task.abort();
|
||||
}
|
||||
let check_path = path.clone();
|
||||
let check_instance = instance.clone();
|
||||
let inventory = resolved_inventory(&manifest);
|
||||
let task = tokio::spawn(async move {
|
||||
let previous = previous
|
||||
.or_else(|| UpdateSnapshot::load(&path))
|
||||
.filter(|previous| previous.applies_to(&instance));
|
||||
let snapshot = scan_with_registry(
|
||||
&instance,
|
||||
&manifest,
|
||||
&priority,
|
||||
registry,
|
||||
previous.as_ref(),
|
||||
|snapshot| publish_snapshot(&instance, snapshot.clone()),
|
||||
|snapshot| publish_current_snapshot(&instance, snapshot.clone(), &path, false),
|
||||
)
|
||||
.await;
|
||||
if let Ok(bytes) = serde_json::to_vec_pretty(&snapshot)
|
||||
&& let Err(error) = crate::storage::write_atomic(&path, &bytes)
|
||||
{
|
||||
tracing::debug!("Could not cache content update snapshot: {error}");
|
||||
}
|
||||
publish_snapshot(&instance, snapshot);
|
||||
publish_current_snapshot(&instance, snapshot, &path, true);
|
||||
});
|
||||
checks.insert(
|
||||
check_path,
|
||||
RunningCheck {
|
||||
instance: check_instance,
|
||||
inventory,
|
||||
task,
|
||||
},
|
||||
);
|
||||
true
|
||||
}
|
||||
|
||||
fn publish_current_snapshot(
|
||||
instance: &InstanceConfig,
|
||||
snapshot: UpdateSnapshot,
|
||||
path: &std::path::Path,
|
||||
complete: bool,
|
||||
) {
|
||||
let Ok(checks) = RUNNING_CHECKS.lock() else {
|
||||
return;
|
||||
};
|
||||
if checks
|
||||
.get(path)
|
||||
.is_none_or(|check| check.task.id() != tokio::task::id())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Hold the check registry through persistence and publication so a replaced
|
||||
// worker cannot overwrite its successor's snapshot.
|
||||
if complete
|
||||
&& let Ok(bytes) = serde_json::to_vec_pretty(&snapshot)
|
||||
&& let Err(error) = crate::storage::write_atomic(path, &bytes)
|
||||
{
|
||||
tracing::debug!("Could not cache content update snapshot: {error}");
|
||||
}
|
||||
publish_snapshot(instance, snapshot);
|
||||
}
|
||||
|
||||
fn publish_snapshot(instance: &InstanceConfig, snapshot: UpdateSnapshot) {
|
||||
|
||||
@@ -417,6 +417,17 @@ fn provider(versions: Vec<VersionInfo>) -> FakeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn controlled_update_registry(
|
||||
versions: Vec<VersionInfo>,
|
||||
started: tokio::sync::mpsc::UnboundedSender<String>,
|
||||
pauses: HashMap<String, std::sync::Arc<tokio::sync::Semaphore>>,
|
||||
) -> ProviderRegistry {
|
||||
let mut provider = provider(versions);
|
||||
provider.compatible_started = Some(started);
|
||||
provider.compatible_pause = pauses;
|
||||
provider.registry()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_checks_prioritize_list_rows_and_publish_before_the_rest_finish() {
|
||||
use crate::instance::content::updates::{AvailableUpdate, UpdateSnapshot, scan_with_registry};
|
||||
|
||||
+40
-20
@@ -160,16 +160,7 @@ impl App {
|
||||
if local_streamed {
|
||||
self.apply_cached_content_manifest();
|
||||
}
|
||||
if self.content_update_check_pending
|
||||
&& ![
|
||||
&self.mods_state,
|
||||
&self.resource_packs_state,
|
||||
&self.shaders_state,
|
||||
&self.world_datapacks_state,
|
||||
]
|
||||
.iter()
|
||||
.any(|state| state.is_scanning())
|
||||
{
|
||||
if self.content_update_check_ready() {
|
||||
self.content_update_check_pending = false;
|
||||
if crate::config::SETTINGS.read().general.check_content_updates {
|
||||
self.spawn_selected_content_update_check();
|
||||
@@ -423,7 +414,9 @@ impl App {
|
||||
let Some(mut result) = result else {
|
||||
return;
|
||||
};
|
||||
self.reconciliation_for = Some((result.instance_name.clone(), result.instance_created));
|
||||
if result.complete {
|
||||
self.reconciliation_for = Some((result.instance_name.clone(), result.instance_created));
|
||||
}
|
||||
if let Some(error) = &result.error {
|
||||
tracing::warn!(
|
||||
"Content reconciliation for {} was incomplete: {}",
|
||||
@@ -490,18 +483,30 @@ impl App {
|
||||
.instances_dir
|
||||
.join(&result.instance_name),
|
||||
);
|
||||
let cached =
|
||||
crate::instance::content::updates::UpdateSnapshot::load(&paths.content_updates())
|
||||
.filter(|snapshot| snapshot.applies_to(&selected));
|
||||
let stale = cached
|
||||
if self.content_update_snapshot.is_none() {
|
||||
self.content_update_snapshot =
|
||||
crate::instance::content::updates::UpdateSnapshot::load(&paths.content_updates())
|
||||
.filter(|snapshot| snapshot.applies_to(&selected))
|
||||
.map(|snapshot| (result.instance_name.clone(), snapshot));
|
||||
}
|
||||
let stale = self
|
||||
.content_update_snapshot
|
||||
.as_ref()
|
||||
.is_none_or(|snapshot| snapshot.is_stale(&result.manifest));
|
||||
self.content_update_snapshot =
|
||||
cached.map(|snapshot| (result.instance_name.clone(), snapshot));
|
||||
.is_none_or(|(_, snapshot)| snapshot.is_stale(&result.manifest));
|
||||
let running = crate::instance::content::updates::is_running(
|
||||
&selected,
|
||||
&result.manifest,
|
||||
&paths.content_updates(),
|
||||
);
|
||||
self.content_manifest = Some((result.instance_name.clone(), result.manifest.clone()));
|
||||
self.apply_content_update_snapshot();
|
||||
self.content_update_check_pending =
|
||||
stale && crate::config::SETTINGS.read().general.check_content_updates;
|
||||
self.content_update_check_pending |=
|
||||
stale && !running && crate::config::SETTINGS.read().general.check_content_updates;
|
||||
}
|
||||
|
||||
fn content_update_check_ready(&self) -> bool {
|
||||
let active = self.active_installed_content_state();
|
||||
self.content_update_check_pending && !(active.is_scanning() && active.entries.is_empty())
|
||||
}
|
||||
|
||||
fn apply_cached_content_manifest(&mut self) {
|
||||
@@ -561,6 +566,15 @@ impl App {
|
||||
let Some(snapshot) = snapshot else {
|
||||
return;
|
||||
};
|
||||
if self
|
||||
.content_manifest
|
||||
.as_ref()
|
||||
.is_some_and(|(name, manifest)| {
|
||||
name == &snapshot.instance_name && !snapshot.snapshot.is_stale(manifest)
|
||||
})
|
||||
{
|
||||
self.content_update_check_pending = false;
|
||||
}
|
||||
self.content_update_snapshot = Some((snapshot.instance_name, snapshot.snapshot));
|
||||
self.apply_content_update_snapshot();
|
||||
}
|
||||
@@ -1239,6 +1253,12 @@ impl App {
|
||||
}
|
||||
|
||||
pub(super) fn forget_instance_content(&mut self, instance_name: &str) {
|
||||
crate::instance::content::updates::cancel(Some(
|
||||
&crate::storage::InstancePaths::new(
|
||||
self.instance_manager.instances_dir.join(instance_name),
|
||||
)
|
||||
.content_updates(),
|
||||
));
|
||||
self.settings_state
|
||||
.invalidate_java_cache(Some(instance_name));
|
||||
self.cached_instance_content
|
||||
|
||||
+13
-4
@@ -2357,6 +2357,7 @@ impl App {
|
||||
}
|
||||
|
||||
pub(super) fn reset_discovery_states(&mut self) {
|
||||
crate::instance::content::updates::cancel(None);
|
||||
self.reconciliation_for = None;
|
||||
for cached in self.cached_instance_content.values_mut() {
|
||||
cached.reconciliation_for = None;
|
||||
@@ -2397,18 +2398,26 @@ impl App {
|
||||
manifest.clone(),
|
||||
path,
|
||||
self.content_update_priority(),
|
||||
self.content_update_snapshot
|
||||
.as_ref()
|
||||
.map(|(_, snapshot)| snapshot.clone()),
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn content_update_priority(&self) -> Vec<crate::instance::ProviderProject> {
|
||||
let active = match self.content_tab {
|
||||
pub(super) fn active_installed_content_state(
|
||||
&self,
|
||||
) -> &widgets::content::list::ContentListState {
|
||||
match self.content_tab {
|
||||
widgets::content::ContentTab::ResourcePacks => &self.resource_packs_state,
|
||||
widgets::content::ContentTab::Shaders => &self.shaders_state,
|
||||
widgets::content::ContentTab::Worlds => &self.world_datapacks_state,
|
||||
_ => &self.mods_state,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn content_update_priority(&self) -> Vec<crate::instance::ProviderProject> {
|
||||
[
|
||||
active,
|
||||
self.active_installed_content_state(),
|
||||
&self.mods_state,
|
||||
&self.resource_packs_state,
|
||||
&self.shaders_state,
|
||||
|
||||
@@ -176,6 +176,334 @@ fn partial_update_snapshots_label_rows_immediately_and_keep_inactive_results() {
|
||||
assert!(PENDING_UPDATE_SNAPSHOTS.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_badges_stream_while_the_content_index_is_still_being_saved() {
|
||||
use crate::instance::content::{manifest, reconcile, updates};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
fn wait_for(mut ready: impl FnMut() -> bool) {
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(5);
|
||||
while !ready() {
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"content work timed out"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
}
|
||||
|
||||
let mut ui = UiHarness::new();
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(2)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
let _runtime = runtime.enter();
|
||||
ui.add_instance("Streaming index");
|
||||
ui.app.sync_instance_content();
|
||||
let instance = ui.app.instances_state.selected_instance().unwrap().clone();
|
||||
let paths = crate::storage::InstancePaths::new(ui.instance_path(&instance.name));
|
||||
let minecraft = paths.minecraft();
|
||||
let mut saved = crate::instance::ContentManifest::default();
|
||||
let mut entries = Vec::new();
|
||||
let mut versions = Vec::new();
|
||||
let mut pauses = HashMap::new();
|
||||
for name in ["alpha", "bravo"] {
|
||||
let relative_path = std::path::PathBuf::from("mods").join(format!("{name}.jar"));
|
||||
let path = minecraft.join(&relative_path);
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, name).unwrap();
|
||||
saved.files.push(crate::instance::ContentFileRecord {
|
||||
relative_path,
|
||||
kind: crate::instance::ContentKind::Mod,
|
||||
enabled: true,
|
||||
fingerprint: manifest::fingerprint(&path).unwrap(),
|
||||
resolution: crate::instance::Resolution::Resolved {
|
||||
project: crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: name.to_owned(),
|
||||
version_id: format!("{name}-old"),
|
||||
},
|
||||
},
|
||||
provider_aliases: Vec::new(),
|
||||
provider_checks: vec!["modrinth".to_owned(), "curseforge".to_owned()],
|
||||
required_dependencies: Vec::new(),
|
||||
automatic_dependency: false,
|
||||
cleanup_eligible: false,
|
||||
});
|
||||
entries.push(crate::instance::scan_one_mod(&path, name, true));
|
||||
for (suffix, date) in [
|
||||
("old", "2026-01-01T00:00:00Z"),
|
||||
("new", "2026-02-01T00:00:00Z"),
|
||||
] {
|
||||
versions.push(
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"id": format!("{name}-{suffix}"), "project_id": name,
|
||||
"name": name, "version_number": suffix,
|
||||
"date_published": date, "game_versions": ["1.21.1"],
|
||||
"loaders": ["fabric"], "files": []
|
||||
}))
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
pauses.insert(name.to_owned(), Arc::new(tokio::sync::Semaphore::new(0)));
|
||||
}
|
||||
let mut removed = saved.files[0].clone();
|
||||
removed.relative_path = std::path::PathBuf::from("mods").join("removed.jar");
|
||||
saved.files.push(removed);
|
||||
saved.save(&paths.content_manifest()).unwrap();
|
||||
let stream = ui.app.mods_state.start_stream(&instance.name);
|
||||
let _shader_stream = ui.app.shaders_state.start_stream(&instance.name);
|
||||
updates::PENDING_UPDATE_SNAPSHOTS.lock().unwrap().clear();
|
||||
reconcile::PENDING_RECONCILIATIONS.lock().unwrap().clear();
|
||||
let instances_dir = ui.app.instance_manager.instances_dir.clone();
|
||||
let indexing_instance = instance.clone();
|
||||
let (resume_save, saving) = std::sync::mpsc::channel();
|
||||
let indexing = runtime.spawn(async move {
|
||||
let task = crate::feedback::progress::ProgressTask::start("Preparing content index");
|
||||
let result = reconcile::reconcile(
|
||||
indexing_instance,
|
||||
instances_dir,
|
||||
crate::net::HttpClient::new(),
|
||||
&task,
|
||||
move |result| {
|
||||
reconcile::publish_reconciliation(result);
|
||||
saving.recv().unwrap();
|
||||
},
|
||||
)
|
||||
.await;
|
||||
reconcile::publish_reconciliation(result);
|
||||
});
|
||||
wait_for(|| {
|
||||
!reconcile::PENDING_RECONCILIATIONS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
});
|
||||
assert!(!reconcile::PENDING_RECONCILIATIONS.lock().unwrap()[0].complete);
|
||||
ui.app.drain_content_reconciliation();
|
||||
assert_eq!(
|
||||
ui.app.content_update_check_pending,
|
||||
crate::config::SETTINGS.read().general.check_content_updates
|
||||
);
|
||||
assert!(!ui.app.content_update_check_ready());
|
||||
for entry in entries {
|
||||
assert!(stream.send(entry));
|
||||
}
|
||||
ui.app.mods_state.drain_pending();
|
||||
ui.app.apply_cached_content_manifest();
|
||||
assert!(ui.app.content_update_check_ready());
|
||||
assert!(ui.app.mods_state.is_scanning());
|
||||
assert!(ui.app.shaders_state.is_scanning());
|
||||
let priority = ui.app.content_update_priority();
|
||||
let manifest = ui.app.content_manifest.as_ref().unwrap().1.clone();
|
||||
ui.app.content_update_check_pending = false;
|
||||
let (started, mut requests) = tokio::sync::mpsc::unbounded_channel();
|
||||
let registry = Arc::new(
|
||||
crate::instance::content::dependencies::tests::controlled_update_registry(
|
||||
versions,
|
||||
started,
|
||||
pauses.clone(),
|
||||
),
|
||||
);
|
||||
let start_check = |manifest: &crate::instance::ContentManifest, previous| {
|
||||
updates::spawn_with_registry(
|
||||
instance.clone(),
|
||||
manifest.clone(),
|
||||
paths.content_updates(),
|
||||
priority.clone(),
|
||||
previous,
|
||||
registry.clone(),
|
||||
)
|
||||
};
|
||||
let mut wait_for_requests = || {
|
||||
runtime.block_on(async {
|
||||
for _ in 0..2 {
|
||||
tokio::time::timeout(Duration::from_secs(5), requests.recv())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
};
|
||||
assert!(start_check(&manifest, None));
|
||||
assert!(!start_check(&manifest, None));
|
||||
wait_for_requests();
|
||||
pauses["alpha"].add_permits(1);
|
||||
wait_for(|| !updates::PENDING_UPDATE_SNAPSHOTS.lock().unwrap().is_empty());
|
||||
ui.app.drain_content_update_snapshots();
|
||||
assert_eq!(
|
||||
ui.app.mods_state.entries[0].title_suffix.as_deref(),
|
||||
Some("Update")
|
||||
);
|
||||
assert_eq!(ui.app.mods_state.entries[1].title_suffix, None);
|
||||
assert!(updates::is_running(
|
||||
&instance,
|
||||
&manifest,
|
||||
&paths.content_updates()
|
||||
));
|
||||
assert_eq!(
|
||||
crate::instance::ContentManifest::load(&paths.content_manifest())
|
||||
.unwrap()
|
||||
.files
|
||||
.len(),
|
||||
3
|
||||
);
|
||||
assert!(
|
||||
reconcile::PENDING_RECONCILIATIONS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
ui.draw();
|
||||
assert!(ui.screen().contains("Update"));
|
||||
assert_eq!(
|
||||
crate::feedback::progress::PROGRESS.lock().unwrap().progress,
|
||||
Some((1, 2))
|
||||
);
|
||||
|
||||
resume_save.send(()).unwrap();
|
||||
runtime.block_on(indexing).unwrap();
|
||||
wait_for(|| {
|
||||
!reconcile::PENDING_RECONCILIATIONS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
});
|
||||
assert!(reconcile::PENDING_RECONCILIATIONS.lock().unwrap()[0].complete);
|
||||
assert_eq!(
|
||||
crate::instance::ContentManifest::load(&paths.content_manifest())
|
||||
.unwrap()
|
||||
.files
|
||||
.len(),
|
||||
2
|
||||
);
|
||||
ui.app.drain_content_reconciliation();
|
||||
assert!(!ui.app.content_update_check_pending);
|
||||
assert_eq!(
|
||||
ui.app.mods_state.entries[0].title_suffix.as_deref(),
|
||||
Some("Update")
|
||||
);
|
||||
assert_eq!(ui.app.mods_state.entries[1].title_suffix, None);
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.content_update_snapshot
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.1
|
||||
.checked_at,
|
||||
0
|
||||
);
|
||||
pauses["bravo"].add_permits(1);
|
||||
wait_for(|| !updates::is_running(&instance, &manifest, &paths.content_updates()));
|
||||
ui.app.content_update_check_pending = true;
|
||||
ui.app.drain_content_update_snapshots();
|
||||
assert!(!ui.app.content_update_check_pending);
|
||||
assert!(
|
||||
ui.app
|
||||
.mods_state
|
||||
.entries
|
||||
.iter()
|
||||
.all(|entry| entry.title_suffix.as_deref() == Some("Update"))
|
||||
);
|
||||
|
||||
ui.app
|
||||
.content_update_snapshot
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.1
|
||||
.checked_at = 0;
|
||||
reconcile::publish_reconciliation(reconcile::ReconcileResult {
|
||||
instance_name: instance.name.clone(),
|
||||
instance_created: instance.created,
|
||||
manifest: manifest.clone(),
|
||||
complete: true,
|
||||
error: None,
|
||||
});
|
||||
ui.app.drain_content_reconciliation();
|
||||
assert!(ui.app.content_update_check_pending);
|
||||
let previous = ui.app.content_update_snapshot.as_ref().unwrap().1.clone();
|
||||
assert!(start_check(&manifest, Some(previous)));
|
||||
wait_for_requests();
|
||||
|
||||
let mut changed = manifest.clone();
|
||||
changed.files[1].resolution = crate::instance::Resolution::Resolved {
|
||||
project: crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "bravo".to_owned(),
|
||||
version_id: "bravo-new".to_owned(),
|
||||
},
|
||||
};
|
||||
changed.save(&paths.content_manifest()).unwrap();
|
||||
reconcile::publish_reconciliation(reconcile::ReconcileResult {
|
||||
instance_name: instance.name.clone(),
|
||||
instance_created: instance.created,
|
||||
manifest: changed.clone(),
|
||||
complete: true,
|
||||
error: None,
|
||||
});
|
||||
ui.app.drain_content_reconciliation();
|
||||
assert!(ui.app.content_update_check_ready());
|
||||
let previous = ui.app.content_update_snapshot.as_ref().unwrap().1.clone();
|
||||
assert!(start_check(&changed, Some(previous)));
|
||||
wait_for_requests();
|
||||
pauses["bravo"].add_permits(1);
|
||||
wait_for(|| !updates::PENDING_UPDATE_SNAPSHOTS.lock().unwrap().is_empty());
|
||||
ui.app.drain_content_update_snapshots();
|
||||
assert_eq!(
|
||||
ui.app.mods_state.entries[0].title_suffix.as_deref(),
|
||||
Some("Update")
|
||||
);
|
||||
assert_eq!(ui.app.mods_state.entries[1].title_suffix, None);
|
||||
assert!(updates::is_running(
|
||||
&instance,
|
||||
&changed,
|
||||
&paths.content_updates()
|
||||
));
|
||||
assert_eq!(
|
||||
ui.app
|
||||
.content_update_snapshot
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.1
|
||||
.checked_at,
|
||||
0
|
||||
);
|
||||
pauses["alpha"].add_permits(1);
|
||||
wait_for(|| !updates::is_running(&instance, &changed, &paths.content_updates()));
|
||||
ui.app.drain_content_update_snapshots();
|
||||
assert!(
|
||||
ui.app
|
||||
.content_update_snapshot
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.1
|
||||
.matches_manifest(&changed)
|
||||
);
|
||||
assert!(
|
||||
updates::UpdateSnapshot::load(&paths.content_updates())
|
||||
.unwrap()
|
||||
.matches_manifest(&changed)
|
||||
);
|
||||
assert!(!ui.app.content_update_check_pending);
|
||||
let previous = ui.app.content_update_snapshot.as_ref().unwrap().1.clone();
|
||||
assert!(start_check(&changed, Some(previous)));
|
||||
wait_for_requests();
|
||||
assert!(updates::is_running(
|
||||
&instance,
|
||||
&changed,
|
||||
&paths.content_updates()
|
||||
));
|
||||
ui.app.forget_instance_content(&instance.name);
|
||||
assert!(!updates::is_running(
|
||||
&instance,
|
||||
&changed,
|
||||
&paths.content_updates()
|
||||
));
|
||||
assert!(updates::PENDING_UPDATE_SNAPSHOTS.lock().unwrap().is_empty());
|
||||
assert!(requests.try_recv().is_err());
|
||||
}
|
||||
|
||||
fn key_kind(code: KeyCode, kind: KeyEventKind) -> KeyEvent {
|
||||
KeyEvent::new_with_kind(code, KeyModifiers::NONE, kind)
|
||||
}
|
||||
@@ -744,6 +1072,7 @@ fn launcher_config_save_process() {
|
||||
.save_launcher_settings(config)
|
||||
.unwrap();
|
||||
wait_for_java(&mut ui, "jdk17", "10G");
|
||||
wait_for_edited_config(&mut ui, true);
|
||||
|
||||
theme.theme = "dracula".to_owned();
|
||||
theme.border_style = crate::config::theme::BorderStyle::Thick;
|
||||
|
||||
Reference in new issue
Block a user