From 40759b9c35ecb831d1d650d8a20a1205042286ad Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Fri, 10 Nov 2023 11:06:40 +0000 Subject: [PATCH] Remove unused crates from the project (#4179) Remove some unused crates and convert our redis tests to use the `fred` crate. That means we can remove our dev dependency on the `redis` crate. This yielded a 1.5% reduction in test build time on my laptop. --- **Checklist** Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review. - [ ] Changes are compatible[^1] - [ ] Documentation[^2] completed - [ ] Performance impact assessed and acceptable - Tests added and passing[^3] - [ ] Unit Tests - [ ] Integration Tests - [ ] Manual Tests **Exceptions** *Note any exceptions here* **Notes** [^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. --- Cargo.lock | 90 ++---------------------- apollo-router/Cargo.toml | 3 - apollo-router/src/http_server_factory.rs | 1 + apollo-router/tests/redis_test.rs | 47 ++++++------- 4 files changed, 29 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46dbc17375..a0bc01b13c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,7 +372,6 @@ dependencies = [ "proteus", "rand 0.8.5", "rand_core 0.6.4", - "redis", "regex", "reqwest", "rhai", @@ -388,10 +387,9 @@ dependencies = [ "serde_json_bytes", "serde_urlencoded", "serde_yaml", - "sha1 0.10.6", + "sha1", "sha2", "shellexpand", - "similar-asserts", "static_assertions", "strum_macros", "sys-info", @@ -1137,7 +1135,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sha1 0.10.6", + "sha1", "sync_wrapper", "tokio", "tokio-tungstenite", @@ -1314,17 +1312,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata 0.1.10", -] - [[package]] name = "bstr" version = "1.6.0" @@ -1582,20 +1569,6 @@ dependencies = [ "unreachable", ] -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "futures-core", - "memchr", - "pin-project-lite", - "tokio", - "tokio-util", -] - [[package]] name = "concolor" version = "0.1.1" @@ -2140,7 +2113,7 @@ dependencies = [ "sec1", "serde", "serde_bytes", - "sha1 0.10.6", + "sha1", "sha2", "signature 1.6.4", "spki", @@ -3006,7 +2979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" dependencies = [ "aho-corasick", - "bstr 1.6.0", + "bstr", "fnv", "log", "regex", @@ -3039,7 +3012,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2ebc8013b4426d5b81a4364c419a95ed0b404af2b82e2457de52d9348f0e474" dependencies = [ - "combine 3.8.1", + "combine", "thiserror", ] @@ -3174,7 +3147,7 @@ dependencies = [ "http", "httpdate", "mime", - "sha1 0.10.6", + "sha1", ] [[package]] @@ -5240,26 +5213,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "redis" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "152f3863635cbb76b73bc247845781098302c6c9ad2060e1a9a7de56840346b6" -dependencies = [ - "async-trait", - "bytes", - "combine 4.6.6", - "futures-util", - "itoa", - "percent-encoding", - "pin-project-lite", - "ryu", - "sha1 0.6.1", - "tokio", - "tokio-util", - "url", -] - [[package]] name = "redis-protocol" version = "4.1.0" @@ -6065,15 +6018,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - [[package]] name = "sha1" version = "0.10.6" @@ -6085,12 +6029,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "sha2" version = "0.10.8" @@ -6160,20 +6098,6 @@ name = "similar" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" -dependencies = [ - "bstr 0.2.17", - "unicode-segmentation", -] - -[[package]] -name = "similar-asserts" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e041bb827d1bfca18f213411d51b665309f1afb37a04a5d1464530e13779fc0f" -dependencies = [ - "console 0.15.7", - "similar", -] [[package]] name = "simple_asn1" @@ -7204,7 +7128,7 @@ dependencies = [ "log", "rand 0.8.5", "rustls", - "sha1 0.10.6", + "sha1", "thiserror", "url", "utf-8", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 6902c65a97..8dcaf398bd 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -172,7 +172,6 @@ prost = "0.11.9" prost-types = "0.11.9" proteus = "0.5.0" rand = "0.8.5" -rand_core = "0.6.4" rhai = { version = "1.16.2", features = ["sync", "serde", "internals"] } regex = "1.10.2" reqwest = { version = "0.11.22", default-features = false, features = [ @@ -283,7 +282,6 @@ once_cell = "1.18.0" opentelemetry-stdout = { version = "0.1.0", features = ["trace"] } p256 = "0.12.0" rand_core = "0.6.4" -redis = { version = "0.21.7", features = ["tokio-comp"] } reqwest = { version = "0.11.22", default-features = false, features = [ "json", "stream", @@ -294,7 +292,6 @@ rhai = { version = "1.16.2", features = [ "internals", "testing-environ", ] } -similar-asserts = "1.5.0" tempfile = "3.8.0" test-log = { version = "0.2.13", default-features = false, features = [ "trace", diff --git a/apollo-router/src/http_server_factory.rs b/apollo-router/src/http_server_factory.rs index 7ff866d987..c66c9da0f0 100644 --- a/apollo-router/src/http_server_factory.rs +++ b/apollo-router/src/http_server_factory.rs @@ -102,6 +102,7 @@ impl HttpServerHandle { } pub(crate) async fn shutdown(mut self) -> Result<(), ApolloRouterError> { + #[cfg(unix)] let listen_addresses = std::mem::take(&mut self.listen_addresses); let (_main_listener, _extra_listener) = self.wait_for_servers().await?; diff --git a/apollo-router/tests/redis_test.rs b/apollo-router/tests/redis_test.rs index 0802d35d29..ccb4434093 100644 --- a/apollo-router/tests/redis_test.rs +++ b/apollo-router/tests/redis_test.rs @@ -3,10 +3,9 @@ mod test { use apollo_router::services::execution::QueryPlan; use apollo_router::services::router; use apollo_router::services::supergraph; + use fred::prelude::*; use futures::StreamExt; use http::Method; - use redis::AsyncCommands; - use redis::Client; use serde::Deserialize; use serde::Serialize; use serde_json::json; @@ -15,14 +14,12 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn query_planner() -> Result<(), BoxError> { - let client = Client::open("redis://127.0.0.1:6379").expect("opening ClusterClient"); - let mut connection = client - .get_async_connection() - .await - .expect("got redis connection"); + let config = RedisConfig::from_url("redis://127.0.0.1:6379")?; + let client = RedisClient::new(config, None, None); + let connection_task = client.connect(); + client.wait_for_connect().await?; - connection - .del::<&'static str, ()>("plan.5abb5fecf7df056396fb90fdf38d430b8c1fec55ec132fde878161608af18b76.4c45433039407593557f8a982dafd316a66ec03f0e1ed5fa1b7ef8060d76e8ec.3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112.4f918cb09d5956bea87fe8addb4db3bd16de2cdf935e899cf252cac5528090e4").await.unwrap(); + client.del::("plan.5abb5fecf7df056396fb90fdf38d430b8c1fec55ec132fde878161608af18b76.4c45433039407593557f8a982dafd316a66ec03f0e1ed5fa1b7ef8060d76e8ec.3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112.4f918cb09d5956bea87fe8addb4db3bd16de2cdf935e899cf252cac5528090e4").await.unwrap(); let supergraph = apollo_router::TestHarness::builder() .with_subgraph_network_requests() @@ -51,7 +48,7 @@ mod test { let _ = supergraph.oneshot(request).await?.next_response().await; - let s:String = connection + let s:String = client .get("plan.5abb5fecf7df056396fb90fdf38d430b8c1fec55ec132fde878161608af18b76.4c45433039407593557f8a982dafd316a66ec03f0e1ed5fa1b7ef8060d76e8ec.3973e022e93220f9212c18d0d0c543ae7c309e46640da93a4a0314de999f5112.4f918cb09d5956bea87fe8addb4db3bd16de2cdf935e899cf252cac5528090e4") .await .unwrap(); @@ -69,7 +66,9 @@ mod test { .get("root"); insta::assert_json_snapshot!(query_plan); - + client.quit().await?; + // calling quit ends the connection and event listener tasks + let _ = connection_task.await; Ok(()) } @@ -81,11 +80,10 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn apq() -> Result<(), BoxError> { - let client = Client::open("redis://127.0.0.1:6379").expect("opening ClusterClient"); - let mut connection = client - .get_async_connection() - .await - .expect("got redis connection"); + let config = RedisConfig::from_url("redis://127.0.0.1:6379")?; + let client = RedisClient::new(config, None, None); + let connection_task = client.connect(); + client.wait_for_connect().await?; let config = json!({ "apq": { @@ -111,8 +109,8 @@ mod test { let query_hash = "4c45433039407593557f8a982dafd316a66ec03f0e1ed5fa1b7ef8060d76e8ec"; - connection - .del::(format!("apq\x00{query_hash}")) + client + .del::(&format!("apq\x00{query_hash}")) .await .unwrap(); @@ -141,10 +139,7 @@ mod test { .unwrap()?; assert_eq!(res.errors.get(0).unwrap().message, "PersistedQueryNotFound"); - let r: Option = connection - .get(&format!("apq\x00{query_hash}")) - .await - .unwrap(); + let r: Option = client.get(&format!("apq\x00{query_hash}")).await.unwrap(); assert!(r.is_none()); // Now we register the query @@ -169,10 +164,7 @@ mod test { assert!(res.data.is_some()); assert!(res.errors.is_empty()); - let s: Option = connection - .get(&format!("apq\x00{query_hash}")) - .await - .unwrap(); + let s: Option = client.get(&format!("apq\x00{query_hash}")).await.unwrap(); insta::assert_display_snapshot!(s.unwrap()); // we start a new router with the same config @@ -204,6 +196,9 @@ mod test { assert!(res.data.is_some()); assert!(res.errors.is_empty()); + client.quit().await?; + // calling quit ends the connection and event listener tasks + let _ = connection_task.await; Ok(()) } }