@@ -60,6 +60,51 @@ func TestCommitAborted(t *testing.T) {
6060 }
6161}
6262
63+ func TestCommitWithMutationsAborted (t * testing.T ) {
64+ t .Parallel ()
65+
66+ db , server , teardown := setupTestDBConnectionWithParams (t , "minSessions=1;maxSessions=1" )
67+ defer teardown ()
68+ ctx := context .Background ()
69+
70+ conn , err := db .Conn (ctx )
71+ if err != nil {
72+ t .Fatalf ("failed to open connection: %v" , err )
73+ }
74+ defer func () { _ = conn .Close () }()
75+
76+ tx , err := conn .BeginTx (ctx , & sql.TxOptions {})
77+ if err != nil {
78+ t .Fatalf ("begin failed: %v" , err )
79+ }
80+ if err := conn .Raw (func (driverConn interface {}) error {
81+ spannerConn , _ := driverConn .(SpannerConn )
82+ mutation := spanner .Insert ("foo" , []string {}, []interface {}{})
83+ return spannerConn .BufferWrite ([]* spanner.Mutation {mutation })
84+ }); err != nil {
85+ t .Fatalf ("failed to buffer mutations: %v" , err )
86+ }
87+ // Abort the transaction on the first commit attempt.
88+ server .TestSpanner .PutExecutionTime (testutil .MethodCommitTransaction , testutil.SimulatedExecutionTime {
89+ Errors : []error {status .Error (codes .Aborted , "Aborted" )},
90+ })
91+ err = tx .Commit ()
92+ if err != nil {
93+ t .Fatalf ("commit failed: %v" , err )
94+ }
95+ reqs := drainRequestsFromServer (server .TestSpanner )
96+ commitReqs := requestsOfType (reqs , reflect .TypeOf (& sppb.CommitRequest {}))
97+ if g , w := len (commitReqs ), 2 ; g != w {
98+ t .Fatalf ("commit request count mismatch\n Got: %v\n Want: %v" , g , w )
99+ }
100+ for _ , req := range commitReqs {
101+ commitReq := req .(* sppb.CommitRequest )
102+ if g , w := len (commitReq .Mutations ), 1 ; g != w {
103+ t .Fatalf ("mutation count mismatch\n Got: %v\n Want: %v" , g , w )
104+ }
105+ }
106+ }
107+
63108func TestCommitAbortedWithInternalRetriesDisabled (t * testing.T ) {
64109 t .Parallel ()
65110
0 commit comments