@@ -54,9 +54,14 @@ impl From<InstrumentationEvent<'_>> for Event {
54
54
}
55
55
56
56
async 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 : diesel_async:: AsyncPgConnection ,
62
+ ) -> ( Arc < Mutex < Vec < Event > > > , diesel_async:: AsyncPgConnection ) {
57
63
let events = Arc :: new ( Mutex :: new ( Vec :: < Event > :: new ( ) ) ) ;
58
64
let events_to_check = events. clone ( ) ;
59
- let mut conn = connection_with_sean_and_tess_in_users_table ( ) . await ;
60
65
conn. set_instrumentation ( move |event : InstrumentationEvent < ' _ > | {
61
66
events. lock ( ) . unwrap ( ) . push ( event. into ( ) ) ;
62
67
} ) ;
@@ -255,3 +260,26 @@ async fn check_events_transaction_nested() {
255
260
assert_matches ! ( events[ 10 ] , Event :: StartQuery { .. } ) ;
256
261
assert_matches ! ( events[ 11 ] , Event :: FinishQuery { .. } ) ;
257
262
}
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