Update to latest version of actix-web, tracing-bunyan-formatter and tracing-subscriber. Use tokio macros instead of actix-web's macros.

This commit is contained in:
Luca Palmieri 2021-12-26 16:28:03 +01:00
parent b7b4270fca
commit 6ab9d60410
5 changed files with 276 additions and 360 deletions

605
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,8 @@ path = "src/main.rs"
name = "zero2prod"
[dependencies]
actix-web = "=4.0.0-beta.9"
actix-http = "=3.0.0-beta.10"
actix-web = "=4.0.0-beta.15"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = "1.0.115"
config = { version = "0.10.1", default-features = false, features = ["yaml"] }
sqlx = { version = "0.5.5", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] }
@ -23,13 +23,13 @@ chrono = "0.4.15"
log = "0.4"
tracing = "0.1.19"
tracing-futures = "0.2.4"
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.1.6"
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3.1"
tracing-log = "0.1.1"
serde-aux = "1.0.1"
unicode-segmentation = "1.7.1"
tracing-actix-web = "0.5.0-beta.6"
validator = "0.12.0"
tracing-actix-web = "0.4.0-beta.12"
[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }
@ -37,6 +37,4 @@ claim = "0.4.0"
quickcheck = "0.9.2"
quickcheck_macros = "0.9.1"
fake = "~2.3.0"
actix-rt = "2"
tokio = "1"
once_cell = "1.7.2"

View file

@ -4,7 +4,7 @@ use zero2prod::configuration::get_configuration;
use zero2prod::startup::run;
use zero2prod::telemetry::{get_subscriber, init_subscriber};
#[actix_web::main]
#[tokio::main]
async fn main() -> std::io::Result<()> {
let subscriber = get_subscriber("zero2prod".into(), "info".into(), std::io::stdout);
init_subscriber(subscriber);

View file

@ -11,11 +11,14 @@ use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
///
/// We are using `impl Subscriber` as return type to avoid having to spell out the actual
/// type of the returned subscriber, which is indeed quite complex.
pub fn get_subscriber(
pub fn get_subscriber<Sink>(
name: String,
env_filter: String,
sink: impl MakeWriter + Send + Sync + 'static,
) -> impl Subscriber + Sync + Send {
sink: Sink,
) -> impl Subscriber + Sync + Send
where
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
{
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
let formatting_layer = BunyanFormattingLayer::new(name, sink);

View file

@ -68,7 +68,7 @@ pub async fn configure_database(config: &DatabaseSettings) -> PgPool {
connection_pool
}
#[actix_rt::test]
#[tokio::test]
async fn health_check_works() {
// Arrange
let app = spawn_app().await;
@ -87,7 +87,7 @@ async fn health_check_works() {
assert_eq!(Some(0), response.content_length());
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_a_200_for_valid_form_data() {
// Arrange
let app = spawn_app().await;
@ -115,7 +115,7 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
assert_eq!(saved.name, "le guin");
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_a_400_when_data_is_missing() {
// Arrange
let app = spawn_app().await;
@ -147,7 +147,7 @@ async fn subscribe_returns_a_400_when_data_is_missing() {
}
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_a_400_when_fields_are_present_but_invalid() {
// Arrange
let app = spawn_app().await;