Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
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
Joshua
wendelin.core
Commits
4b588f69
Commit
4b588f69
authored
Dec 15, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e5600597
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
zopenrace4.py
zopenrace4.py
+25
-5
No files found.
zopenrace4.py
View file @
4b588f69
...
...
@@ -5,8 +5,10 @@
from
__future__
import
print_function
from
ZODB
import
DB
from
ZODB.MappingStorage
import
MappingStorage
from
ZODB.POSException
import
ConflictError
import
transaction
from
persistent
import
Persistent
from
random
import
randint
from
golang
import
func
,
defer
,
select
,
default
from
golang
import
sync
,
context
...
...
@@ -67,6 +69,8 @@ def main():
#
# access to obj1 is organized to always trigger loading from zstor.
# access to obj2 goes through zconn cache and so verifies whether the cache is not stale.
#
# XXX + commit
@
func
def
T1
(
ctx
,
name
,
N
):
db
=
dbopen
()
...
...
@@ -88,18 +92,33 @@ def main():
i1
=
obj1
.
i
i2
=
obj2
.
i
if
i1
!=
i2
:
raise
AssertionError
(
"T1: obj1.i (%d) != obj2.i (%d)"
%
(
i1
,
i2
))
print
(
'FAIL'
)
raise
AssertionError
(
"T%s: obj1.i (%d) != obj2.i (%d)"
%
(
name
,
i1
,
i2
))
# change objects once in a while
if
randint
(
0
,
4
)
==
0
:
obj1
.
i
+=
1
obj2
.
i
+=
1
#transaction.abort() # we did not changed anything; also fails with commit
try
:
transaction
.
commit
()
except
ConflictError
:
#print('conflict -> ignore')
transaction
.
abort
()
transaction
.
abort
()
# we did not changed anything; also fails with commit
zconn
.
close
()
for
i
in
range
(
N
):
#print('T1%s.%d' % (name, i))
if
ready
(
ctx
.
done
()):
break
print
(
'T1%s.%d'
%
(
name
,
i
))
t1
()
raise
RuntimeError
(
"T1: done"
)
"""
# T2 changes obj1/obj2 in a loop by doing `objX.i += 1`.
#
# Since both objects start from 0, the invariant that `obj1.i == obj2.i` is always preserved.
...
...
@@ -127,6 +146,7 @@ def main():
break
#print('T2.%d' % i)
t2()
"""
# run T1 and T2 concurrently. As of 20191210, due to race condition in
...
...
@@ -135,9 +155,9 @@ def main():
N
=
100000
wg
=
sync
.
WorkGroup
(
context
.
background
())
for
x
in
'a'
:
for
x
in
'a
b
'
:
wg
.
go
(
T1
,
x
,
N
)
wg
.
go
(
T2
,
N
)
#
wg.go(T2, N)
wg
.
wait
()
print
(
'OK'
)
...
...
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