Skip to content

Commit 1378695

Browse files
Remove #[test] attributes from doc tests (#4214)
## Motivation and Context This PR cleans up doc tests by removing `#[test]` attributes from code snippets to prevent them from being executed. We've observed logs indicating that some doc snippets have been running for over 60 seconds, even though they are annotated with `no_run`. In addition, this PR also removes duplicated example snippets that previously took up a lot of space. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Landon James <lnj@amazon.com>
1 parent b096900 commit 1378695

File tree

2 files changed

+29
-148
lines changed

2 files changed

+29
-148
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/InterceptorConfigCustomization.kt

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
99
import software.amazon.smithy.rust.codegen.client.smithy.configReexport
1010
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
1111
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
12+
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
1213
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1314
import software.amazon.smithy.rust.codegen.core.rustlang.writable
1415
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
@@ -21,6 +22,8 @@ class InterceptorConfigCustomization(codegenContext: ClientCodegenContext) : Con
2122
arrayOf(
2223
"Intercept" to configReexport(RuntimeType.intercept(runtimeConfig)),
2324
"SharedInterceptor" to configReexport(RuntimeType.sharedInterceptor(runtimeConfig)),
25+
// TODO(Http1x): Update this dependency to Http1x
26+
"Http" to CargoDependency.Http.toType(),
2427
)
2528

2629
override fun section(section: ServiceConfig) =
@@ -48,14 +51,14 @@ class InterceptorConfigCustomization(codegenContext: ClientCodegenContext) : Con
4851
///
4952
/// ## Examples
5053
/// ```no_run
51-
/// ## ##[cfg(test)]
52-
/// ## mod tests {
53-
/// ## ##[test]
5454
/// ## fn example() {
55-
/// use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
56-
/// use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
55+
/// use aws_smithy_runtime_api::box_error::BoxError;
56+
/// use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
57+
/// use aws_smithy_runtime_api::client::interceptors::Intercept;
58+
/// use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
5759
/// use aws_smithy_types::config_bag::ConfigBag;
5860
/// use $moduleUseName::config::Config;
61+
/// use #{Http}::uri::Uri;
5962
///
6063
/// fn base_url() -> String {
6164
/// // ...
@@ -65,14 +68,18 @@ class InterceptorConfigCustomization(codegenContext: ClientCodegenContext) : Con
6568
/// ##[derive(Debug)]
6669
/// pub struct UriModifierInterceptor;
6770
/// impl Intercept for UriModifierInterceptor {
71+
/// fn name(&self) -> &'static str {
72+
/// "UriModifierInterceptor"
73+
/// }
6874
/// fn modify_before_signing(
6975
/// &self,
70-
/// context: &mut InterceptorContext<BeforeTransmit>,
76+
/// context: &mut BeforeTransmitInterceptorContextMut<'_>,
77+
/// _runtime_components: &RuntimeComponents,
7178
/// _cfg: &mut ConfigBag,
72-
/// ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
79+
/// ) -> Result<(), BoxError> {
7380
/// let request = context.request_mut();
74-
/// let uri = format!("{}{}", base_url(), request.uri().path());
75-
/// *request.uri_mut() = uri.parse()?;
81+
/// let uri = format!("{}{}", base_url(), request.uri());
82+
/// *request.uri_mut() = uri.parse::<Uri>()?.into();
7683
///
7784
/// Ok(())
7885
/// }
@@ -82,60 +89,13 @@ class InterceptorConfigCustomization(codegenContext: ClientCodegenContext) : Con
8289
/// .interceptor(UriModifierInterceptor)
8390
/// .build();
8491
/// ## }
85-
/// ## }
8692
/// ```
8793
pub fn interceptor(mut self, interceptor: impl #{Intercept} + 'static) -> Self {
8894
self.push_interceptor(#{SharedInterceptor}::new(interceptor));
8995
self
9096
}
9197
92-
/// Add a [`SharedInterceptor`](#{SharedInterceptor}) that runs at specific stages of the request execution pipeline.
93-
///
94-
/// Interceptors targeted at a certain stage are executed according to the pre-defined priority.
95-
/// The SDK provides a default set of interceptors. An interceptor configured by this method
96-
/// will run after those default interceptors.
97-
///
98-
/// ## Examples
99-
/// ```no_run
100-
/// ## ##[cfg(test)]
101-
/// ## mod tests {
102-
/// ## ##[test]
103-
/// ## fn example() {
104-
/// use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
105-
/// use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext, SharedInterceptor};
106-
/// use aws_smithy_types::config_bag::ConfigBag;
107-
/// use $moduleUseName::config::{Builder, Config};
108-
///
109-
/// fn base_url() -> String {
110-
/// // ...
111-
/// ## String::new()
112-
/// }
113-
///
114-
/// fn modify_request_uri(builder: &mut Builder) {
115-
/// ##[derive(Debug)]
116-
/// pub struct UriModifierInterceptor;
117-
/// impl Intercept for UriModifierInterceptor {
118-
/// fn modify_before_signing(
119-
/// &self,
120-
/// context: &mut InterceptorContext<BeforeTransmit>,
121-
/// _cfg: &mut ConfigBag,
122-
/// ) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
123-
/// let request = context.request_mut();
124-
/// let uri = format!("{}{}", base_url(), request.uri().path());
125-
/// *request.uri_mut() = uri.parse()?;
126-
///
127-
/// Ok(())
128-
/// }
129-
/// }
130-
/// builder.push_interceptor(SharedInterceptor::new(UriModifierInterceptor));
131-
/// }
132-
///
133-
/// let mut builder = Config::builder();
134-
/// modify_request_uri(&mut builder);
135-
/// let config = builder.build();
136-
/// ## }
137-
/// ## }
138-
/// ```
98+
/// Like [`Self::interceptor`], but takes a [`SharedInterceptor`](#{SharedInterceptor}).
13999
pub fn push_interceptor(&mut self, interceptor: #{SharedInterceptor}) -> &mut Self {
140100
self.runtime_components.push_interceptor(interceptor);
141101
self

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/RetryClassifierConfigCustomization.kt

Lines changed: 12 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ class RetryClassifierConfigCustomization(codegenContext: ClientCodegenContext) :
5656
///
5757
/// ## Examples
5858
/// ```no_run
59-
/// ## ##[cfg(test)]
60-
/// ## mod tests {
61-
/// ## ##[test]
6259
/// ## fn example() {
6360
/// use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
6461
/// use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
@@ -69,17 +66,26 @@ class RetryClassifierConfigCustomization(codegenContext: ClientCodegenContext) :
6966
/// use aws_smithy_types::retry::ErrorKind;
7067
/// use std::error::Error as StdError;
7168
/// use std::marker::PhantomData;
69+
/// use std::fmt;
7270
/// use $moduleUseName::config::Config;
71+
/// ## ##[derive(Debug)]
7372
/// ## struct SomeOperationError {}
73+
/// ## impl StdError for SomeOperationError {}
74+
/// ## impl fmt::Display for SomeOperationError {
75+
/// ## fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { todo!() }
76+
/// ## }
77+
/// ## impl ProvideErrorMetadata for SomeOperationError {
78+
/// ## fn meta(&self) -> &$moduleUseName::error::ErrorMetadata { todo!() }
79+
/// ## }
7480
///
75-
/// const RETRYABLE_ERROR_CODES: &[&str] = [
81+
/// const RETRYABLE_ERROR_CODES: &[&str] = &[
7682
/// // List error codes to be retried here...
7783
/// ];
7884
///
7985
/// // When classifying at an operation's error type, classifiers require a generic parameter.
8086
/// // When classifying the HTTP response alone, no generic is needed.
8187
/// ##[derive(Debug, Default)]
82-
/// pub struct ErrorCodeClassifier<E> {
88+
/// pub struct ExampleErrorCodeClassifier<E> {
8389
/// _inner: PhantomData<E>,
8490
/// }
8591
///
@@ -129,98 +135,13 @@ class RetryClassifierConfigCustomization(codegenContext: ClientCodegenContext) :
129135
/// .retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
130136
/// .build();
131137
/// ## }
132-
/// ## }
133138
/// ```
134139
pub fn retry_classifier(mut self, retry_classifier: impl #{ClassifyRetry} + 'static) -> Self {
135140
self.push_retry_classifier(#{SharedRetryClassifier}::new(retry_classifier));
136141
self
137142
}
138143
139-
/// Add a [`SharedRetryClassifier`](#{SharedRetryClassifier}) that will be used by the
140-
/// [`RetryStrategy`](#{RetryStrategy}) to determine what responses should be retried.
141-
///
142-
/// A retry classifier configured by this method will run according to its priority.
143-
///
144-
/// ## Examples
145-
/// ```no_run
146-
/// ## ##[cfg(test)]
147-
/// ## mod tests {
148-
/// ## ##[test]
149-
/// ## fn example() {
150-
/// use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
151-
/// use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
152-
/// use aws_smithy_runtime_api::client::retries::classifiers::{
153-
/// ClassifyRetry, RetryAction, RetryClassifierPriority,
154-
/// };
155-
/// use aws_smithy_types::error::metadata::ProvideErrorMetadata;
156-
/// use aws_smithy_types::retry::ErrorKind;
157-
/// use std::error::Error as StdError;
158-
/// use std::marker::PhantomData;
159-
/// use $moduleUseName::config::{Builder, Config};
160-
/// ## struct SomeOperationError {}
161-
///
162-
/// const RETRYABLE_ERROR_CODES: &[&str] = [
163-
/// // List error codes to be retried here...
164-
/// ];
165-
/// fn set_example_error_code_classifier(builder: &mut Builder) {
166-
/// // When classifying at an operation's error type, classifiers require a generic parameter.
167-
/// // When classifying the HTTP response alone, no generic is needed.
168-
/// ##[derive(Debug, Default)]
169-
/// pub struct ExampleErrorCodeClassifier<E> {
170-
/// _inner: PhantomData<E>,
171-
/// }
172-
///
173-
/// impl<E> ExampleErrorCodeClassifier<E> {
174-
/// pub fn new() -> Self {
175-
/// Self {
176-
/// _inner: PhantomData,
177-
/// }
178-
/// }
179-
/// }
180-
///
181-
/// impl<E> ClassifyRetry for ExampleErrorCodeClassifier<E>
182-
/// where
183-
/// // Adding a trait bound for ProvideErrorMetadata allows us to inspect the error code.
184-
/// E: StdError + ProvideErrorMetadata + Send + Sync + 'static,
185-
/// {
186-
/// fn classify_retry(&self, ctx: &InterceptorContext) -> RetryAction {
187-
/// // Check for a result
188-
/// let output_or_error = ctx.output_or_error();
189-
/// // Check for an error
190-
/// let error = match output_or_error {
191-
/// Some(Ok(_)) | None => return RetryAction::NoActionIndicated,
192-
/// Some(Err(err)) => err,
193-
/// };
194-
///
195-
/// // Downcast the generic error and extract the code
196-
/// let error_code = OrchestratorError::as_operation_error(error)
197-
/// .and_then(|err| err.downcast_ref::<E>())
198-
/// .and_then(|err| err.code());
199-
///
200-
/// // If this error's code is in our list, return an action that tells the RetryStrategy to retry this request.
201-
/// if let Some(error_code) = error_code {
202-
/// if RETRYABLE_ERROR_CODES.contains(&error_code) {
203-
/// return RetryAction::transient_error();
204-
/// }
205-
/// }
206-
///
207-
/// // Otherwise, return that no action is indicated i.e. that this classifier doesn't require a retry.
208-
/// // Another classifier may still classify this response as retryable.
209-
/// RetryAction::NoActionIndicated
210-
/// }
211-
///
212-
/// fn name(&self) -> &'static str { "Example Error Code Classifier" }
213-
/// }
214-
///
215-
/// builder.push_retry_classifier(ExampleErrorCodeClassifier::<SomeOperationError>::new())
216-
/// }
217-
///
218-
/// let mut builder = Config::builder();
219-
/// set_example_error_code_classifier(&mut builder);
220-
/// let config = builder.build();
221-
/// ## }
222-
/// ## }
223-
/// ```
144+
/// Like [`Self::retry_classifier`], but takes a [`SharedRetryClassifier`](#{SharedRetryClassifier}).
224145
pub fn push_retry_classifier(&mut self, retry_classifier: #{SharedRetryClassifier}) -> &mut Self {
225146
self.runtime_components.push_retry_classifier(retry_classifier);
226147
self

0 commit comments

Comments
 (0)