diff --git a/contrib/codegen/src/database.rs b/contrib/codegen/src/database.rs index aa011e2e..366ca5e1 100644 --- a/contrib/codegen/src/database.rs +++ b/contrib/codegen/src/database.rs @@ -93,8 +93,8 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result impl ::rocket::fairing::Fairing { use #databases::Poolable; - ::rocket::fairing::AdHoc::on_attach(#fairing_name, |mut rocket| { - let pool = #databases::database_config(#name, rocket.inspect().config()) + ::rocket::fairing::AdHoc::on_attach(#fairing_name, |mut rocket| async { + let pool = #databases::database_config(#name, rocket.inspect().await.config()) .map(<#conn_type>::pool); match pool { diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs index b4ba4260..a961fb06 100644 --- a/contrib/lib/src/databases.rs +++ b/contrib/lib/src/databases.rs @@ -548,9 +548,9 @@ pub enum ConfigError { /// # .extra("databases", databases) /// # .expect("custom config okay"); /// # -/// # rocket::custom(config).attach(AdHoc::on_attach("Testing", |mut rocket| { +/// # rocket::custom(config).attach(AdHoc::on_attach("Testing", |mut rocket| async { /// # { -/// let manifest = rocket.inspect(); +/// let manifest = rocket.inspect().await; /// let config = database_config("my_db", manifest.config()).unwrap(); /// assert_eq!(config.url, "db/db.sqlite"); /// assert_eq!(config.pool_size, 25); diff --git a/contrib/lib/src/templates/fairing.rs b/contrib/lib/src/templates/fairing.rs index e2a517a9..fde7274c 100644 --- a/contrib/lib/src/templates/fairing.rs +++ b/contrib/lib/src/templates/fairing.rs @@ -151,8 +151,8 @@ impl Fairing for TemplateFairing { /// The user's callback, if any was supplied, is called to customize the /// template engines. In debug mode, the `ContextManager::new` method /// initializes a directory watcher for auto-reloading of templates. - fn on_attach(&self, mut rocket: Rocket) -> Result { - let manifest = rocket.inspect(); + async fn on_attach(&self, mut rocket: Rocket) -> Result { + let manifest = rocket.inspect().await; let config = manifest.config(); let mut template_root = config.root_relative(DEFAULT_TEMPLATE_DIR); match config.get_str("template_dir") { diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs index b5ca1a2d..f428bd9e 100644 --- a/contrib/lib/src/templates/mod.rs +++ b/contrib/lib/src/templates/mod.rs @@ -331,8 +331,9 @@ impl Template { /// use rocket::local::Client; /// /// fn main() { + /// # rocket::async_test(async { /// let rocket = rocket::ignite().attach(Template::fairing()); - /// let client = Client::new(rocket).expect("valid rocket"); + /// let client = Client::new(rocket).await.expect("valid rocket"); /// /// // Create a `context`. Here, just an empty `HashMap`. /// let mut context = HashMap::new(); @@ -340,6 +341,7 @@ impl Template { /// # context.insert("test", "test"); /// # #[allow(unused_variables)] /// let template = Template::show(client.manifest(), "index", context); + /// # }); /// } /// ``` #[inline] diff --git a/contrib/lib/tests/databases.rs b/contrib/lib/tests/databases.rs index 60cc16c3..62d4df3b 100644 --- a/contrib/lib/tests/databases.rs +++ b/contrib/lib/tests/databases.rs @@ -22,8 +22,8 @@ mod rusqlite_integration_test { #[database("test_db")] struct SqliteDb(pub rusqlite::Connection); - #[test] - fn deref_mut_impl_present() { + #[rocket::async_test] + async fn deref_mut_impl_present() { let mut test_db: BTreeMap = BTreeMap::new(); let mut test_db_opts: BTreeMap = BTreeMap::new(); test_db_opts.insert("url".into(), Value::String(":memory:".into())); @@ -34,7 +34,7 @@ mod rusqlite_integration_test { .unwrap(); let mut rocket = rocket::custom(config).attach(SqliteDb::fairing()); - let mut conn = SqliteDb::get_one(rocket.inspect()).expect("unable to get connection"); + let mut conn = SqliteDb::get_one(rocket.inspect().await).expect("unable to get connection"); // Rusqlite's `transaction()` method takes `&mut self`; this tests the // presence of a `DerefMut` trait on the generated connection type. @@ -43,8 +43,8 @@ mod rusqlite_integration_test { tx.commit().expect("committed transaction"); } - #[test] - fn deref_impl_present() { + #[rocket::async_test] + async fn deref_impl_present() { let mut test_db: BTreeMap = BTreeMap::new(); let mut test_db_opts: BTreeMap = BTreeMap::new(); test_db_opts.insert("url".into(), Value::String(":memory:".into())); @@ -55,7 +55,7 @@ mod rusqlite_integration_test { .unwrap(); let mut rocket = rocket::custom(config).attach(SqliteDb::fairing()); - let conn = SqliteDb::get_one(rocket.inspect()).expect("unable to get connection"); + let conn = SqliteDb::get_one(rocket.inspect().await).expect("unable to get connection"); let _: i32 = conn.query_row("SELECT 1", &[] as &[&dyn ToSql], |row| row.get(0)).expect("get row"); } } diff --git a/contrib/lib/tests/helmet.rs b/contrib/lib/tests/helmet.rs index e627c821..4182bc27 100644 --- a/contrib/lib/tests/helmet.rs +++ b/contrib/lib/tests/helmet.rs @@ -34,7 +34,7 @@ mod helmet_tests { macro_rules! dispatch { ($helmet:expr, $closure:expr) => {{ let rocket = rocket::ignite().mount("/", routes![hello]).attach($helmet); - let client = Client::new(rocket).unwrap(); + let client = Client::new(rocket).await.unwrap(); let response = client.get("/").dispatch().await; assert_eq!(response.status(), Status::Ok); $closure(response) diff --git a/contrib/lib/tests/static_files.rs b/contrib/lib/tests/static_files.rs index 7a13e609..b241341c 100644 --- a/contrib/lib/tests/static_files.rs +++ b/contrib/lib/tests/static_files.rs @@ -73,7 +73,7 @@ mod static_tests { #[rocket::async_test] async fn test_static_no_index() { - let client = Client::new(rocket()).expect("valid rocket"); + let client = Client::new(rocket()).await.expect("valid rocket"); assert_all(&client, "no_index", REGULAR_FILES, true).await; assert_all(&client, "no_index", HIDDEN_FILES, false).await; assert_all(&client, "no_index", INDEXED_DIRECTORIES, false).await; @@ -81,7 +81,7 @@ mod static_tests { #[rocket::async_test] async fn test_static_hidden() { - let client = Client::new(rocket()).expect("valid rocket"); + let client = Client::new(rocket()).await.expect("valid rocket"); assert_all(&client, "dots", REGULAR_FILES, true).await; assert_all(&client, "dots", HIDDEN_FILES, true).await; assert_all(&client, "dots", INDEXED_DIRECTORIES, false).await; @@ -89,7 +89,7 @@ mod static_tests { #[rocket::async_test] async fn test_static_index() { - let client = Client::new(rocket()).expect("valid rocket"); + let client = Client::new(rocket()).await.expect("valid rocket"); assert_all(&client, "index", REGULAR_FILES, true).await; assert_all(&client, "index", HIDDEN_FILES, false).await; assert_all(&client, "index", INDEXED_DIRECTORIES, true).await; @@ -101,7 +101,7 @@ mod static_tests { #[rocket::async_test] async fn test_static_all() { - let client = Client::new(rocket()).expect("valid rocket"); + let client = Client::new(rocket()).await.expect("valid rocket"); assert_all(&client, "both", REGULAR_FILES, true).await; assert_all(&client, "both", HIDDEN_FILES, true).await; assert_all(&client, "both", INDEXED_DIRECTORIES, true).await; @@ -133,7 +133,7 @@ mod static_tests { fn catch_two(a: &RawStr, b: &RawStr) -> String { format!("{}/{}", a, b) } let rocket = rocket().mount("/default", routes![catch_one, catch_two]); - let client = Client::new(rocket).expect("valid rocket"); + let client = Client::new(rocket).await.expect("valid rocket"); let mut response = client.get("/default/ireallydontexist").dispatch().await; assert_eq!(response.status(), Status::Ok); diff --git a/contrib/lib/tests/templates.rs b/contrib/lib/tests/templates.rs index 680db191..6d7e0361 100644 --- a/contrib/lib/tests/templates.rs +++ b/contrib/lib/tests/templates.rs @@ -49,10 +49,10 @@ mod templates_tests { const ESCAPED_EXPECTED: &'static str = "\nh_start\ntitle: _test_\nh_end\n\n\n<script />\n\nfoot\n"; - #[test] - fn test_tera_templates() { + #[rocket::async_test] + async fn test_tera_templates() { let mut rocket = rocket(); - let manifest = rocket.inspect(); + let manifest = rocket.inspect().await; let mut map = HashMap::new(); map.insert("title", "_test_"); map.insert("content", "