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
+2 -2
View File
@@ -16,7 +16,7 @@ name: Continuous Integration
on: on:
push: push:
branches: [main] branches: [ main ]
paths-ignore: paths-ignore:
- "**.md" - "**.md"
- "**.txt" - "**.txt"
@@ -36,7 +36,7 @@ on:
- ".github/workflows/audit.yml" - ".github/workflows/audit.yml"
- ".github/workflows/performance.yml" - ".github/workflows/performance.yml"
pull_request: pull_request:
branches: [main] branches: [ main ]
paths-ignore: paths-ignore:
- "**.md" - "**.md"
- "**.txt" - "**.txt"
Generated
+14
View File
@@ -8492,6 +8492,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
"tokio-test",
"tokio-util", "tokio-util",
] ]
@@ -10278,6 +10279,19 @@ dependencies = [
"xattr", "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]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.15" version = "0.7.15"
+1
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-rustls = { version = "0.26.2", default-features = false }
tokio-stream = { version = "0.1.17" } tokio-stream = { version = "0.1.17" }
tokio-tar = "0.3.1" tokio-tar = "0.3.1"
tokio-test = "0.4.4"
tokio-util = { version = "0.7.15", features = ["io", "compat"] } tokio-util = { version = "0.7.15", features = ["io", "compat"] }
tonic = { version = "0.14.0", features = ["gzip"] } tonic = { version = "0.14.0", features = ["gzip"] }
tonic-prost = { version = "0.14.0" } tonic-prost = { version = "0.14.0" }
+1
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 SHA_256_HEADER_NAME: &str = "x-amz-checksum-sha256";
pub const CRC_64_NVME_HEADER_NAME: &str = "x-amz-checksum-crc64nvme"; 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(crate) static MD5_HEADER_NAME: &str = "content-md5";
pub const CHECKSUM_ALGORITHMS_IN_PRIORITY_ORDER: [&str; 5] = pub const CHECKSUM_ALGORITHMS_IN_PRIORITY_ORDER: [&str; 5] =
+1 -1
View File
@@ -294,7 +294,7 @@ impl Checksum for Sha256 {
Self::size() Self::size()
} }
} }
#[allow(dead_code)]
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Md5 { struct Md5 {
hasher: md5::Md5, hasher: md5::Md5,
@@ -54,8 +54,8 @@ pub fn get_object_retention_meta(meta: HashMap<String, String>) -> ObjectLockRet
} }
if let Some(till_str) = till_str { if let Some(till_str) = till_str {
let t = OffsetDateTime::parse(till_str, &format_description::well_known::Iso8601::DEFAULT); let t = OffsetDateTime::parse(till_str, &format_description::well_known::Iso8601::DEFAULT);
if t.is_err() { if let Ok(parsed_time) = t {
retain_until_date = Date::from(t.expect("err")); //TODO: utc retain_until_date = Date::from(parsed_time);
} }
} }
ObjectLockRetention { ObjectLockRetention {
+1 -1
View File
@@ -1897,7 +1897,7 @@ impl ReplicationState {
} else if !self.replica_status.is_empty() { } else if !self.replica_status.is_empty() {
self.replica_status.clone() self.replica_status.clone()
} else { } else {
return ReplicationStatusType::Unknown; ReplicationStatusType::Unknown
} }
} }
+2 -2
View File
@@ -139,8 +139,8 @@ async fn init_format_erasure(
let idx = i * set_drive_count + j; let idx = i * set_drive_count + j;
let mut newfm = fm.clone(); let mut newfm = fm.clone();
newfm.erasure.this = fm.erasure.sets[i][j]; newfm.erasure.this = fm.erasure.sets[i][j];
if deployment_id.is_some() { if let Some(id) = deployment_id {
newfm.id = deployment_id.unwrap(); newfm.id = id;
} }
fms[idx] = Some(newfm); fms[idx] = Some(newfm);
+1 -1
View File
@@ -2363,7 +2363,7 @@ mod test {
assert!(stats.delete_markers > 0, "应该有删除标记"); 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(), "合并后应该有版本"); assert!(!merged.is_empty(), "合并后应该有版本");
} }
+14 -12
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.opts.no_wait && now - self.last_update_ms.load(AtomicOrdering::SeqCst) < self.ttl.as_secs() * 2 {
if self.updating.try_lock().is_ok() { if let Some(value) = v {
let this = Arc::clone(&self); if self.updating.try_lock().is_ok() {
spawn(async move { let this = Arc::clone(&self);
let _ = this.update().await; spawn(async move {
}); let _ = this.update().await;
});
}
return Ok(value);
} }
return Ok(v.unwrap());
} }
let _ = self.updating.lock().await; let _ = self.updating.lock().await;
if let Ok(duration) = if let (Ok(duration), Some(value)) = (
SystemTime::now().duration_since(UNIX_EPOCH + Duration::from_secs(self.last_update_ms.load(AtomicOrdering::SeqCst))) SystemTime::now().duration_since(UNIX_EPOCH + Duration::from_secs(self.last_update_ms.load(AtomicOrdering::SeqCst))),
{ v,
) {
if duration < self.ttl { if duration < self.ttl {
return Ok(v.unwrap()); return Ok(value);
} }
} }
+1 -1
View File
@@ -45,4 +45,4 @@ serde_json.workspace = true
md-5 = { workspace = true } md-5 = { workspace = true }
[dev-dependencies] [dev-dependencies]
tokio = { workspace = true, features = ["test-util"] } tokio-test = { workspace = true }
@@ -103,7 +103,7 @@ impl TableSource for TableSourceAdapter {
} }
/// Called by [`InlineTableScan`] /// 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())) Some(Cow::Owned(self.plan.clone()))
} }
} }
+2 -1
View File
@@ -53,7 +53,6 @@ use s3s::stream::{ByteStream, DynByteStream};
use s3s::{Body, S3Error, S3Request, S3Response, S3Result, s3_error}; use s3s::{Body, S3Error, S3Request, S3Response, S3Result, s3_error};
use s3s::{S3ErrorCode, StdError}; use s3s::{S3ErrorCode, StdError};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::debug;
// use serde_json::to_vec; // use serde_json::to_vec;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::path::PathBuf; use std::path::PathBuf;
@@ -65,6 +64,7 @@ use tokio::sync::mpsc::{self};
use tokio::time::interval; use tokio::time::interval;
use tokio::{select, spawn}; use tokio::{select, spawn};
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
use tracing::debug;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
// use url::UrlQuery; // use url::UrlQuery;
@@ -81,6 +81,7 @@ pub mod trace;
pub mod user; pub mod user;
use urlencoding::decode; use urlencoding::decode;
#[allow(dead_code)]
#[derive(Debug, Serialize, Default)] #[derive(Debug, Serialize, Default)]
#[serde(rename_all = "PascalCase", default)] #[serde(rename_all = "PascalCase", default)]
pub struct AccountInfo { pub struct AccountInfo {
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![allow(dead_code)]
use crate::admin::router::Operation; use crate::admin::router::Operation;
use crate::auth::{check_key_valid, get_session_token}; use crate::auth::{check_key_valid, get_session_token};
use http::{HeaderMap, StatusCode}; use http::{HeaderMap, StatusCode};
+1
View File
@@ -341,6 +341,7 @@ impl Operation for RemoveTier {
} }
} }
#[allow(dead_code)]
pub struct VerifyTier {} pub struct VerifyTier {}
#[async_trait::async_trait] #[async_trait::async_trait]
impl Operation for VerifyTier { impl Operation for VerifyTier {
+2
View File
@@ -22,6 +22,7 @@ use tracing::warn;
use crate::admin::router::Operation; use crate::admin::router::Operation;
#[allow(dead_code)]
fn extract_trace_options(uri: &Uri) -> S3Result<ServiceTraceOpts> { fn extract_trace_options(uri: &Uri) -> S3Result<ServiceTraceOpts> {
let mut st_opts = ServiceTraceOpts::default(); let mut st_opts = ServiceTraceOpts::default();
st_opts st_opts
@@ -31,6 +32,7 @@ fn extract_trace_options(uri: &Uri) -> S3Result<ServiceTraceOpts> {
Ok(st_opts) Ok(st_opts)
} }
#[allow(dead_code)]
pub struct Trace {} pub struct Trace {}
#[async_trait::async_trait] #[async_trait::async_trait]
+2 -4
View File
@@ -490,11 +490,9 @@ mod tests {
let result = check_claims_from_token("", &cred); let result = check_claims_from_token("", &cred);
// This might fail due to global state dependencies, but should return error about global cred init // This might fail due to global state dependencies, but should return error about global cred init
if result.is_ok() { if let Ok(claims) = result {
let claims = result.unwrap();
assert!(claims.is_empty()); assert!(claims.is_empty());
} else { } else if let Err(error) = result {
let error = result.unwrap_err();
assert_eq!(error.code(), &S3ErrorCode::InternalError); assert_eq!(error.code(), &S3ErrorCode::InternalError);
assert!(error.message().unwrap_or("").contains("action cred not init")); assert!(error.message().unwrap_or("").contains("action cred not init"));
} }