Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
gevent
Commits
1c3c77c2
Commit
1c3c77c2
authored
Jan 18, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak test__issues461_471.py for coverage.
parent
7dd7eeb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
47 deletions
+59
-47
src/greentest/greentest/sysinfo.py
src/greentest/greentest/sysinfo.py
+1
-1
src/greentest/test__issues461_471.py
src/greentest/test__issues461_471.py
+58
-46
No files found.
src/greentest/greentest/sysinfo.py
View file @
1c3c77c2
...
...
@@ -40,7 +40,7 @@ else:
DEBUG
=
False
RUN_LEAKCHECKS
=
os
.
getenv
(
'GEVENTTEST_LEAKCHECK'
)
RUN_COVERAGE
=
os
.
getenv
(
"COVERAGE_PROCESS_START"
)
RUN_COVERAGE
=
os
.
getenv
(
"COVERAGE_PROCESS_START"
)
or
os
.
getenv
(
"GEVENTTEST_COVERAGE"
)
# Generally, ignore the portions that are only implemented
# on particular platforms; they generally contain partial
...
...
src/greentest/test__issues461_471.py
View file @
1c3c77c2
...
...
@@ -7,7 +7,6 @@ handling of KeyboardInterrupt.
'''
import
sys
WIN
=
sys
.
platform
.
startswith
(
"win"
)
if
sys
.
argv
[
1
:]
==
[
'subprocess'
]:
import
gevent
...
...
@@ -29,50 +28,63 @@ else:
from
subprocess
import
Popen
,
PIPE
import
time
if
sys
.
platform
.
startswith
(
'win'
):
from
subprocess
import
CREATE_NEW_PROCESS_GROUP
kwargs
=
{
'creationflags'
:
CREATE_NEW_PROCESS_GROUP
}
else
:
kwargs
=
{}
p
=
Popen
([
sys
.
executable
,
__file__
,
'subprocess'
],
stdout
=
PIPE
,
**
kwargs
)
line
=
p
.
stdout
.
readline
()
if
not
isinstance
(
line
,
str
):
line
=
line
.
decode
(
'ascii'
)
# Windows needs the \n in the string to write (because of buffering), but
# because of newline handling it doesn't make it through the read; whereas
# it does on other platforms. Universal newlines is broken on Py3, so the best
# thing to do is to strip it
line
=
line
.
strip
()
assert
line
==
'ready'
,
line
# On Windows, we have to send the CTRL_BREAK_EVENT (which seems to terminate the process); SIGINT triggers
# "ValueError: Unsupported signal: 2". The CTRL_C_EVENT is ignored on Python 3 (but not Python 2).
# So this test doesn't test much on Windows.
signal_to_send
=
signal
.
SIGINT
if
not
WIN
else
getattr
(
signal
,
'CTRL_BREAK_EVENT'
)
p
.
send_signal
(
signal_to_send
)
# Wait a few seconds for child process to die. Sometimes signal delivery is delayed
# or even swallowed by Python, so send the signal a few more times if necessary
wait_seconds
=
10.0
now
=
time
.
time
()
midtime
=
now
+
(
wait_seconds
/
2.0
)
endtime
=
time
.
time
()
+
wait_seconds
while
time
.
time
()
<
endtime
:
if
p
.
poll
()
is
not
None
:
break
if
time
.
time
()
>
midtime
:
import
unittest
import
greentest
from
greentest.sysinfo
import
CFFI_BACKEND
from
greentest.sysinfo
import
RUN_COVERAGE
from
greentest.sysinfo
import
WIN
class
Test
(
unittest
.
TestCase
):
@
unittest
.
skipIf
(
CFFI_BACKEND
and
RUN_COVERAGE
,
"Interferes with the timing"
)
def
test_hang
(
self
):
if
WIN
:
from
subprocess
import
CREATE_NEW_PROCESS_GROUP
kwargs
=
{
'creationflags'
:
CREATE_NEW_PROCESS_GROUP
}
else
:
kwargs
=
{}
p
=
Popen
([
sys
.
executable
,
__file__
,
'subprocess'
],
stdout
=
PIPE
,
**
kwargs
)
line
=
p
.
stdout
.
readline
()
if
not
isinstance
(
line
,
str
):
line
=
line
.
decode
(
'ascii'
)
# Windows needs the \n in the string to write (because of buffering), but
# because of newline handling it doesn't make it through the read; whereas
# it does on other platforms. Universal newlines is broken on Py3, so the best
# thing to do is to strip it
line
=
line
.
strip
()
self
.
assertEqual
(
line
,
'ready'
)
# On Windows, we have to send the CTRL_BREAK_EVENT (which seems to terminate the process); SIGINT triggers
# "ValueError: Unsupported signal: 2". The CTRL_C_EVENT is ignored on Python 3 (but not Python 2).
# So this test doesn't test much on Windows.
signal_to_send
=
signal
.
SIGINT
if
not
WIN
else
getattr
(
signal
,
'CTRL_BREAK_EVENT'
)
p
.
send_signal
(
signal_to_send
)
midtime
=
endtime
+
1
# only once
time
.
sleep
(
0.1
)
else
:
# Kill unresponsive child and exit with error 1
sys
.
stderr
.
write
(
__file__
)
sys
.
stderr
.
write
(
": Failed to wait for child
\
n
"
)
p
.
terminate
()
p
.
wait
()
sys
.
exit
(
1
)
# Wait a few seconds for child process to die. Sometimes signal delivery is delayed
# or even swallowed by Python, so send the signal a few more times if necessary
wait_seconds
=
15.0
now
=
time
.
time
()
midtime
=
now
+
(
wait_seconds
/
2.0
)
endtime
=
time
.
time
()
+
wait_seconds
while
time
.
time
()
<
endtime
:
if
p
.
poll
()
is
not
None
:
break
if
time
.
time
()
>
midtime
:
p
.
send_signal
(
signal_to_send
)
midtime
=
endtime
+
1
# only once
time
.
sleep
(
0.1
)
else
:
# Kill unresponsive child and exit with error 1
p
.
terminate
()
p
.
wait
()
raise
AssertionError
(
"Failed to wait for child"
)
# If we get here, it's because we caused the process to exit; it
# didn't hang. Under Windows, however, we have to use CTRL_BREAK_EVENT,
# which has an arbitrary returncode depending on versions (so does CTRL_C_EVENT
# on Python 2). We still
# count this as success.
self
.
assertEqual
(
p
.
returncode
if
not
WIN
else
0
,
0
)
# If we get here, it's because we caused the process to exit; it
# didn't hang. Under Windows, however, we have to use CTRL_BREAK_EVENT,
# which has an arbitrary returncode depending on versions (so does CTRL_C_EVENT
# on Python 2). We still
# count this as success.
sys
.
exit
(
p
.
returncode
if
not
WIN
else
0
)
if
__name__
==
'__main__'
:
greentest
.
main
()
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