From 310eb28e63034ab0aa6796f2cd5351c2ffd651f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Vasconcellos?= Date: Thu, 25 Apr 2024 14:58:50 -0300 Subject: [PATCH] Fix `cargo test` & improve `pnpm prep` native deps download (#2393) Couple of fixes - Increase `pnpm prep` connection timeout to 5min, to better handle downloading native deps under flaky network conditions - Fix `cargo test` and cache-factory CI - Clippy and fmt --- apps/desktop/src-tauri/src/main.rs | 2 +- core/src/api/files.rs | 2 +- core/src/api/p2p.rs | 3 +-- core/src/api/search/mod.rs | 12 +++++------ .../src/keyring/linux/secret_service.rs | 13 +++++------- crates/p2p-block/src/block.rs | 2 -- crates/p2p-block/src/sb_request.rs | 2 +- crates/sync/src/compressed.rs | 20 ++++++++----------- scripts/utils/fetch.mjs | 10 +++++++++- 9 files changed, 31 insertions(+), 35 deletions(-) diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 579152429..aaaed1dbf 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -187,7 +187,7 @@ async fn open_trash_in_os_explorer() -> Result<(), ()> { .wait() .map_err(|err| error!("Error opening trash: {err:#?}"))?; - return Ok(()); + Ok(()) } } diff --git a/core/src/api/files.rs b/core/src/api/files.rs index 63ede3af3..684406272 100644 --- a/core/src/api/files.rs +++ b/core/src/api/files.rs @@ -561,7 +561,7 @@ pub(crate) fn mount() -> AlphaRouter { ); #[cfg(not(any(target_os = "ios", target_os = "android")))] - trash::delete(&full_path).unwrap(); + trash::delete(full_path).unwrap(); Ok(()) } diff --git a/core/src/api/p2p.rs b/core/src/api/p2p.rs index c042db75a..89c88ea17 100644 --- a/core/src/api/p2p.rs +++ b/core/src/api/p2p.rs @@ -79,8 +79,7 @@ pub(crate) fn mount() -> AlphaRouter { .p2p .listeners() .iter() - .map(|l| l.addrs.clone()) - .flatten() + .flat_map(|l| l.addrs.clone()) .collect::>(); let errors = node diff --git a/core/src/api/search/mod.rs b/core/src/api/search/mod.rs index 9eb1d8a82..80961b0de 100644 --- a/core/src/api/search/mod.rs +++ b/core/src/api/search/mod.rs @@ -36,7 +36,7 @@ pub mod object; pub mod saved; mod utils; -pub use self::{file_path::*, object::*, utils::*}; +pub use self::{file_path::*, object::*}; use super::{Ctx, R}; @@ -69,10 +69,11 @@ impl SearchFilterArgs { file_path: &mut Vec, object: &mut Vec, ) -> Result<(), rspc::Error> { - Ok(match self { + match self { Self::FilePath(v) => file_path.extend(v.into_params(db).await?), Self::Object(v) => object.extend(v.into_params()), - }) + }; + Ok(()) } } @@ -160,12 +161,9 @@ pub fn mount() -> AlphaRouter { }).collect::>() )]) .exec() - .await - .and_then(|l| { - Ok(l.into_iter() + .await.map(|l| l.into_iter() .filter_map(|item| item.path.clone().map(|l| (l, item))) .collect::>()) - }) .map_err(|err| error!("Looking up locations failed: {err:?}")) .unwrap_or_default(); diff --git a/crates/crypto/src/keyring/linux/secret_service.rs b/crates/crypto/src/keyring/linux/secret_service.rs index 4236174d9..334a52b88 100644 --- a/crates/crypto/src/keyring/linux/secret_service.rs +++ b/crates/crypto/src/keyring/linux/secret_service.rs @@ -33,14 +33,11 @@ impl KeyringInterface for SecretServiceKeyring { } fn contains_key(&self, id: &Identifier) -> bool { - self.get_collection() - .ok() - .map(|k| { - k.search_items(id.as_sec_ser_identifier()) - .ok() - .map_or(false, |x| !x.is_empty()) - }) - .unwrap_or_default() + self.get_collection().ok().is_some_and(|k| { + k.search_items(id.as_sec_ser_identifier()) + .ok() + .map_or(false, |x| !x.is_empty()) + }) } fn get(&self, id: &Identifier) -> Result>> { diff --git a/crates/p2p-block/src/block.rs b/crates/p2p-block/src/block.rs index be64f4e3c..12268c822 100644 --- a/crates/p2p-block/src/block.rs +++ b/crates/p2p-block/src/block.rs @@ -58,8 +58,6 @@ impl<'a> Block<'a> { mod tests { use std::io::Cursor; - use crate::BlockSize; - use super::*; #[tokio::test] diff --git a/crates/p2p-block/src/sb_request.rs b/crates/p2p-block/src/sb_request.rs index a119b2923..1384ca5ed 100644 --- a/crates/p2p-block/src/sb_request.rs +++ b/crates/p2p-block/src/sb_request.rs @@ -198,7 +198,7 @@ mod tests { async fn test_spaceblock_requests_empty() { let req = SpaceblockRequests { id: Uuid::new_v4(), - block_size: BlockSize::from_size(42069), + block_size: BlockSize::from_file_size(42069), requests: vec![], }; diff --git a/crates/sync/src/compressed.rs b/crates/sync/src/compressed.rs index 79585cef1..bdcd523da 100644 --- a/crates/sync/src/compressed.rs +++ b/crates/sync/src/compressed.rs @@ -23,7 +23,7 @@ impl CompressedCRDTOperations { let mut instance_id = first.instance; let mut instance = vec![]; - let mut model_str = first.model.clone(); + let mut model_str = first.model; let mut model = vec![]; let mut record_id = first.record_id.clone(); @@ -36,7 +36,7 @@ impl CompressedCRDTOperations { std::mem::take(&mut record), )); instance.push(( - std::mem::replace(&mut model_str, op.model.clone()), + std::mem::replace(&mut model_str, op.model), std::mem::take(&mut model), )); compressed.push(( @@ -49,7 +49,7 @@ impl CompressedCRDTOperations { std::mem::take(&mut record), )); instance.push(( - std::mem::replace(&mut model_str, op.model.clone()), + std::mem::replace(&mut model_str, op.model), std::mem::take(&mut model), )); } else if record_id != op.record_id { @@ -72,10 +72,8 @@ impl CompressedCRDTOperations { pub fn first(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> { self.0.first().and_then(|(instance, data)| { data.first().and_then(|(model, data)| { - data.first().and_then(|(record, ops)| { - ops.first() - .and_then(|op| Some((*instance, *model, record, op))) - }) + data.first() + .and_then(|(record, ops)| ops.first().map(|op| (*instance, *model, record, op))) }) }) } @@ -83,10 +81,8 @@ impl CompressedCRDTOperations { pub fn last(&self) -> Option<(Uuid, u16, &rmpv::Value, &CompressedCRDTOperation)> { self.0.last().and_then(|(instance, data)| { data.last().and_then(|(model, data)| { - data.last().and_then(|(record, ops)| { - ops.last() - .and_then(|op| Some((*instance, *model, record, op))) - }) + data.last() + .and_then(|(record, ops)| ops.last().map(|op| (*instance, *model, record, op))) }) }) } @@ -111,7 +107,7 @@ impl CompressedCRDTOperations { for op in record { ops.push(CRDTOperation { instance: instance_id, - model: model_str.clone(), + model: model_str, record_id: record_id.clone(), timestamp: op.timestamp, data: op.data, diff --git a/scripts/utils/fetch.mjs b/scripts/utils/fetch.mjs index dbf5b0225..778148fad 100644 --- a/scripts/utils/fetch.mjs +++ b/scripts/utils/fetch.mjs @@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url' import { getSystemProxy } from 'os-proxy-config' import { fetch, Headers, Agent, ProxyAgent } from 'undici' +const CONNECT_TIMEOUT = 5 * 60 * 1000 const __debug = env.NODE_ENV === 'debug' const __offline = env.OFFLINE === 'true' const __filename = fileURLToPath(import.meta.url) @@ -15,12 +16,19 @@ const cacheDir = joinPath(__dirname, '.tmp') /** @type {Agent.Options} */ const agentOpts = { allowH2: true, + connect: { timeout: CONNECT_TIMEOUT }, + connectTimeout: CONNECT_TIMEOUT, autoSelectFamily: true, } const { proxyUrl } = (await getSystemProxy()) ?? {} const dispatcher = proxyUrl - ? new ProxyAgent({ ...agentOpts, uri: proxyUrl }) + ? new ProxyAgent({ + ...agentOpts, + proxyTls: { timeout: CONNECT_TIMEOUT }, + requestTls: { timeout: CONNECT_TIMEOUT }, + uri: proxyUrl, + }) : new Agent(agentOpts) await fs.mkdir(cacheDir, { recursive: true, mode: 0o751 })