fix: add tokio-test (#363)

* fix: add tokio-test

* fix: "called `unwrap` on `v` after checking its variant with `is_some`"

    = help: try using `if let` or `match`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
    = note: `-D clippy::unnecessary-unwrap` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::unnecessary_unwrap)]`

* fmt

* set toolchain 1.88.0

* fmt

* fix: cliip
This commit is contained in:
houseme
2025-08-08 10:23:22 +08:00
committed by GitHub
parent b89450f54d
commit 48a9707110
17 changed files with 50 additions and 28 deletions

View File

@@ -16,7 +16,7 @@ name: Continuous Integration
on:
push:
branches: [main]
branches: [ main ]
paths-ignore:
- "**.md"
- "**.txt"
@@ -36,7 +36,7 @@ on:
- ".github/workflows/audit.yml"
- ".github/workflows/performance.yml"
pull_request:
branches: [main]
branches: [ main ]
paths-ignore:
- "**.md"
- "**.txt"

14
Cargo.lock generated
View File

@@ -8492,6 +8492,7 @@ dependencies = [
"serde",
"serde_json",
"tokio",
"tokio-test",
"tokio-util",
]
@@ -10278,6 +10279,19 @@ dependencies = [
"xattr",
]
[[package]]
name = "tokio-test"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7"
dependencies = [
"async-stream",
"bytes",
"futures-core",
"tokio",
"tokio-stream",
]
[[package]]
name = "tokio-util"
version = "0.7.15"

View File

@@ -249,6 +249,7 @@ tokio = { version = "1.47.1", features = ["fs", "rt-multi-thread"] }
tokio-rustls = { version = "0.26.2", default-features = false }
tokio-stream = { version = "0.1.17" }
tokio-tar = "0.3.1"
tokio-test = "0.4.4"
tokio-util = { version = "0.7.15", features = ["io", "compat"] }
tonic = { version = "0.14.0", features = ["gzip"] }
tonic-prost = { version = "0.14.0" }

View File

@@ -24,6 +24,7 @@ pub const SHA_1_HEADER_NAME: &str = "x-amz-checksum-sha1";
pub const SHA_256_HEADER_NAME: &str = "x-amz-checksum-sha256";
pub const CRC_64_NVME_HEADER_NAME: &str = "x-amz-checksum-crc64nvme";
#[allow(dead_code)]
pub(crate) static MD5_HEADER_NAME: &str = "content-md5";
pub const CHECKSUM_ALGORITHMS_IN_PRIORITY_ORDER: [&str; 5] =

View File

@@ -294,7 +294,7 @@ impl Checksum for Sha256 {
Self::size()
}
}
#[allow(dead_code)]
#[derive(Debug, Default)]
struct Md5 {
hasher: md5::Md5,

View File

@@ -54,8 +54,8 @@ pub fn get_object_retention_meta(meta: HashMap<String, String>) -> ObjectLockRet
}
if let Some(till_str) = till_str {
let t = OffsetDateTime::parse(till_str, &format_description::well_known::Iso8601::DEFAULT);
if t.is_err() {
retain_until_date = Date::from(t.expect("err")); //TODO: utc
if let Ok(parsed_time) = t {
retain_until_date = Date::from(parsed_time);
}
}
ObjectLockRetention {

View File

@@ -1897,7 +1897,7 @@ impl ReplicationState {
} else if !self.replica_status.is_empty() {
self.replica_status.clone()
} else {
return ReplicationStatusType::Unknown;
ReplicationStatusType::Unknown
}
}

View File

@@ -139,8 +139,8 @@ async fn init_format_erasure(
let idx = i * set_drive_count + j;
let mut newfm = fm.clone();
newfm.erasure.this = fm.erasure.sets[i][j];
if deployment_id.is_some() {
newfm.id = deployment_id.unwrap();
if let Some(id) = deployment_id {
newfm.id = id;
}
fms[idx] = Some(newfm);

View File

@@ -2363,7 +2363,7 @@ mod test {
assert!(stats.delete_markers > 0, "应该有删除标记");
// 测试版本合并功能
let merged = merge_file_meta_versions(1, false, 0, &[fm.versions.clone()]);
let merged = merge_file_meta_versions(1, false, 0, std::slice::from_ref(&fm.versions));
assert!(!merged.is_empty(), "合并后应该有版本");
}

View File

@@ -795,24 +795,26 @@ impl<T: Clone + Debug + Send + 'static> Cache<T> {
}
}
if self.opts.no_wait && v.is_some() && now - self.last_update_ms.load(AtomicOrdering::SeqCst) < self.ttl.as_secs() * 2 {
if self.updating.try_lock().is_ok() {
let this = Arc::clone(&self);
spawn(async move {
let _ = this.update().await;
});
if self.opts.no_wait && now - self.last_update_ms.load(AtomicOrdering::SeqCst) < self.ttl.as_secs() * 2 {
if let Some(value) = v {
if self.updating.try_lock().is_ok() {
let this = Arc::clone(&self);
spawn(async move {
let _ = this.update().await;
});
}
return Ok(value);
}
return Ok(v.unwrap());
}
let _ = self.updating.lock().await;
if let Ok(duration) =
SystemTime::now().duration_since(UNIX_EPOCH + Duration::from_secs(self.last_update_ms.load(AtomicOrdering::SeqCst)))
{
if let (Ok(duration), Some(value)) = (
SystemTime::now().duration_since(UNIX_EPOCH + Duration::from_secs(self.last_update_ms.load(AtomicOrdering::SeqCst))),
v,
) {
if duration < self.ttl {
return Ok(v.unwrap());
return Ok(value);
}
}

View File

@@ -45,4 +45,4 @@ serde_json.workspace = true
md-5 = { workspace = true }
[dev-dependencies]
tokio = { workspace = true, features = ["test-util"] }
tokio-test = { workspace = true }

View File

@@ -103,7 +103,7 @@ impl TableSource for TableSourceAdapter {
}
/// Called by [`InlineTableScan`]
fn get_logical_plan(&self) -> Option<Cow<LogicalPlan>> {
fn get_logical_plan(&self) -> Option<Cow<'_, LogicalPlan>> {
Some(Cow::Owned(self.plan.clone()))
}
}

View File

@@ -53,7 +53,6 @@ use s3s::stream::{ByteStream, DynByteStream};
use s3s::{Body, S3Error, S3Request, S3Response, S3Result, s3_error};
use s3s::{S3ErrorCode, StdError};
use serde::{Deserialize, Serialize};
use tracing::debug;
// use serde_json::to_vec;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
@@ -65,6 +64,7 @@ use tokio::sync::mpsc::{self};
use tokio::time::interval;
use tokio::{select, spawn};
use tokio_stream::wrappers::ReceiverStream;
use tracing::debug;
use tracing::{error, info, warn};
// use url::UrlQuery;
@@ -81,6 +81,7 @@ pub mod trace;
pub mod user;
use urlencoding::decode;
#[allow(dead_code)]
#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "PascalCase", default)]
pub struct AccountInfo {

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(dead_code)]
use crate::admin::router::Operation;
use crate::auth::{check_key_valid, get_session_token};
use http::{HeaderMap, StatusCode};

View File

@@ -341,6 +341,7 @@ impl Operation for RemoveTier {
}
}
#[allow(dead_code)]
pub struct VerifyTier {}
#[async_trait::async_trait]
impl Operation for VerifyTier {

View File

@@ -22,6 +22,7 @@ use tracing::warn;
use crate::admin::router::Operation;
#[allow(dead_code)]
fn extract_trace_options(uri: &Uri) -> S3Result<ServiceTraceOpts> {
let mut st_opts = ServiceTraceOpts::default();
st_opts
@@ -31,6 +32,7 @@ fn extract_trace_options(uri: &Uri) -> S3Result<ServiceTraceOpts> {
Ok(st_opts)
}
#[allow(dead_code)]
pub struct Trace {}
#[async_trait::async_trait]

View File

@@ -490,11 +490,9 @@ mod tests {
let result = check_claims_from_token("", &cred);
// This might fail due to global state dependencies, but should return error about global cred init
if result.is_ok() {
let claims = result.unwrap();
if let Ok(claims) = result {
assert!(claims.is_empty());
} else {
let error = result.unwrap_err();
} else if let Err(error) = result {
assert_eq!(error.code(), &S3ErrorCode::InternalError);
assert!(error.message().unwrap_or("").contains("action cred not init"));
}