mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-11-15 21:21:00 +00:00
Keep test suite fast by tuning timeout for tests.
This commit is contained in:
parent
ed0f2fb593
commit
50a5814eb2
4 changed files with 22 additions and 7 deletions
|
@ -12,3 +12,4 @@ email_client:
|
||||||
base_url: "localhost"
|
base_url: "localhost"
|
||||||
sender_email: "test@gmail.com"
|
sender_email: "test@gmail.com"
|
||||||
authorization_token: "my-secret-token"
|
authorization_token: "my-secret-token"
|
||||||
|
timeout_milliseconds: 10000
|
|
@ -54,12 +54,17 @@ pub struct EmailClientSettings {
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub sender_email: String,
|
pub sender_email: String,
|
||||||
pub authorization_token: String,
|
pub authorization_token: String,
|
||||||
|
pub timeout_milliseconds: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmailClientSettings {
|
impl EmailClientSettings {
|
||||||
pub fn sender(&self) -> Result<SubscriberEmail, String> {
|
pub fn sender(&self) -> Result<SubscriberEmail, String> {
|
||||||
SubscriberEmail::parse(self.sender_email.clone())
|
SubscriberEmail::parse(self.sender_email.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn timeout(&self) -> std::time::Duration {
|
||||||
|
std::time::Duration::from_millis(self.timeout_milliseconds)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
||||||
|
|
|
@ -9,11 +9,13 @@ pub struct EmailClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmailClient {
|
impl EmailClient {
|
||||||
pub fn new(base_url: String, sender: SubscriberEmail, authorization_token: String) -> Self {
|
pub fn new(
|
||||||
let http_client = Client::builder()
|
base_url: String,
|
||||||
.timeout(std::time::Duration::from_secs(10))
|
sender: SubscriberEmail,
|
||||||
.build()
|
authorization_token: String,
|
||||||
.unwrap();
|
timeout: std::time::Duration,
|
||||||
|
) -> Self {
|
||||||
|
let http_client = Client::builder().timeout(timeout).build().unwrap();
|
||||||
Self {
|
Self {
|
||||||
http_client,
|
http_client,
|
||||||
base_url,
|
base_url,
|
||||||
|
@ -103,7 +105,12 @@ mod tests {
|
||||||
|
|
||||||
/// Get a test instance of `EmailClient`.
|
/// Get a test instance of `EmailClient`.
|
||||||
fn email_client(base_url: String) -> EmailClient {
|
fn email_client(base_url: String) -> EmailClient {
|
||||||
EmailClient::new(base_url, email(), Faker.fake())
|
EmailClient::new(
|
||||||
|
base_url,
|
||||||
|
email(),
|
||||||
|
Faker.fake(),
|
||||||
|
std::time::Duration::from_millis(200),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -24,10 +24,12 @@ impl Application {
|
||||||
.email_client
|
.email_client
|
||||||
.sender()
|
.sender()
|
||||||
.expect("Invalid sender email address.");
|
.expect("Invalid sender email address.");
|
||||||
|
let timeout = configuration.email_client.timeout();
|
||||||
let email_client = EmailClient::new(
|
let email_client = EmailClient::new(
|
||||||
configuration.email_client.base_url,
|
configuration.email_client.base_url,
|
||||||
sender_email,
|
sender_email,
|
||||||
configuration.email_client.authorization_token,
|
configuration.email_client.authorization_token,
|
||||||
|
timeout,
|
||||||
);
|
);
|
||||||
|
|
||||||
let address = format!(
|
let address = format!(
|
||||||
|
|
Loading…
Reference in a new issue