diff options
25 files changed, 21 insertions, 41 deletions
@@ -1 +1 @@ -7226cbe46016b51a2f76743555e734415f67923b
\ No newline at end of file +f414cd9a922f157165dc954757e9ba3aca30fa53
\ No newline at end of file diff --git a/pingora-cache/src/cache_control.rs b/pingora-cache/src/cache_control.rs index 6686c3e..a8a893f 100644 --- a/pingora-cache/src/cache_control.rs +++ b/pingora-cache/src/cache_control.rs @@ -20,8 +20,7 @@ use http::header::HeaderName; use http::HeaderValue; use indexmap::IndexMap; use once_cell::sync::Lazy; -use pingora_error::{Error, ErrorType, Result}; -use pingora_http::ResponseHeader; +use pingora_error::{Error, ErrorType}; use regex::bytes::Regex; use std::num::IntErrorKind; use std::slice; @@ -434,7 +433,6 @@ pub trait InterpretCacheControl { mod tests { use super::*; use http::header::CACHE_CONTROL; - use http::HeaderValue; use http::{request, response}; fn build_response(cc_key: HeaderName, cc_value: &str) -> response::Parts { diff --git a/pingora-cache/src/eviction/lru.rs b/pingora-cache/src/eviction/lru.rs index 35ceb77..9c00a94 100644 --- a/pingora-cache/src/eviction/lru.rs +++ b/pingora-cache/src/eviction/lru.rs @@ -233,7 +233,6 @@ impl<const N: usize> EvictionManager for Manager<N> { mod test { use super::*; use crate::CacheKey; - use EvictionManager; // we use shard (N) = 1 for eviction consistency in all tests diff --git a/pingora-cache/src/filters.rs b/pingora-cache/src/filters.rs index 4255673..b84bbf7 100644 --- a/pingora-cache/src/filters.rs +++ b/pingora-cache/src/filters.rs @@ -16,12 +16,12 @@ use super::*; use crate::cache_control::{CacheControl, Cacheable, InterpretCacheControl}; -use crate::{RespCacheable, RespCacheable::*}; +use crate::RespCacheable::*; use http::{header, HeaderValue}; use httpdate::HttpDate; use log::warn; -use pingora_http::{RequestHeader, ResponseHeader}; +use pingora_http::RequestHeader; /// Decide if the request can be cacheable pub fn request_cacheable(req_header: &ReqHeader) -> bool { @@ -206,6 +206,7 @@ pub mod upstream { #[cfg(test)] mod tests { use super::*; + use crate::RespCacheable::Cacheable; use http::header::{HeaderName, CACHE_CONTROL, EXPIRES, SET_COOKIE}; use http::StatusCode; use httpdate::fmt_http_date; diff --git a/pingora-cache/src/memory.rs b/pingora-cache/src/memory.rs index 525bf23..6d0a519 100644 --- a/pingora-cache/src/memory.rs +++ b/pingora-cache/src/memory.rs @@ -19,8 +19,8 @@ //TODO: Mark this module #[test] only use super::*; -use crate::key::{CacheHashKey, CompactCacheKey}; -use crate::storage::{HandleHit, HandleMiss, Storage}; +use crate::key::CompactCacheKey; +use crate::storage::{HandleHit, HandleMiss}; use crate::trace::SpanHandle; use async_trait::async_trait; diff --git a/pingora-cache/src/put.rs b/pingora-cache/src/put.rs index c50cc2b..be0d510 100644 --- a/pingora-cache/src/put.rs +++ b/pingora-cache/src/put.rs @@ -264,14 +264,12 @@ mod test { mod parse_response { use super::*; - use bytes::{Bytes, BytesMut}; + use bytes::BytesMut; use httparse::Status; use pingora_error::{ Error, ErrorType::{self, *}, - Result, }; - use pingora_http::ResponseHeader; pub const INVALID_CHUNK: ErrorType = ErrorType::new("InvalidChunk"); pub const INCOMPLETE_BODY: ErrorType = ErrorType::new("IncompleteHttpBody"); @@ -280,7 +278,7 @@ mod parse_response { const INIT_HEADER_BUF_SIZE: usize = 4096; const CHUNK_DELIMITER_SIZE: usize = 2; // \r\n - #[derive(Debug, Clone, Copy)] + #[derive(Debug, Clone, Copy, PartialEq)] enum ParseState { Init, PartialHeader, @@ -561,6 +559,10 @@ mod parse_response { let output = parser.inject_data(input); // header is not complete assert!(output.is_err()); + match parser.state { + ParseState::Invalid(httparse::Error::Version) => {} + _ => panic!("should have failed to parse"), + } } #[test] diff --git a/pingora-core/src/apps/prometheus_http_app.rs b/pingora-core/src/apps/prometheus_http_app.rs index 3508d20..36513a1 100644 --- a/pingora-core/src/apps/prometheus_http_app.rs +++ b/pingora-core/src/apps/prometheus_http_app.rs @@ -15,7 +15,7 @@ //! An HTTP application that reports Prometheus metrics. use async_trait::async_trait; -use http::{self, Response}; +use http::Response; use prometheus::{Encoder, TextEncoder}; use super::http_app::HttpServer; diff --git a/pingora-core/src/connectors/mod.rs b/pingora-core/src/connectors/mod.rs index e35df37..9a4a236 100644 --- a/pingora-core/src/connectors/mod.rs +++ b/pingora-core/src/connectors/mod.rs @@ -427,7 +427,7 @@ mod tests { let stream = connector.new_stream(&peer).await; let error = stream.unwrap_err(); - // XXX: some system will allow the socket to bind and connect without error, only to timeout + // XXX: some systems will allow the socket to bind and connect without error, only to timeout assert!(error.etype() == &ConnectError || error.etype() == &ConnectTimedout) } diff --git a/pingora-core/src/protocols/http/date.rs b/pingora-core/src/protocols/http/date.rs index 4b15c4e..20e6375 100644 --- a/pingora-core/src/protocols/http/date.rs +++ b/pingora-core/src/protocols/http/date.rs @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use chrono::NaiveDateTime; +use chrono::DateTime; use http::header::HeaderValue; use std::cell::RefCell; use std::time::{Duration, SystemTime}; fn to_date_string(epoch_sec: i64) -> String { - let dt = NaiveDateTime::from_timestamp_opt(epoch_sec, 0).unwrap(); + let dt = DateTime::from_timestamp(epoch_sec, 0).unwrap(); dt.format("%a, %d %b %Y %H:%M:%S GMT").to_string() } diff --git a/pingora-core/src/protocols/http/v1/body.rs b/pingora-core/src/protocols/http/v1/body.rs index 8968f9e..c317bb7 100644 --- a/pingora-core/src/protocols/http/v1/body.rs +++ b/pingora-core/src/protocols/http/v1/body.rs @@ -644,7 +644,6 @@ impl BodyWriter { #[cfg(test)] mod tests { use super::*; - use crate::utils::BufRef; use tokio_test::io::Builder; fn init_log() { diff --git a/pingora-core/src/protocols/http/v1/client.rs b/pingora-core/src/protocols/http/v1/client.rs index 1d970d7..e28d2af 100644 --- a/pingora-core/src/protocols/http/v1/client.rs +++ b/pingora-core/src/protocols/http/v1/client.rs @@ -672,8 +672,6 @@ mod tests_stream { use super::*; use crate::protocols::http::v1::body::ParseState; use crate::ErrorType; - use std::str; - use std::time::Duration; use tokio_test::io::Builder; fn init_log() { diff --git a/pingora-core/src/protocols/http/v1/server.rs b/pingora-core/src/protocols/http/v1/server.rs index 5b3a111..c1b2d75 100644 --- a/pingora-core/src/protocols/http/v1/server.rs +++ b/pingora-core/src/protocols/http/v1/server.rs @@ -983,9 +983,8 @@ fn http_resp_header_to_buf( mod tests_stream { use super::*; use crate::protocols::http::v1::body::{BodyMode, ParseState}; - use http::{Method, StatusCode}; + use http::StatusCode; use std::str; - use std::time::Duration; use tokio_test::io::Builder; fn init_log() { diff --git a/pingora-core/src/server/mod.rs b/pingora-core/src/server/mod.rs index 4273550..fa2cea2 100644 --- a/pingora-core/src/server/mod.rs +++ b/pingora-core/src/server/mod.rs @@ -22,7 +22,6 @@ use daemon::daemonize; use log::{debug, error, info}; use pingora_runtime::Runtime; use pingora_timeout::fast_timeout; -use std::clone::Clone; use std::sync::Arc; use std::thread; use tokio::signal::unix; diff --git a/pingora-core/src/server/transfer_fd/mod.rs b/pingora-core/src/server/transfer_fd/mod.rs index ae07e33..d773935 100644 --- a/pingora-core/src/server/transfer_fd/mod.rs +++ b/pingora-core/src/server/transfer_fd/mod.rs @@ -343,7 +343,6 @@ where mod tests { use super::*; use log::{debug, error}; - use std::thread; fn init_log() { let _ = env_logger::builder().is_test(true).try_init(); diff --git a/pingora-http/src/lib.rs b/pingora-http/src/lib.rs index f310308..24b648f 100644 --- a/pingora-http/src/lib.rs +++ b/pingora-http/src/lib.rs @@ -30,7 +30,6 @@ use http::response::Builder as RespBuilder; use http::response::Parts as RespParts; use http::uri::Uri; use pingora_error::{ErrorType::*, OrErr, Result}; -use std::convert::TryInto; use std::ops::Deref; pub use http::method::Method; diff --git a/pingora-load-balancing/src/selection/consistent.rs b/pingora-load-balancing/src/selection/consistent.rs index 60c7b9f..9c62726 100644 --- a/pingora-load-balancing/src/selection/consistent.rs +++ b/pingora-load-balancing/src/selection/consistent.rs @@ -18,7 +18,6 @@ use super::*; use pingora_core::protocols::l4::socket::SocketAddr; use pingora_ketama::{Bucket, Continuum}; use std::collections::HashMap; -use std::sync::Arc; /// Weighted Ketama consistent hashing pub struct KetamaHashing { diff --git a/pingora-proxy/src/proxy_h1.rs b/pingora-proxy/src/proxy_h1.rs index 77bc50b..f50d310 100644 --- a/pingora-proxy/src/proxy_h1.rs +++ b/pingora-proxy/src/proxy_h1.rs @@ -15,7 +15,6 @@ use super::*; use crate::proxy_cache::{range_filter::RangeBodyFilter, ServeFromCache}; use crate::proxy_common::*; -use http::Version; impl<SV> HttpProxy<SV> { pub(crate) async fn proxy_1to1( diff --git a/pingora-proxy/src/proxy_purge.rs b/pingora-proxy/src/proxy_purge.rs index 16796ba..73e27a0 100644 --- a/pingora-proxy/src/proxy_purge.rs +++ b/pingora-proxy/src/proxy_purge.rs @@ -14,9 +14,6 @@ use super::*; -use once_cell::sync::Lazy; -use pingora_core::protocols::http::SERVER_NAME; - fn gen_purge_response(code: u16) -> ResponseHeader { let mut resp = ResponseHeader::build(code, Some(3)).unwrap(); resp.insert_header(header::SERVER, &SERVER_NAME[..]) diff --git a/pingora-proxy/src/proxy_trait.rs b/pingora-proxy/src/proxy_trait.rs index 3049c1d..042dbd4 100644 --- a/pingora-proxy/src/proxy_trait.rs +++ b/pingora-proxy/src/proxy_trait.rs @@ -13,9 +13,7 @@ // limitations under the License. use super::*; -use pingora_cache::{ - key::HashBinary, CacheKey, CacheMeta, NoCacheReason, RespCacheable, RespCacheable::*, -}; +use pingora_cache::{key::HashBinary, CacheKey, CacheMeta, RespCacheable, RespCacheable::*}; /// The interface to control the HTTP proxy /// diff --git a/pingora-proxy/tests/test_upstream.rs b/pingora-proxy/tests/test_upstream.rs index 5149d8f..b8e5a49 100644 --- a/pingora-proxy/tests/test_upstream.rs +++ b/pingora-proxy/tests/test_upstream.rs @@ -135,7 +135,7 @@ async fn test_ws_server_ends_conn() { mod test_cache { use super::*; - use tokio::time::{sleep, Duration}; + use tokio::time::sleep; #[tokio::test] async fn test_basic_caching() { diff --git a/pingora-timeout/src/fast_timeout.rs b/pingora-timeout/src/fast_timeout.rs index d8f9c25..c3b251a 100644 --- a/pingora-timeout/src/fast_timeout.rs +++ b/pingora-timeout/src/fast_timeout.rs @@ -94,7 +94,6 @@ pub fn unpause() { #[cfg(test)] mod tests { use super::*; - use std::time::Duration; #[tokio::test] async fn test_timeout() { diff --git a/pingora-timeout/src/lib.rs b/pingora-timeout/src/lib.rs index f3a33dd..d52dcea 100644 --- a/pingora-timeout/src/lib.rs +++ b/pingora-timeout/src/lib.rs @@ -147,7 +147,6 @@ where #[cfg(test)] mod tests { use super::*; - use std::time::Duration; #[tokio::test] async fn test_timeout() { diff --git a/pingora-timeout/src/timer.rs b/pingora-timeout/src/timer.rs index 6e25c24..6916d7d 100644 --- a/pingora-timeout/src/timer.rs +++ b/pingora-timeout/src/timer.rs @@ -248,7 +248,6 @@ impl TimerManager { #[cfg(test)] mod tests { use super::*; - use std::sync::Arc; #[test] fn test_round() { diff --git a/pingora/examples/server.rs b/pingora/examples/server.rs index be60b3a..b28b15e 100644 --- a/pingora/examples/server.rs +++ b/pingora/examples/server.rs @@ -25,7 +25,6 @@ use structopt::StructOpt; use tokio::time::interval; use std::time::Duration; -use std::vec::Vec; mod app; mod service; diff --git a/tinyufo/src/lib.rs b/tinyufo/src/lib.rs index 9a9e79c..001f4e3 100644 --- a/tinyufo/src/lib.rs +++ b/tinyufo/src/lib.rs @@ -329,9 +329,7 @@ impl<T: Clone + Send + Sync> FiFoQueues<T> { fn evict_one_from_main(&self, buckets: &Buckets<T>) -> Option<KV<T>> { loop { - let Some(to_evict) = self.main.pop() else { - return None; - }; + let to_evict = self.main.pop()?; let buckets = buckets.pin(); let maybe_bucket = buckets.get(&to_evict); if let Some(bucket) = maybe_bucket.as_ref() { |