@@ -15,6 +15,7 @@ use crate::{
1515use crate :: schema:: users;
1616use chrono:: { Duration , Utc } ;
1717use diesel:: prelude:: * ;
18+ use diesel_async:: RunQueryDsl ;
1819use http:: StatusCode ;
1920use insta:: assert_snapshot;
2021use serde_json:: json;
@@ -128,7 +129,7 @@ impl MockAnonymousUser {
128129#[ tokio:: test( flavor = "multi_thread" ) ]
129130async fn new_crate_owner ( ) {
130131 let ( app, _, _, token) = TestApp :: full ( ) . with_token ( ) . await ;
131- let mut conn = app. db_conn ( ) ;
132+ let mut conn = app. async_db_conn ( ) . await ;
132133
133134 // Create a crate under one user
134135 let crate_to_publish = PublishBuilder :: new ( "foo_owner" , "1.0.0" ) ;
@@ -141,7 +142,7 @@ async fn new_crate_owner() {
141142 assert_snapshot ! ( app. emails_snapshot( ) . await ) ;
142143
143144 // accept invitation for user to be added as owner
144- let krate: Crate = Crate :: by_name ( "foo_owner" ) . first ( & mut conn) . unwrap ( ) ;
145+ let krate: Crate = Crate :: by_name ( "foo_owner" ) . first ( & mut conn) . await . unwrap ( ) ;
145146 user2
146147 . accept_ownership_invitation ( "foo_owner" , krate. id )
147148 . await ;
@@ -465,7 +466,7 @@ async fn invitations_list_does_not_include_expired_invites_v1() {
465466 . good ( ) ;
466467
467468 // Simulate one of the invitations expiring
468- expire_invitation ( & app, krate1. id ) ;
469+ expire_invitation ( & app, krate1. id ) . await ;
469470
470471 let invitations = user. list_invitations ( ) . await ;
471472 assert_eq ! (
@@ -588,10 +589,10 @@ async fn test_accept_invitation_by_mail() {
588589
589590/// Hacky way to simulate the expiration of an ownership invitation. Instead of letting a month
590591/// pass, the creation date of the invite is moved back a month.
591- pub fn expire_invitation ( app : & TestApp , crate_id : i32 ) {
592+ pub async fn expire_invitation ( app : & TestApp , crate_id : i32 ) {
592593 use crate :: schema:: crate_owner_invitations;
593594
594- let mut conn = app. db_conn ( ) ;
595+ let mut conn = app. async_db_conn ( ) . await ;
595596
596597 let expiration = app. as_inner ( ) . config . ownership_invitations_expiration_days as i64 ;
597598 let created_at = ( Utc :: now ( ) - Duration :: days ( expiration) ) . naive_utc ( ) ;
@@ -600,6 +601,7 @@ pub fn expire_invitation(app: &TestApp, crate_id: i32) {
600601 . set ( crate_owner_invitations:: created_at. eq ( created_at) )
601602 . filter ( crate_owner_invitations:: crate_id. eq ( crate_id) )
602603 . execute ( & mut conn)
604+ . await
603605 . expect ( "failed to override the creation time" ) ;
604606}
605607
@@ -619,7 +621,7 @@ async fn test_accept_expired_invitation() {
619621 . good ( ) ;
620622
621623 // Manually update the creation time to simulate the invite expiring
622- expire_invitation ( & app, krate. id ) ;
624+ expire_invitation ( & app, krate. id ) . await ;
623625
624626 // New owner tries to accept the invitation but it fails
625627 let resp = invited_user
@@ -659,7 +661,7 @@ async fn test_decline_expired_invitation() {
659661 . good ( ) ;
660662
661663 // Manually update the creation time to simulate the invite expiring
662- expire_invitation ( & app, krate. id ) ;
664+ expire_invitation ( & app, krate. id ) . await ;
663665
664666 // New owner declines the invitation and it succeeds, even though the invitation expired.
665667 invited_user
@@ -687,7 +689,7 @@ async fn test_accept_expired_invitation_by_mail() {
687689 . good ( ) ;
688690
689691 // Manually update the creation time to simulate the invite expiring
690- expire_invitation ( & app, krate. id ) ;
692+ expire_invitation ( & app, krate. id ) . await ;
691693
692694 // Retrieve the ownership invitation
693695 let invite_token = extract_token_from_invite_email ( & app. emails ( ) . await ) ;
@@ -719,7 +721,7 @@ async fn inactive_users_dont_get_invitations() {
719721 use crate :: models:: NewUser ;
720722
721723 let ( app, _, owner, owner_token) = TestApp :: init ( ) . with_token ( ) . await ;
722- let mut conn = app. db_conn ( ) ;
724+ let mut conn = app. async_db_conn ( ) . await ;
723725 let owner = owner. as_model ( ) ;
724726
725727 // An inactive user with gh_id -1 and an active user with a non-negative gh_id both exist
@@ -737,8 +739,10 @@ async fn inactive_users_dont_get_invitations() {
737739 diesel:: insert_into ( users:: table)
738740 . values ( user)
739741 . execute ( & mut conn)
742+ . await
740743 . unwrap ( ) ;
741744
745+ let mut conn = app. db_conn ( ) ;
742746 CrateBuilder :: new ( krate_name, owner. id ) . expect_build ( & mut conn) ;
743747
744748 let invited_user = app. db_new_user ( invited_gh_login) . await ;
0 commit comments