@@ -659,6 +659,58 @@ async fn split_large_event() -> Result<()> {
659
659
Ok ( ( ) )
660
660
}
661
661
662
+ /// Test that transaction fields are parsed correctly
663
+ #[ tokio:: test]
664
+ async fn transaction_fields ( ) -> Result < ( ) > {
665
+ let ( client, coll, mut stream) =
666
+ match init_stream ( "chang_stream_transaction_fields" , true ) . await ? {
667
+ Some ( t) => t,
668
+ None => return Ok ( ( ) ) ,
669
+ } ;
670
+ if client. is_sharded ( ) {
671
+ log_uncaptured ( "skipping change stream test transaction_fields on unsupported topology" ) ;
672
+ return Ok ( ( ) ) ;
673
+ }
674
+ if !VersionReq :: parse ( ">=5.0" )
675
+ . unwrap ( )
676
+ . matches ( & client. server_version )
677
+ {
678
+ log_uncaptured ( format ! (
679
+ "skipping change stream test transaction_fields on unsupported version {:?}" ,
680
+ client. server_version
681
+ ) ) ;
682
+ return Ok ( ( ) ) ;
683
+ }
684
+ if !client. supports_transactions ( ) {
685
+ log_uncaptured (
686
+ "skipping change stream transaction_fields test due to lack of transaction support" ,
687
+ ) ;
688
+ return Ok ( ( ) ) ;
689
+ }
690
+
691
+ let mut session = client. start_session ( ) . await . unwrap ( ) ;
692
+ let session_id = session. id ( ) . get ( "id" ) . cloned ( ) ;
693
+ assert ! ( session_id. is_some( ) ) ;
694
+ session. start_transaction ( ) . await . unwrap ( ) ;
695
+ coll. insert_one ( doc ! { "_id" : 1 } )
696
+ . session ( & mut session)
697
+ . await ?;
698
+ session. commit_transaction ( ) . await . unwrap ( ) ;
699
+
700
+ let next_event = stream. next ( ) . await . transpose ( ) ?;
701
+ assert ! ( matches!( next_event,
702
+ Some ( ChangeStreamEvent {
703
+ operation_type: OperationType :: Insert ,
704
+ document_key: Some ( key) ,
705
+ lsid: Some ( lsid) ,
706
+ txn_number: Some ( 1 ) ,
707
+ ..
708
+ } ) if key == doc! { "_id" : 1 } && lsid. get( "id" ) == session_id. as_ref( )
709
+ ) ) ;
710
+
711
+ Ok ( ( ) )
712
+ }
713
+
662
714
// Regression test: `Collection::watch` uses the type parameter. This is not flagged as a test to
663
715
// run because it's just asserting that this compiles.
664
716
#[ allow( unreachable_code, unused_variables, clippy:: diverging_sub_expression) ]
0 commit comments