mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 01:42:37 +08:00
add tests for new database behavior to python scripted tests
This also fixes the behavior for the tests of the options which are no longer reset when on_error is called.
This commit is contained in:
parent
e6e2ea2af6
commit
63f23c0818
@ -221,15 +221,14 @@ def test_retry_limits(db):
|
||||
|
||||
txn4(db)
|
||||
|
||||
# (5) Retry limits don't survive on_error()
|
||||
# (5) Retry limits survive on_error()
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn5(tr):
|
||||
tr.options.set_retry_limit(1)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr.options.set_retry_limit(2)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(5) Retry limit was ignored.')
|
||||
@ -247,6 +246,119 @@ def test_retry_limits(db):
|
||||
txn5(db)
|
||||
|
||||
|
||||
def test_db_retry_limits(db):
|
||||
err = fdb.FDBError(1007)
|
||||
db.options.set_transaction_retry_limit(1)
|
||||
|
||||
# (1) Basic retry limit
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn1(tr):
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(1) Retry limit from database was ignored.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != err.code:
|
||||
raise
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(1) Transaction not cancelled after error.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1025:
|
||||
raise
|
||||
|
||||
txn1(db)
|
||||
|
||||
# (2) More retries in transaction than database
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn2(tr):
|
||||
tr.options.set_retry_limit(2)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(2) Retry limit from transaction was ignored.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != err.code:
|
||||
raise
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(2) Transaction not cancelled after error.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1025:
|
||||
raise
|
||||
|
||||
txn2(db)
|
||||
|
||||
# (3) More retries in database than transaction
|
||||
db.options.set_transaction_retry_limit(2)
|
||||
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn3(tr):
|
||||
tr.options.set_retry_limit(1)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(3) Retry limit from transaction was ignored.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != err.code:
|
||||
raise
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(3) Transaction not cancelled after error.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1025:
|
||||
raise
|
||||
|
||||
txn3(db)
|
||||
|
||||
# (4) Reset resets to database default
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn4(tr):
|
||||
tr.options.set_retry_limit(1)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(4) Retry limit from transaction was ignored.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != err.code:
|
||||
raise
|
||||
tr.reset()
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(4) Retry limit from database was ignored.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != err.code:
|
||||
raise
|
||||
try:
|
||||
tr.on_error(err).wait() # should throw
|
||||
raise TestError('(4) Transaction not cancelled after error.')
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1025:
|
||||
raise
|
||||
|
||||
txn4(db)
|
||||
|
||||
db.options.set_transaction_retry_limit(-1) # reset to default (infinite retries)
|
||||
|
||||
|
||||
def test_timeouts(db):
|
||||
# (1) Basic timeouts
|
||||
@retry_with_timeout(default_timeout)
|
||||
@ -262,13 +374,17 @@ def test_timeouts(db):
|
||||
|
||||
txn1(db)
|
||||
|
||||
# (2) Timeout does not survive on_error()
|
||||
# (2) Timeout survives on_error()
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn2(tr):
|
||||
tr.options.set_timeout(100)
|
||||
tr.on_error(fdb.FDBError(1007)).wait() # should not throw
|
||||
time.sleep(1)
|
||||
tr.commit().wait() # should not throw
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn2(db)
|
||||
|
||||
@ -307,6 +423,11 @@ def test_timeouts(db):
|
||||
def txn5(tr):
|
||||
tr.options.set_timeout(100)
|
||||
time.sleep(1)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
tr.reset()
|
||||
tr.commit().wait() # should not throw
|
||||
|
||||
@ -413,6 +534,102 @@ def test_timeouts(db):
|
||||
txn11(db)
|
||||
|
||||
|
||||
def test_db_timeouts(db):
|
||||
err = fdb.FDBError(1007)
|
||||
db.options.set_transaction_timeout(500)
|
||||
|
||||
# (1) Basic timeout
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn1(tr):
|
||||
time.sleep(1)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(1) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn1(db)
|
||||
|
||||
# (2) Timeout after on_error
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn2(tr):
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
time.sleep(1)
|
||||
tr[b'foo']
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(2) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn2(db)
|
||||
|
||||
# (3) Longer timeout than database timeout
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn3(tr):
|
||||
tr.options.set_timeout(1000)
|
||||
time.sleep(0.75)
|
||||
tr[b'foo'] = b'bar'
|
||||
tr.on_error(err).wait() # should not throw
|
||||
tr[b'foo']
|
||||
time.sleep(0.75)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(3) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn3(db)
|
||||
|
||||
# (4) Shorter timeout than database timeout
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn4(tr):
|
||||
tr.options.set_timeout(100)
|
||||
tr[b'foo'] = b'bar'
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(4) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn4(db)
|
||||
|
||||
# (5) Reset resets timeout to database timeout
|
||||
@retry_with_timeout(default_timeout)
|
||||
def txn5(tr):
|
||||
tr.options.set_timeout(100)
|
||||
tr[b'foo'] = b'bar'
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(5) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
tr.reset()
|
||||
tr[b'foo'] = b'bar'
|
||||
time.sleep(0.2)
|
||||
tr.on_error(err).wait() #should not throw
|
||||
tr[b'foo'] = b'bar'
|
||||
time.sleep(0.8)
|
||||
try:
|
||||
tr.commit().wait() # should throw
|
||||
raise TestError("(5) Timeout didn't fire.")
|
||||
except fdb.FDBError as e:
|
||||
if e.code != 1031:
|
||||
raise
|
||||
|
||||
txn5(db)
|
||||
|
||||
db.options.set_transaction_timeout(0) # reset to default (no timeout)
|
||||
|
||||
|
||||
def test_combinations(db):
|
||||
# (1) Cancellation does survive on_error() even when retry limit is hit
|
||||
@retry_with_timeout(default_timeout)
|
||||
|
@ -42,8 +42,10 @@ import fdb.tuple
|
||||
from directory_extension import DirectoryExtension
|
||||
|
||||
from cancellation_timeout_tests import test_timeouts
|
||||
from cancellation_timeout_tests import test_db_timeouts
|
||||
from cancellation_timeout_tests import test_cancellation
|
||||
from cancellation_timeout_tests import test_retry_limits
|
||||
from cancellation_timeout_tests import test_db_retry_limits
|
||||
from cancellation_timeout_tests import test_combinations
|
||||
|
||||
random.seed(0)
|
||||
@ -547,7 +549,9 @@ class Tester:
|
||||
test_watches(db)
|
||||
test_cancellation(db)
|
||||
test_retry_limits(db)
|
||||
test_db_retry_limits(db)
|
||||
test_timeouts(db)
|
||||
test_db_timeouts(db)
|
||||
test_combinations(db)
|
||||
test_locality(db)
|
||||
test_predicates()
|
||||
|
Loading…
x
Reference in New Issue
Block a user