From 93782fba10bdce0a911d3a2101c07e8360dc6dc6 Mon Sep 17 00:00:00 2001 From: Fedir Panasenko Date: Sat, 20 Jul 2024 23:35:34 -0400 Subject: [PATCH 1/4] Add test for adaptors losing Requester trait bounds issue --- crates/teloxide-core/src/adaptors.rs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/teloxide-core/src/adaptors.rs b/crates/teloxide-core/src/adaptors.rs index 070c1a24..f6d2ffb8 100644 --- a/crates/teloxide-core/src/adaptors.rs +++ b/crates/teloxide-core/src/adaptors.rs @@ -45,3 +45,37 @@ pub use throttle::Throttle; pub use trace::Trace; pub use parse_mode::DefaultParseMode; + +#[cfg(all( + test, + feature = "cache_me", + feature = "throttle", + feature = "trace_adaptor", + feature = "erased" +))] +// Tests composition of all possible adaptors. The goal of this test is to +// catch situations when wrapped by adaptor bot loses Requester trait bounds. +// The problem occurs because Throttle adaptor holds queue of requests, thus +// introducing requirement for all requests to also implement Clone. +mod composition_test { + use crate::{requests::RequesterExt, types::ParseMode, Bot}; + use throttle::Limits; + use trace::Settings; + + use super::*; + + // Has to be async test due to Throttle adaptor requirements + #[tokio::test] + async fn composition() { + let bot = Bot::new("TOKEN"); + + // Erased adaptor validates Requester trait bounds, so this should fail to + // compile whenever issue occurs. + let _ = bot + .throttle(Limits::default()) + .cache_me() + .trace(Settings::empty()) + .parse_mode(ParseMode::MarkdownV2) + .erase(); + } +} From 00c6974788fa87671892fe9581871dde6ae39372 Mon Sep 17 00:00:00 2001 From: Fedir Panasenko Date: Sat, 20 Jul 2024 23:37:22 -0400 Subject: [PATCH 2/4] Fix Trace and Throttle adaptors to implement Requester --- crates/teloxide-core/src/adaptors/throttle/request.rs | 1 + crates/teloxide-core/src/adaptors/trace.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/teloxide-core/src/adaptors/throttle/request.rs b/crates/teloxide-core/src/adaptors/throttle/request.rs index 47e7d451..26af4bd5 100644 --- a/crates/teloxide-core/src/adaptors/throttle/request.rs +++ b/crates/teloxide-core/src/adaptors/throttle/request.rs @@ -19,6 +19,7 @@ use crate::{ /// Request returned by [`Throttling`](crate::adaptors::Throttle) methods. #[must_use = "Requests are lazy and do nothing unless sent"] +#[derive(Clone)] pub struct ThrottlingRequest { pub(super) request: Arc, pub(super) chat_id: fn(&R::Payload) -> ChatIdHash, diff --git a/crates/teloxide-core/src/adaptors/trace.rs b/crates/teloxide-core/src/adaptors/trace.rs index bf4141bc..46882c6b 100644 --- a/crates/teloxide-core/src/adaptors/trace.rs +++ b/crates/teloxide-core/src/adaptors/trace.rs @@ -243,6 +243,7 @@ where } #[must_use = "Requests are lazy and do nothing unless sent"] +#[derive(Clone)] pub struct TraceRequest { inner: R, settings: Settings, From 72f7944e3880a89ff8716c44043e6a5a214de956 Mon Sep 17 00:00:00 2001 From: Fedir Panasenko Date: Sat, 20 Jul 2024 23:42:44 -0400 Subject: [PATCH 3/4] Fix formatting --- crates/teloxide-core/src/adaptors.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/teloxide-core/src/adaptors.rs b/crates/teloxide-core/src/adaptors.rs index f6d2ffb8..f150b829 100644 --- a/crates/teloxide-core/src/adaptors.rs +++ b/crates/teloxide-core/src/adaptors.rs @@ -53,10 +53,10 @@ pub use parse_mode::DefaultParseMode; feature = "trace_adaptor", feature = "erased" ))] -// Tests composition of all possible adaptors. The goal of this test is to +// Tests composition of all possible adaptors. The goal of this test is to // catch situations when wrapped by adaptor bot loses Requester trait bounds. -// The problem occurs because Throttle adaptor holds queue of requests, thus -// introducing requirement for all requests to also implement Clone. +// The problem occurs because Throttle adaptor holds queue of requests, thus +// introducing requirement for all requests to also implement Clone. mod composition_test { use crate::{requests::RequesterExt, types::ParseMode, Bot}; use throttle::Limits; @@ -69,7 +69,7 @@ mod composition_test { async fn composition() { let bot = Bot::new("TOKEN"); - // Erased adaptor validates Requester trait bounds, so this should fail to + // Erased adaptor validates Requester trait bounds, so this should fail to // compile whenever issue occurs. let _ = bot .throttle(Limits::default()) From 75f24fcd98eee2d8dffe3563432da65743899286 Mon Sep 17 00:00:00 2001 From: Fedir Panasenko Date: Mon, 5 Aug 2024 23:08:33 -0400 Subject: [PATCH 4/4] Remove adaptors test As per discussion, the usefulness of the test is dubious. --- crates/teloxide-core/src/adaptors.rs | 34 ---------------------------- 1 file changed, 34 deletions(-) diff --git a/crates/teloxide-core/src/adaptors.rs b/crates/teloxide-core/src/adaptors.rs index f150b829..070c1a24 100644 --- a/crates/teloxide-core/src/adaptors.rs +++ b/crates/teloxide-core/src/adaptors.rs @@ -45,37 +45,3 @@ pub use throttle::Throttle; pub use trace::Trace; pub use parse_mode::DefaultParseMode; - -#[cfg(all( - test, - feature = "cache_me", - feature = "throttle", - feature = "trace_adaptor", - feature = "erased" -))] -// Tests composition of all possible adaptors. The goal of this test is to -// catch situations when wrapped by adaptor bot loses Requester trait bounds. -// The problem occurs because Throttle adaptor holds queue of requests, thus -// introducing requirement for all requests to also implement Clone. -mod composition_test { - use crate::{requests::RequesterExt, types::ParseMode, Bot}; - use throttle::Limits; - use trace::Settings; - - use super::*; - - // Has to be async test due to Throttle adaptor requirements - #[tokio::test] - async fn composition() { - let bot = Bot::new("TOKEN"); - - // Erased adaptor validates Requester trait bounds, so this should fail to - // compile whenever issue occurs. - let _ = bot - .throttle(Limits::default()) - .cache_me() - .trace(Settings::empty()) - .parse_mode(ParseMode::MarkdownV2) - .erase(); - } -}