@@ -54,9 +54,14 @@ impl From<InstrumentationEvent<'_>> for Event {
5454}
5555
5656async fn setup_test_case ( ) -> ( Arc < Mutex < Vec < Event > > > , TestConnection ) {
57+ setup_test_case_with_connection ( connection_with_sean_and_tess_in_users_table ( ) . await )
58+ }
59+
60+ fn setup_test_case_with_connection (
61+ mut conn : TestConnection ,
62+ ) -> ( Arc < Mutex < Vec < Event > > > , TestConnection ) {
5763 let events = Arc :: new ( Mutex :: new ( Vec :: < Event > :: new ( ) ) ) ;
5864 let events_to_check = events. clone ( ) ;
59- let mut conn = connection_with_sean_and_tess_in_users_table ( ) . await ;
6065 conn. set_instrumentation ( move |event : InstrumentationEvent < ' _ > | {
6166 events. lock ( ) . unwrap ( ) . push ( event. into ( ) ) ;
6267 } ) ;
@@ -255,3 +260,26 @@ async fn check_events_transaction_nested() {
255260 assert_matches ! ( events[ 10 ] , Event :: StartQuery { .. } ) ;
256261 assert_matches ! ( events[ 11 ] , Event :: FinishQuery { .. } ) ;
257262}
263+
264+ #[ cfg( feature = "postgres" ) ]
265+ #[ tokio:: test]
266+ async fn check_events_transaction_builder ( ) {
267+ use crate :: connection_without_transaction;
268+ use diesel:: result:: Error ;
269+ use scoped_futures:: ScopedFutureExt ;
270+
271+ let ( events_to_check, mut conn) =
272+ setup_test_case_with_connection ( connection_without_transaction ( ) . await ) ;
273+ conn. build_transaction ( )
274+ . run ( |_tx| async move { Ok :: < ( ) , Error > ( ( ) ) } . scope_boxed ( ) )
275+ . await
276+ . unwrap ( ) ;
277+ let events = events_to_check. lock ( ) . unwrap ( ) ;
278+ assert_eq ! ( events. len( ) , 6 , "{:?}" , events) ;
279+ assert_matches ! ( events[ 0 ] , Event :: BeginTransaction { .. } ) ;
280+ assert_matches ! ( events[ 1 ] , Event :: StartQuery { .. } ) ;
281+ assert_matches ! ( events[ 2 ] , Event :: FinishQuery { .. } ) ;
282+ assert_matches ! ( events[ 3 ] , Event :: CommitTransaction { .. } ) ;
283+ assert_matches ! ( events[ 4 ] , Event :: StartQuery { .. } ) ;
284+ assert_matches ! ( events[ 5 ] , Event :: FinishQuery { .. } ) ;
285+ }
0 commit comments