Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
transaction
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
transaction
Commits
90aa4eb0
Commit
90aa4eb0
authored
Dec 17, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coverage.
parent
e618c0a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
76 deletions
+31
-76
transaction/tests/test__manager.py
transaction/tests/test__manager.py
+9
-75
transaction/tests/test__transaction.py
transaction/tests/test__transaction.py
+22
-1
No files found.
transaction/tests/test__manager.py
View file @
90aa4eb0
...
...
@@ -28,7 +28,7 @@ class TransactionManagerTests(unittest.TestCase):
# basic tests with two sub trans jars
# really we only need one, so tests for
# sub1 should identical to tests for sub2
def
test
TransactionCommit
(
self
):
def
test
_commit_normal
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
modify
()
...
...
@@ -39,7 +39,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
sub1
.
_p_jar
.
ccommit_sub
==
0
assert
sub1
.
_p_jar
.
ctpc_finish
==
1
def
test
TransactionAbort
(
self
):
def
test
_abort_normal
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
modify
()
...
...
@@ -49,22 +49,10 @@ class TransactionManagerTests(unittest.TestCase):
assert
sub2
.
_p_jar
.
cabort
==
1
def
testTransactionNote
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
t
=
mgr
.
get
()
t
.
note
(
'This is a note.'
)
self
.
assertEqual
(
t
.
description
,
'This is a note.'
)
t
.
note
(
'Another.'
)
self
.
assertEqual
(
t
.
description
,
'This is a note.
\
n
Another.'
)
t
.
abort
()
# repeat adding in a nonsub trans jars
def
test
NSJTransactionCommit
(
self
):
def
test
_commit_w_nonsub_jar
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
nosub1
.
modify
()
...
...
@@ -73,7 +61,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ctpc_finish
==
1
def
test
NSJTransactionAbort
(
self
):
def
test
_abort_w_nonsub_jar
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
nosub1
.
modify
()
...
...
@@ -94,7 +82,7 @@ class TransactionManagerTests(unittest.TestCase):
# first the recoverable errors
def
test
ExceptionInAbort
(
self
):
def
test
_abort_w_broken_jar
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
_p_jar
=
BasicJar
(
errors
=
'abort'
)
...
...
@@ -110,7 +98,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
cabort
==
1
assert
sub2
.
_p_jar
.
cabort
==
1
def
test
ExceptionInC
ommit
(
self
):
def
test
_commit_w_broken_jar_c
ommit
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
_p_jar
=
BasicJar
(
errors
=
'commit'
)
...
...
@@ -126,7 +114,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ccommit
==
1
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
def
test
ExceptionInTpcV
ote
(
self
):
def
test
_commit_w_broken_jar_tpc_v
ote
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
_p_jar
=
BasicJar
(
errors
=
'tpc_vote'
)
...
...
@@ -143,7 +131,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
assert
sub1
.
_p_jar
.
ctpc_abort
==
1
def
test
ExceptionInTpcB
egin
(
self
):
def
test
_commit_w_broken_jar_tpc_b
egin
(
self
):
# ok this test reveals a bug in the TM.py
# as the nosub tpc_abort there is ignored.
...
...
@@ -167,7 +155,7 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
assert
sub1
.
_p_jar
.
ctpc_abort
==
1
def
test
ExceptionInTpcAbort
(
self
):
def
test
_commit_w_broken_jar_tpc_abort_tpc_vote
(
self
):
mgr
,
sub1
,
sub2
,
sub3
,
nosub1
=
self
.
_makeDM
()
sub1
.
_p_jar
=
BasicJar
(
errors
=
(
'tpc_abort'
,
'tpc_vote'
))
...
...
@@ -181,38 +169,6 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
# last test, check the hosing mechanism
## def testHoserStoppage(self):
## # It's hard to test the "hosed" state of the database, where
## # hosed means that a failure occurred in the second phase of
## # the two phase commit. It's hard because the database can
## # recover from such an error if it occurs during the very first
## # tpc_finish() call of the second phase.
## mgr, sub1, sub2, sub3, nosub1 = self._makeDM()
## for obj in sub1, sub2:
## j = HoserJar(errors='tpc_finish')
## j.reset()
## obj._p_jar = j
## obj.modify(nojar=1)
## try:
## transaction.commit()
## except TestTxnException:
## pass
## self.assert_(Transaction.hosed)
## sub2.modify()
## try:
## transaction.commit()
## except Transaction.POSException.TransactionError:
## pass
## else:
## self.fail("Hosed Application didn't stop commits")
class
DataObject
:
...
...
@@ -294,28 +250,6 @@ class BasicJar:
self
.
ctpc_finish
+=
1
class
HoserJar
(
BasicJar
):
# The HoserJars coordinate their actions via the class variable
# committed. The check() method will only raise its exception
# if committed > 0.
committed
=
0
def
reset
(
self
):
# Calling reset() on any instance will reset the class variable.
HoserJar
.
committed
=
0
def
check
(
self
,
method
):
if
HoserJar
.
committed
>
0
:
BasicJar
.
check
(
self
,
method
)
def
tpc_finish
(
self
,
*
args
):
self
.
check
(
'tpc_finish'
)
self
.
ctpc_finish
+=
1
HoserJar
.
committed
+=
1
def
positive_id
(
obj
):
"""Return id(obj) as a non-negative integer."""
import
struct
...
...
transaction/tests/test__transaction.py
View file @
90aa4eb0
...
...
@@ -70,6 +70,26 @@ def assertRaisesEx(e_type, checked, *args, **kw):
raise
AssertionError
(
"Didn't raise: %s"
%
e_type
.
__name__
)
class
TransactionTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
from
transaction._transaction
import
Transaction
return
Transaction
def
_makeOne
(
self
,
synchronizers
=
None
,
manager
=
None
):
return
self
.
_getTargetClass
()(
synchronizers
,
manager
)
def
test_note
(
self
):
t
=
self
.
_makeOne
()
try
:
t
.
note
(
'This is a note.'
)
self
.
assertEqual
(
t
.
description
,
'This is a note.'
)
t
.
note
(
'Another.'
)
self
.
assertEqual
(
t
.
description
,
'This is a note.
\
n
Another.'
)
finally
:
t
.
abort
()
class
Test_oid_repr
(
unittest
.
TestCase
):
def
_callFUT
(
self
,
oid
):
...
...
@@ -152,7 +172,7 @@ class MiscellaneousTests(unittest.TestCase):
self
.
assertEqual
(
list
(
dm
.
keys
()),
[])
@
run_in_thread
def
first
():
def
third
():
dm
[
'a'
]
=
1
self
.
assertEqual
(
sync
.
log
,
[
'1 new'
])
...
...
@@ -162,6 +182,7 @@ class MiscellaneousTests(unittest.TestCase):
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
TransactionTests
),
unittest
.
makeSuite
(
Test_oid_repr
),
unittest
.
makeSuite
(
MiscellaneousTests
),
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment