Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
alecs_myu
erp5
Commits
d463d250
Commit
d463d250
authored
Dec 10, 2012
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use threading.Timer instead of a sleeping thread, clean opened threads
parent
4a202f4a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
erp5/tests/testERP5TestNode.py
erp5/tests/testERP5TestNode.py
+8
-14
erp5/util/testnode/ProcessManager.py
erp5/util/testnode/ProcessManager.py
+7
-6
No files found.
erp5/tests/testERP5TestNode.py
View file @
d463d250
...
...
@@ -58,14 +58,15 @@ class ERP5TestNode(TestCase):
os
.
mkdir
(
self
.
remote_repository0
)
os
.
mkdir
(
self
.
remote_repository1
)
os
.
mkdir
(
self
.
remote_repository2
)
def
log
(
*
args
,
**
kw
):
for
arg
in
args
:
print
"TESTNODE LOG : %r"
%
(
arg
,)
self
.
log
=
log
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
_temp_dir
,
True
)
def
getTestNode
(
self
):
def
log
(
*
args
,
**
kw
):
for
arg
in
args
:
print
"TESTNODE LOG : %r"
%
(
arg
,)
# XXX how to get property the git path ?
config
=
{}
config
[
"git_binary"
]
=
"/srv/slapgrid/slappart80/srv/runner/software/ba1e09f3364989dc92da955b64e72f8d/parts/git/bin/git"
...
...
@@ -77,7 +78,7 @@ class ERP5TestNode(TestCase):
config
[
"log_file"
]
=
self
.
log_file
config
[
"test_suite_master_url"
]
=
None
config
[
"test_node_title"
]
=
"Foo-Test-Node"
return
TestNode
(
log
,
config
)
return
TestNode
(
self
.
log
,
config
)
def
getTestSuiteData
(
self
,
add_third_repository
=
False
,
reference
=
"foo"
):
data
=
[{
...
...
@@ -466,16 +467,9 @@ branch = foo
time
.
sleep
=
original_sleep
def
test_12_spawn
(
self
):
def
_log
(
*
args
,
**
kw
):
for
arg
in
args
:
print
"TESTNODE LOG : %r"
%
(
arg
,)
def
_checkCorrectStatus
(
expected_status
,
*
args
):
result
=
process_manager
.
spawn
(
*
args
)
self
.
assertEqual
(
result
[
'status_code'
],
expected_status
)
def
patch_sleep
(
n
):
subprocess
.
check_call
([
"sleep"
,
n
/
10000
])
original_sleep
=
time
.
sleep
process_manager
=
ProcessManager
(
log
=
_log
)
_checkCorrectStatus
(
0
,
*
[
'sleep'
,
'3'
])
_checkCorrectStatus
(
-
15
,
*
[
'sleep'
,
'8'
])
time
.
sleep
=
original_sleep
process_manager
=
ProcessManager
(
log
=
self
.
log
,
max_timeout
=
1
)
_checkCorrectStatus
(
0
,
*
[
'sleep'
,
'0'
])
_checkCorrectStatus
(
-
15
,
*
[
'sleep'
,
'2'
])
erp5/util/testnode/ProcessManager.py
View file @
d463d250
...
...
@@ -32,7 +32,7 @@ import signal
import
sys
import
time
MAX_TIMEOUT
=
5
MAX_TIMEOUT
=
36000
class
SubprocessError
(
EnvironmentError
):
def
__init__
(
self
,
status_dict
):
...
...
@@ -109,13 +109,13 @@ class ProcessManager(object):
self
.
under_cancellation
=
False
self
.
p
=
None
self
.
result
=
None
self
.
max_timeout
=
kw
.
get
(
"max_timeout"
)
or
MAX_TIMEOUT
def
spawn
(
self
,
*
args
,
**
kw
):
def
timeoutExpired
(
p
):
time
.
sleep
(
MAX_TIMEOUT
)
def
timeoutExpired
(
p
,
log
):
if
p
.
poll
()
is
None
:
log
(
'PROCESS TOO LONG OR DEAD, GOING TO BE TERMINATED'
)
p
.
terminate
()
raise
TimeoutError
if
self
.
under_cancellation
:
raise
CancellationError
(
"Test Result was cancelled"
)
...
...
@@ -137,10 +137,11 @@ class ProcessManager(object):
p
=
subprocess
.
Popen
(
args
,
stdin
=
self
.
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
,
**
subprocess_kw
)
self
.
process_pid_set
.
add
(
p
.
pid
)
t
hread
=
threading
.
Thread
(
target
=
timeoutExpired
,
args
=
(
p
,
))
t
hread
.
start
()
t
imer
=
threading
.
Timer
(
self
.
max_timeout
,
timeoutExpired
,
args
=
(
p
,
self
.
log
))
t
imer
.
start
()
stdout
,
stderr
=
subprocess_capture
(
p
,
self
.
log
,
log_prefix
,
get_output
=
get_output
)
timer
.
cancel
()
result
=
dict
(
status_code
=
p
.
returncode
,
command
=
command
,
stdout
=
stdout
,
stderr
=
stderr
)
self
.
process_pid_set
.
discard
(
p
.
pid
)
...
...
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