@@ -233,7 +233,14 @@ def test_commit_ok(self):
233233 self .assertEqual (committed , now )
234234 self .assertEqual (batch .committed , committed )
235235
236- (session , mutations , single_use_txn , request_options , metadata ) = api ._committed
236+ (
237+ session ,
238+ mutations ,
239+ single_use_txn ,
240+ request_options ,
241+ max_commit_delay ,
242+ metadata ,
243+ ) = api ._committed
237244 self .assertEqual (session , self .SESSION_NAME )
238245 self .assertEqual (mutations , batch ._mutations )
239246 self .assertIsInstance (single_use_txn , TransactionOptions )
@@ -246,12 +253,13 @@ def test_commit_ok(self):
246253 ],
247254 )
248255 self .assertEqual (request_options , RequestOptions ())
256+ self .assertEqual (max_commit_delay , None )
249257
250258 self .assertSpanAttributes (
251259 "CloudSpanner.Commit" , attributes = dict (BASE_ATTRIBUTES , num_mutations = 1 )
252260 )
253261
254- def _test_commit_with_request_options (self , request_options = None ):
262+ def _test_commit_with_options (self , request_options = None , max_commit_delay_in = None ):
255263 import datetime
256264 from google .cloud .spanner_v1 import CommitResponse
257265 from google .cloud .spanner_v1 import TransactionOptions
@@ -267,7 +275,9 @@ def _test_commit_with_request_options(self, request_options=None):
267275 batch = self ._make_one (session )
268276 batch .transaction_tag = self .TRANSACTION_TAG
269277 batch .insert (TABLE_NAME , COLUMNS , VALUES )
270- committed = batch .commit (request_options = request_options )
278+ committed = batch .commit (
279+ request_options = request_options , max_commit_delay = max_commit_delay_in
280+ )
271281
272282 self .assertEqual (committed , now )
273283 self .assertEqual (batch .committed , committed )
@@ -284,6 +294,7 @@ def _test_commit_with_request_options(self, request_options=None):
284294 mutations ,
285295 single_use_txn ,
286296 actual_request_options ,
297+ max_commit_delay ,
287298 metadata ,
288299 ) = api ._committed
289300 self .assertEqual (session , self .SESSION_NAME )
@@ -303,33 +314,46 @@ def _test_commit_with_request_options(self, request_options=None):
303314 "CloudSpanner.Commit" , attributes = dict (BASE_ATTRIBUTES , num_mutations = 1 )
304315 )
305316
317+ self .assertEqual (max_commit_delay_in , max_commit_delay )
318+
306319 def test_commit_w_request_tag_success (self ):
307320 request_options = RequestOptions (
308321 request_tag = "tag-1" ,
309322 )
310- self ._test_commit_with_request_options (request_options = request_options )
323+ self ._test_commit_with_options (request_options = request_options )
311324
312325 def test_commit_w_transaction_tag_success (self ):
313326 request_options = RequestOptions (
314327 transaction_tag = "tag-1-1" ,
315328 )
316- self ._test_commit_with_request_options (request_options = request_options )
329+ self ._test_commit_with_options (request_options = request_options )
317330
318331 def test_commit_w_request_and_transaction_tag_success (self ):
319332 request_options = RequestOptions (
320333 request_tag = "tag-1" ,
321334 transaction_tag = "tag-1-1" ,
322335 )
323- self ._test_commit_with_request_options (request_options = request_options )
336+ self ._test_commit_with_options (request_options = request_options )
324337
325338 def test_commit_w_request_and_transaction_tag_dictionary_success (self ):
326339 request_options = {"request_tag" : "tag-1" , "transaction_tag" : "tag-1-1" }
327- self ._test_commit_with_request_options (request_options = request_options )
340+ self ._test_commit_with_options (request_options = request_options )
328341
329342 def test_commit_w_incorrect_tag_dictionary_error (self ):
330343 request_options = {"incorrect_tag" : "tag-1-1" }
331344 with self .assertRaises (ValueError ):
332- self ._test_commit_with_request_options (request_options = request_options )
345+ self ._test_commit_with_options (request_options = request_options )
346+
347+ def test_commit_w_max_commit_delay (self ):
348+ import datetime
349+
350+ request_options = RequestOptions (
351+ request_tag = "tag-1" ,
352+ )
353+ self ._test_commit_with_options (
354+ request_options = request_options ,
355+ max_commit_delay_in = datetime .timedelta (milliseconds = 100 ),
356+ )
333357
334358 def test_context_mgr_already_committed (self ):
335359 import datetime
@@ -368,7 +392,14 @@ def test_context_mgr_success(self):
368392
369393 self .assertEqual (batch .committed , now )
370394
371- (session , mutations , single_use_txn , request_options , metadata ) = api ._committed
395+ (
396+ session ,
397+ mutations ,
398+ single_use_txn ,
399+ request_options ,
400+ _ ,
401+ metadata ,
402+ ) = api ._committed
372403 self .assertEqual (session , self .SESSION_NAME )
373404 self .assertEqual (mutations , batch ._mutations )
374405 self .assertIsInstance (single_use_txn , TransactionOptions )
@@ -565,12 +596,17 @@ def commit(
565596 ):
566597 from google .api_core .exceptions import Unknown
567598
599+ max_commit_delay = None
600+ if type (request ).pb (request ).HasField ("max_commit_delay" ):
601+ max_commit_delay = request .max_commit_delay
602+
568603 assert request .transaction_id == b""
569604 self ._committed = (
570605 request .session ,
571606 request .mutations ,
572607 request .single_use_transaction ,
573608 request .request_options ,
609+ max_commit_delay ,
574610 metadata ,
575611 )
576612 if self ._rpc_error :
0 commit comments