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
5af25a91
Commit
5af25a91
authored
Jan 15, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The skip test condition should be the same as the flaky timeout condition for test_pool_full.
parent
784e3789
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
23 deletions
+35
-23
src/greentest/test__server.py
src/greentest/test__server.py
+28
-22
src/greentest/test__server_pywsgi.py
src/greentest/test__server_pywsgi.py
+7
-1
No files found.
src/greentest/test__server.py
View file @
5af25a91
from
__future__
import
print_function
from
__future__
import
print_function
,
division
import
unittest
import
errno
import
os
...
...
@@ -10,10 +10,8 @@ from gevent import socket
import
gevent
from
gevent.server
import
StreamServer
# Timeouts very flaky on appveyor and PyPy3
_DEFAULT_SOCKET_TIMEOUT
=
0.1
if
not
greentest
.
EXPECT_POOR_TIMER_RESOLUTION
else
1.0
class
SimpleStreamServer
(
StreamServer
):
def
handle
(
self
,
client_socket
,
_address
):
...
...
@@ -41,7 +39,7 @@ class SimpleStreamServer(StreamServer):
fd
.
close
()
class
_
Settings
(
object
):
class
Settings
(
object
):
ServerClass
=
StreamServer
ServerSubClass
=
SimpleStreamServer
restartable
=
True
...
...
@@ -71,11 +69,15 @@ class _Settings(object):
with
inst
.
assertRaises
(
socket
.
timeout
):
inst
.
assertRequestSucceeded
(
timeout
=
0.01
)
@
staticmethod
def
fill_default_server_args
(
inst
,
kwargs
):
kwargs
.
setdefault
(
'spawn'
,
inst
.
get_spawn
())
return
kwargs
class
TestCase
(
greentest
.
TestCase
):
# pylint: disable=too-many-public-methods
__timeout__
=
greentest
.
LARGE_TIMEOUT
Settings
=
_
Settings
Settings
=
Settings
server
=
None
def
cleanup
(
self
):
...
...
@@ -221,13 +223,16 @@ class TestCase(greentest.TestCase):
# so far I can't reproduce it locally on OS X.
import
gc
;
gc
.
collect
()
def
fill_default_server_args
(
self
,
kwargs
):
return
self
.
Settings
.
fill_default_server_args
(
self
,
kwargs
)
def
ServerClass
(
self
,
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'spawn'
,
self
.
get_spawn
())
return
self
.
Settings
.
ServerClass
(
*
args
,
**
kwargs
)
return
self
.
Settings
.
ServerClass
(
*
args
,
**
self
.
fill_default_server_args
(
kwargs
)
)
def
ServerSubClass
(
self
,
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'spawn'
,
self
.
get_spawn
())
return
self
.
Settings
.
ServerSubClass
(
*
args
,
**
kwargs
)
return
self
.
Settings
.
ServerSubClass
(
*
args
,
**
self
.
fill_default_server_args
(
kwargs
)
)
def
get_spawn
(
self
):
return
None
...
...
@@ -339,7 +344,7 @@ class TestDefaultSpawn(TestCase):
def
test_error_in_spawn
(
self
):
self
.
init_server
()
assert
self
.
server
.
started
self
.
assertTrue
(
self
.
server
.
started
)
error
=
ExpectedError
(
'test_error_in_spawn'
)
self
.
server
.
_spawn
=
lambda
*
args
:
gevent
.
getcurrent
().
throw
(
error
)
self
.
expect_one_error
()
...
...
@@ -350,21 +355,19 @@ class TestDefaultSpawn(TestCase):
# PR 501
self
.
init_server
()
self
.
start_server
()
self
.
assert
True
(
'Server'
in
repr
(
self
.
server
))
self
.
assert
In
(
'Server'
,
repr
(
self
.
server
))
self
.
server
.
set_handle
(
self
.
server
.
handle
)
self
.
assert
True
(
'handle=<bound method'
in
repr
(
self
.
server
)
and
'of self>'
in
repr
(
self
.
server
),
repr
(
self
.
server
))
self
.
assert
In
(
'handle=<bound method'
,
repr
(
self
.
server
))
self
.
assertIn
(
'of self>'
,
repr
(
self
.
server
))
self
.
server
.
set_handle
(
self
.
test_server_repr_when_handle_is_instancemethod
)
self
.
assertTrue
(
'test_server_repr_when_handle_is_instancemethod'
in
repr
(
self
.
server
),
repr
(
self
.
server
))
self
.
assertIn
(
'test_server_repr_when_handle_is_instancemethod'
,
repr
(
self
.
server
))
def
handle
():
pass
self
.
server
.
set_handle
(
handle
)
self
.
assertTrue
(
'handle=<function'
in
repr
(
self
.
server
),
repr
(
self
.
server
))
self
.
assertIn
(
'handle=<function'
,
repr
(
self
.
server
))
class
TestRawSpawn
(
TestDefaultSpawn
):
...
...
@@ -378,14 +381,17 @@ class TestPoolSpawn(TestDefaultSpawn):
def
get_spawn
(
self
):
return
2
@
greentest
.
skipOnAppVeyor
(
"Connection timeouts are flaky"
)
@
greentest
.
skipOnPyPy3OnCI
(
"Doesn't always raise timeout for some reason"
)
@
greentest
.
skipIf
(
greentest
.
EXPECT_POOR_TIMER_RESOLUTION
,
"If we have bad timer resolution and hence increase timeouts, "
"it can be hard to sleep for a correct amount of time that lets "
"requests in the pool be full."
)
def
test_pool_full
(
self
):
self
.
init_server
()
short_request
=
self
.
send_request
(
'/short'
)
long_request
=
self
.
send_request
(
'/long'
)
# keep long_request in scope, otherwise the connection will be closed
gevent
.
sleep
(
0.01
)
gevent
.
get_hub
().
loop
.
update_now
()
gevent
.
sleep
(
_DEFAULT_SOCKET_TIMEOUT
/
10.0
)
self
.
assertPoolFull
()
self
.
assertPoolFull
()
# XXX Not entirely clear why this fails (timeout) on appveyor;
...
...
@@ -398,7 +404,7 @@ class TestPoolSpawn(TestDefaultSpawn):
short_request
.
close
()
# gevent.http and gevent.wsgi cannot detect socket close, so sleep a little
# to let /short request finish
gevent
.
sleep
(
0.1
)
gevent
.
sleep
(
_DEFAULT_SOCKET_TIMEOUT
)
# XXX: This tends to timeout. Which is weird, because what would have
# been the third call to assertPoolFull() DID NOT timeout, hence why it
# was removed.
...
...
src/greentest/test__server_pywsgi.py
View file @
5af25a91
...
...
@@ -42,7 +42,7 @@ Content-length: 31
Service Temporarily Unavailable'''
.
replace
(
b'
\
n
'
,
b'
\
r
\
n
'
)
class
Settings
(
object
):
class
Settings
(
test__server
.
Settings
):
ServerClass
=
pywsgi
.
WSGIServer
ServerSubClass
=
SimpleWSGIServer
close_socket_detected
=
True
...
...
@@ -77,6 +77,12 @@ class Settings(object):
result
=
conn
.
read
()
inst
.
assertFalse
(
result
)
@
staticmethod
def
fill_default_server_args
(
inst
,
kwargs
):
kwargs
=
test__server
.
Settings
.
fill_default_server_args
(
inst
,
kwargs
)
kwargs
.
setdefault
(
'log'
,
pywsgi
.
_NoopLog
())
return
kwargs
class
TestCase
(
test__server
.
TestCase
):
Settings
=
Settings
...
...
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