Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
a0867aa0
Commit
a0867aa0
authored
Apr 17, 2023
by
dieter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `TestGroup` tests; minor cleanup
parent
b90d90ce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
src/ZODB/tests/racetest.py
src/ZODB/tests/racetest.py
+19
-12
No files found.
src/ZODB/tests/racetest.py
View file @
a0867aa0
...
@@ -200,7 +200,7 @@ class RaceTests(object):
...
@@ -200,7 +200,7 @@ class RaceTests(object):
for
i
in
range
(
N
):
for
i
in
range
(
N
):
# print('%s.%d' % (f.__name__, i))
# print('%s.%d' % (f.__name__, i))
f
(
tg
)
f
(
tg
)
if
tg
.
failed
.
is_set
():
if
tg
.
failed
():
break
break
# loop verify and modify concurrently.
# loop verify and modify concurrently.
...
@@ -308,7 +308,7 @@ class RaceTests(object):
...
@@ -308,7 +308,7 @@ class RaceTests(object):
for
i
in
range
(
N
):
for
i
in
range
(
N
):
# print('T%s.%d' % (tx, i))
# print('T%s.%d' % (tx, i))
t_
()
t_
()
if
tg
.
failed
.
is_set
():
if
tg
.
failed
():
break
break
finally
:
finally
:
db
.
close
()
db
.
close
()
...
@@ -392,7 +392,7 @@ class RaceTests(object):
...
@@ -392,7 +392,7 @@ class RaceTests(object):
db
=
self
.
dbopen
()
db
=
self
.
dbopen
()
try
:
try
:
for
i
in
range
(
4
):
for
i
in
range
(
4
):
if
tg
.
failed
.
is_set
():
if
tg
.
failed
():
break
break
work1
(
db
)
work1
(
db
)
finally
:
finally
:
...
@@ -400,7 +400,7 @@ class RaceTests(object):
...
@@ -400,7 +400,7 @@ class RaceTests(object):
for
i
in
range
(
N
):
for
i
in
range
(
N
):
# print('T%s.%d' % (tx, i))
# print('T%s.%d' % (tx, i))
if
tg
.
failed
.
is_set
():
if
tg
.
failed
():
break
break
t_
()
t_
()
...
@@ -490,12 +490,13 @@ class TestGroup(object):
...
@@ -490,12 +490,13 @@ class TestGroup(object):
- .go() adds test thread to the group.
- .go() adds test thread to the group.
- .wait() waits for all spawned threads to finish and reports all
- .wait() waits for all spawned threads to finish and reports all
collected failures to containing testcase.
collected failures to containing testcase.
- a test should indicate failure by call to .fail()
- a test should indicate failure by call to .fail(), it
can check for a failure with .failed()
"""
"""
def
__init__
(
self
,
testcase
):
def
__init__
(
self
,
testcase
):
self
.
testcase
=
testcase
self
.
testcase
=
testcase
self
.
failed
=
threading
.
Event
()
self
.
failed
_event
=
threading
.
Event
()
self
.
fail_mu
=
threading
.
Lock
()
self
.
fail_mu
=
threading
.
Lock
()
self
.
failv
=
[]
# failures registerd by .fail
self
.
failv
=
[]
# failures registerd by .fail
self
.
threadv
=
[]
# spawned threads
self
.
threadv
=
[]
# spawned threads
...
@@ -505,7 +506,11 @@ class TestGroup(object):
...
@@ -505,7 +506,11 @@ class TestGroup(object):
"""fail adds failure to test result."""
"""fail adds failure to test result."""
with
self
.
fail_mu
:
with
self
.
fail_mu
:
self
.
failv
.
append
(
msg
)
self
.
failv
.
append
(
msg
)
self
.
failed
.
set
()
self
.
failed_event
.
set
()
def
failed
(
self
):
"""did the thest already fail."""
return
self
.
failed_event
.
is_set
()
def
go
(
self
,
f
,
*
argv
,
**
kw
):
def
go
(
self
,
f
,
*
argv
,
**
kw
):
"""go spawns f(self, #thread, *argv, **kw) in new test thread."""
"""go spawns f(self, #thread, *argv, **kw) in new test thread."""
...
@@ -517,11 +522,12 @@ class TestGroup(object):
...
@@ -517,11 +522,12 @@ class TestGroup(object):
t
.
start
()
t
.
start
()
def
_run
(
self
,
f
,
tx
,
argv
,
kw
):
def
_run
(
self
,
f
,
tx
,
argv
,
kw
):
tname
=
self
.
threadv
[
tx
].
name
try
:
try
:
f
(
self
,
tx
,
*
argv
,
**
kw
)
f
(
self
,
tx
,
*
argv
,
**
kw
)
except
Exception
as
e
:
except
Exception
as
e
:
self
.
fail
(
"Unhandled exception %r in thread %s"
self
.
fail
(
"Unhandled exception %r in thread %s"
%
(
e
,
self
.
threadv
[
tx
].
name
))
%
(
e
,
t
name
))
raise
raise
finally
:
finally
:
self
.
waitg
.
done
()
self
.
waitg
.
done
()
...
@@ -537,13 +543,14 @@ class TestGroup(object):
...
@@ -537,13 +543,14 @@ class TestGroup(object):
try
:
try
:
t
.
join
(
1
)
t
.
join
(
1
)
except
AssertionError
:
except
AssertionError
:
self
.
failed
.
set
()
self
.
failed
_event
.
set
()
failed_to_finish
.
append
(
t
.
name
)
failed_to_finish
.
append
(
t
.
name
)
if
failed_to_finish
:
if
failed_to_finish
:
self
.
fail
(
"threads did not finish: %s"
%
failed_to_finish
)
self
.
fail
(
"threads did not finish: %s"
%
failed_to_finish
)
del
self
.
threadv
# avoid cyclic garbage
if
self
.
failed
.
is_set
():
if
self
.
failed
():
self
.
testcase
.
fail
(
'
\
n
\
n
'
.
join
(
[
_
for
_
in
self
.
failv
if
_
]
))
self
.
testcase
.
fail
(
'
\
n
\
n
'
.
join
(
self
.
failv
))
class
Daemon
(
threading
.
Thread
):
class
Daemon
(
threading
.
Thread
):
...
@@ -616,7 +623,7 @@ class WaitGroup(object):
...
@@ -616,7 +623,7 @@ class WaitGroup(object):
if
self
.
n
<
0
:
if
self
.
n
<
0
:
raise
AssertionError
(
"#workers is negative"
)
raise
AssertionError
(
"#workers is negative"
)
if
self
.
n
==
0
:
if
self
.
n
==
0
:
self
.
condition
.
notify
()
self
.
condition
.
notify
_all
()
def
done
(
self
):
def
done
(
self
):
self
.
add
(
-
1
)
self
.
add
(
-
1
)
...
...
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