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
e012980a
Commit
e012980a
authored
Jan 17, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Centralize socket timeouts.
parent
6184dd23
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
20 deletions
+27
-20
src/greentest/greentest.py
src/greentest/greentest.py
+6
-0
src/greentest/test___example_servers.py
src/greentest/test___example_servers.py
+18
-14
src/greentest/test__example_echoserver.py
src/greentest/test__example_echoserver.py
+2
-5
src/greentest/test__server.py
src/greentest/test__server.py
+1
-1
No files found.
src/greentest/greentest.py
View file @
e012980a
...
...
@@ -490,6 +490,12 @@ if RUNNING_ON_TRAVIS:
# connected to with the same error.
DEFAULT_BIND_ADDR
=
'127.0.0.1'
# For in-process sockets
DEFAULT_SOCKET_TIMEOUT
=
0.1
if
not
EXPECT_POOR_TIMER_RESOLUTION
else
2.0
# For cross-process sockets
DEFAULT_XPC_SOCKET_TIMEOUT
=
2.0
if
not
EXPECT_POOR_TIMER_RESOLUTION
else
4.0
class
TestCase
(
TestCaseMetaClass
(
"NewBase"
,
(
BaseTestCase
,),
{})):
__timeout__
=
LOCAL_TIMEOUT
if
not
RUNNING_ON_CI
else
CI_TIMEOUT
switch_expected
=
'default'
...
...
src/greentest/test___example_servers.py
View file @
e012980a
import
sys
#import time
from
unittest
import
main
if
sys
.
version_info
[
0
]
==
3
:
try
:
from
urllib
import
request
as
urllib2
e
lse
:
e
xcept
ImportError
:
import
urllib2
from
unittest
import
SkipTest
import
util
import
socket
import
ssl
from
greentest
import
DEFAULT_XPC_SOCKET_TIMEOUT
from
greentest
import
main
class
Test_wsgiserver
(
util
.
TestServer
):
server
=
'wsgiserver.py'
...
...
@@ -22,10 +24,13 @@ class Test_wsgiserver(util.TestServer):
def
read
(
self
,
path
=
'/'
):
url
=
self
.
URL
+
path
try
:
kwargs
=
{}
if
self
.
ssl_ctx
is
not
None
:
response
=
urllib2
.
urlopen
(
url
,
None
,
2
,
context
=
self
.
ssl_ctx
)
else
:
response
=
urllib2
.
urlopen
(
url
,
None
,
2
)
kwargs
=
{
'context'
:
self
.
ssl_ctx
}
response
=
urllib2
.
urlopen
(
url
,
None
,
DEFAULT_XPC_SOCKET_TIMEOUT
,
**
kwargs
)
except
urllib2
.
HTTPError
:
response
=
sys
.
exc_info
()[
1
]
result
=
'%s %s'
%
(
response
.
code
,
response
.
msg
),
response
.
read
()
...
...
@@ -47,7 +52,6 @@ class Test_wsgiserver(util.TestServer):
def
_do_test_a_blocking_client
(
self
):
# We spawn this in a separate server because if it's broken
# the whole server hangs
print
(
"Checking blocking"
)
with
self
.
running_server
():
# First, make sure we can talk to it.
self
.
_test_hello
()
...
...
@@ -75,10 +79,10 @@ class Test_wsgiserver(util.TestServer):
line
=
sock_file
.
readline
()
self
.
assertEqual
(
line
,
b'HTTP/1.1 404 Not Found
\
r
\
n
'
)
sock
.
close
()
sock_file
.
close
()
if
ssl_sock
is
not
None
:
ssl_sock
.
close
()
sock
.
close
()
def
test_a_blocking_client
(
self
):
self
.
_do_test_a_blocking_client
()
...
...
@@ -102,14 +106,14 @@ class Test_webproxy(Test_wsgiserver):
def
_run_all_tests
(
self
):
status
,
data
=
self
.
read
(
'/'
)
self
.
assertEqual
(
status
,
'200 OK'
)
assert
b"gevent example"
in
data
,
repr
(
data
)
self
.
assertIn
(
b"gevent example"
,
data
)
status
,
data
=
self
.
read
(
'/http://www.google.com'
)
self
.
assertEqual
(
status
,
'200 OK'
)
assert
b'google'
in
data
.
lower
(),
repr
(
data
)
self
.
assertIn
(
b'google'
,
data
.
lower
()
)
def
_do_
test_a_blocking_client
(
self
):
def
test_a_blocking_client
(
self
):
# Not applicable
r
eturn
r
aise
SkipTest
(
"Not applicable"
)
# class Test_webpy(Test_wsgiserver):
...
...
src/greentest/test__example_echoserver.py
View file @
e012980a
...
...
@@ -4,9 +4,6 @@ import gevent
import
util
_DEFAULT_SOCKET_TIMEOUT
=
0.1
if
not
greentest
.
EXPECT_POOR_TIMER_RESOLUTION
else
2.0
class
Test
(
util
.
TestServer
):
server
=
'echoserver.py'
...
...
@@ -18,11 +15,11 @@ class Test(util.TestServer):
kwargs
=
{
'bufsize'
:
1
}
kwargs
[
'mode'
]
=
'rb'
conn
=
create_connection
((
'127.0.0.1'
,
16000
))
conn
.
settimeout
(
_DEFAULT
_SOCKET_TIMEOUT
)
conn
.
settimeout
(
greentest
.
DEFAULT_XPC
_SOCKET_TIMEOUT
)
rfile
=
conn
.
makefile
(
**
kwargs
)
welcome
=
rfile
.
readline
()
assert
b'Welcome'
in
welcome
,
repr
(
welcome
)
self
.
assertIn
(
b'Welcome'
,
welcome
)
conn
.
sendall
(
message
)
received
=
rfile
.
read
(
len
(
message
))
...
...
src/greentest/test__server.py
View file @
e012980a
...
...
@@ -6,11 +6,11 @@ import os
import
greentest
from
greentest
import
PY3
from
greentest
import
DEFAULT_SOCKET_TIMEOUT
as
_DEFAULT_SOCKET_TIMEOUT
from
gevent
import
socket
import
gevent
from
gevent.server
import
StreamServer
_DEFAULT_SOCKET_TIMEOUT
=
0.1
if
not
greentest
.
EXPECT_POOR_TIMER_RESOLUTION
else
1.0
class
SimpleStreamServer
(
StreamServer
):
...
...
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