Skip to content

Commit 1060137

Browse files
committed
rename tests and add reasoning
1 parent 405aed4 commit 1060137

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

test/asynchronous/test_transactions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ async def set_fail_point(self, command_args):
448448
await self.configure_fail_point(client, command_args)
449449

450450
@async_client_context.require_transactions
451-
async def test_callback_raises_custom_error(self):
451+
async def test_1_callback_raises_custom_error(self):
452452
class _MyException(Exception):
453453
pass
454454

@@ -460,7 +460,7 @@ async def raise_error(_):
460460
await s.with_transaction(raise_error)
461461

462462
@async_client_context.require_transactions
463-
async def test_callback_returns_value(self):
463+
async def test_2_callback_returns_value(self):
464464
async def callback(_):
465465
return "Foo"
466466

@@ -488,7 +488,7 @@ def callback(_):
488488
self.assertEqual(await s.with_transaction(callback), "Foo")
489489

490490
@async_client_context.require_transactions
491-
async def test_callback_not_retried_after_timeout(self):
491+
async def test_3_1_callback_not_retried_after_timeout(self):
492492
listener = OvertCommandListener()
493493
client = await self.async_rs_client(event_listeners=[listener])
494494
coll = client[self.db.name].test
@@ -516,7 +516,7 @@ async def callback(session):
516516

517517
@async_client_context.require_test_commands
518518
@async_client_context.require_transactions
519-
async def test_callback_not_retried_after_commit_timeout(self):
519+
async def test_3_2_callback_not_retried_after_commit_timeout(self):
520520
listener = OvertCommandListener()
521521
client = await self.async_rs_client(event_listeners=[listener])
522522
coll = client[self.db.name].test
@@ -550,7 +550,7 @@ async def callback(session):
550550

551551
@async_client_context.require_test_commands
552552
@async_client_context.require_transactions
553-
async def test_commit_not_retried_after_timeout(self):
553+
async def test_3_3_commit_not_retried_after_timeout(self):
554554
listener = OvertCommandListener()
555555
client = await self.async_rs_client(event_listeners=[listener])
556556
coll = client[self.db.name].test
@@ -622,10 +622,12 @@ async def callback(session):
622622

623623
@async_client_context.require_test_commands
624624
@async_client_context.require_transactions
625-
async def test_transaction_backoff(self):
625+
async def test_4_retry_backoff_is_enforced(self):
626626
client = async_client_context.client
627627
coll = client[self.db.name].test
628-
# patch random to make it deterministic
628+
# patch random to make it deterministic -- once to effectively have
629+
# no backoff and the second time with "max" backoff (always waiting the longest
630+
# possible time)
629631
_original_random_random = random.random
630632

631633
def always_one():
@@ -639,12 +641,10 @@ def always_zero():
639641
await self.set_fail_point(
640642
{
641643
"configureFailPoint": "failCommand",
642-
"mode": {
643-
"times": 13
644-
}, # sufficiently high enough such that the time effect of backoff is noticeable
644+
"mode": {"times": 13},
645645
"data": {
646646
"failCommands": ["commitTransaction"],
647-
"errorCode": 24,
647+
"errorCode": 251,
648648
},
649649
}
650650
)
@@ -671,7 +671,7 @@ async def callback(session):
671671
}, # sufficiently high enough such that the time effect of backoff is noticeable
672672
"data": {
673673
"failCommands": ["commitTransaction"],
674-
"errorCode": 24,
674+
"errorCode": 251,
675675
},
676676
}
677677
)

test/test_transactions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def set_fail_point(self, command_args):
440440
self.configure_fail_point(client, command_args)
441441

442442
@client_context.require_transactions
443-
def test_callback_raises_custom_error(self):
443+
def test_1_callback_raises_custom_error(self):
444444
class _MyException(Exception):
445445
pass
446446

@@ -452,7 +452,7 @@ def raise_error(_):
452452
s.with_transaction(raise_error)
453453

454454
@client_context.require_transactions
455-
def test_callback_returns_value(self):
455+
def test_2_callback_returns_value(self):
456456
def callback(_):
457457
return "Foo"
458458

@@ -480,7 +480,7 @@ def callback(_):
480480
self.assertEqual(s.with_transaction(callback), "Foo")
481481

482482
@client_context.require_transactions
483-
def test_callback_not_retried_after_timeout(self):
483+
def test_3_1_callback_not_retried_after_timeout(self):
484484
listener = OvertCommandListener()
485485
client = self.rs_client(event_listeners=[listener])
486486
coll = client[self.db.name].test
@@ -508,7 +508,7 @@ def callback(session):
508508

509509
@client_context.require_test_commands
510510
@client_context.require_transactions
511-
def test_callback_not_retried_after_commit_timeout(self):
511+
def test_3_2_callback_not_retried_after_commit_timeout(self):
512512
listener = OvertCommandListener()
513513
client = self.rs_client(event_listeners=[listener])
514514
coll = client[self.db.name].test
@@ -540,7 +540,7 @@ def callback(session):
540540

541541
@client_context.require_test_commands
542542
@client_context.require_transactions
543-
def test_commit_not_retried_after_timeout(self):
543+
def test_3_3_commit_not_retried_after_timeout(self):
544544
listener = OvertCommandListener()
545545
client = self.rs_client(event_listeners=[listener])
546546
coll = client[self.db.name].test
@@ -610,10 +610,12 @@ def callback(session):
610610

611611
@client_context.require_test_commands
612612
@client_context.require_transactions
613-
def test_transaction_backoff(self):
613+
def test_4_retry_backoff_is_enforced(self):
614614
client = client_context.client
615615
coll = client[self.db.name].test
616-
# patch random to make it deterministic
616+
# patch random to make it deterministic -- once to effectively have
617+
# no backoff and the second time with "max" backoff (always waiting the longest
618+
# possible time)
617619
_original_random_random = random.random
618620

619621
def always_one():
@@ -627,12 +629,10 @@ def always_zero():
627629
self.set_fail_point(
628630
{
629631
"configureFailPoint": "failCommand",
630-
"mode": {
631-
"times": 13
632-
}, # sufficiently high enough such that the time effect of backoff is noticeable
632+
"mode": {"times": 13},
633633
"data": {
634634
"failCommands": ["commitTransaction"],
635-
"errorCode": 24,
635+
"errorCode": 251,
636636
},
637637
}
638638
)
@@ -657,7 +657,7 @@ def callback(session):
657657
}, # sufficiently high enough such that the time effect of backoff is noticeable
658658
"data": {
659659
"failCommands": ["commitTransaction"],
660-
"errorCode": 24,
660+
"errorCode": 251,
661661
},
662662
}
663663
)

0 commit comments

Comments
 (0)