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
0cc85ac2
Commit
0cc85ac2
authored
Nov 02, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__http.py: make the test cases pass totalrefcount check
parent
25fa1c14
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
29 deletions
+27
-29
greentest/test__http.py
greentest/test__http.py
+27
-29
No files found.
greentest/test__http.py
View file @
0cc85ac2
...
...
@@ -3,9 +3,9 @@ import gevent
from
gevent
import
http
import
greentest
import
os
from
urllib2
import
urlopen
,
HTTPError
import
socket
import
errno
from
test__pywsgi
import
read_http
# add test for "chunked POST input -> chunked output"
...
...
@@ -15,6 +15,7 @@ class BoundTestCase(greentest.TestCase):
address
=
(
'127.0.0.1'
,
0
)
def
setUp
(
self
):
greentest
.
TestCase
.
setUp
(
self
)
self
.
server
=
http
.
HTTPServer
(
self
.
address
,
self
.
handle
)
self
.
server
.
start
()
...
...
@@ -25,23 +26,23 @@ class BoundTestCase(greentest.TestCase):
self
.
server
.
stop
()
finally
:
timeout
.
cancel
()
#self.print_netstat('after stop')
self
.
check_refused
()
greentest
.
TestCase
.
tearDown
(
self
)
def
print_netstat
(
self
,
comment
=
''
):
cmd
=
'sudo netstat -anp | grep %s'
%
self
.
server
.
server_port
print
cmd
,
' # %s'
%
comment
cmd
=
'echo "%s" && netstat -anp 2>&1 | grep %s'
%
(
comment
,
self
.
server
.
server_port
)
os
.
system
(
cmd
)
@
property
def
url
(
self
):
return
'http://%s:%s'
%
(
self
.
server
.
server_host
,
self
.
server
.
server_port
)
def
connect
(
self
):
s
=
socket
.
socket
()
s
.
connect
((
self
.
server
.
server_host
,
self
.
server
.
server_port
))
return
s
def
urlopen
(
self
,
*
args
,
**
kwargs
):
fd
=
self
.
connect
().
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
return
read_http
(
fd
,
*
args
,
**
kwargs
)
def
check_refused
(
self
):
try
:
self
.
connect
()
...
...
@@ -52,6 +53,15 @@ class BoundTestCase(greentest.TestCase):
print
'WARNING: instead of ECONNREFUSED got IOError: %s'
%
e
class
TestNoop
(
BoundTestCase
):
def
handle
(
self
,
r
):
pass
def
test
(
self
):
self
.
urlopen
(
code
=
500
)
class
TestClientCloses
(
BoundTestCase
):
# this test is useless. currently there's no way to know that the client closed the connection,
...
...
@@ -87,14 +97,16 @@ class TestStop(BoundTestCase):
return
gevent
.
spawn_later
(
0.01
,
self
.
reply
,
r
)
def
test
(
self
):
server
=
http
.
HTTPServer
(
self
.
address
,
self
.
handle
)
server
.
start
()
s
=
self
.
connect
()
s
.
sendall
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
s
.
sendall
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
s
.
close
()
se
lf
.
se
rver
.
stop
()
server
.
stop
()
gevent
.
sleep
(
0.02
)
# stopping what already stopped is OK
se
lf
.
se
rver
.
stop
()
server
.
stop
()
class
TestSendReply
(
BoundTestCase
):
...
...
@@ -103,11 +115,7 @@ class TestSendReply(BoundTestCase):
r
.
send_reply
(
200
,
'OK'
,
'hello world'
)
def
test
(
self
):
response
=
urlopen
(
self
.
url
)
assert
response
.
code
==
200
,
response
assert
response
.
msg
==
'OK'
,
response
data
=
response
.
read
()
assert
data
==
'hello world'
,
data
self
.
urlopen
(
body
=
'hello world'
)
def
test_keepalive
(
self
):
s
=
self
.
connect
()
...
...
@@ -121,11 +129,7 @@ class TestException(BoundTestCase):
raise
greentest
.
ExpectedException
(
'TestException.handle'
)
def
test
(
self
):
try
:
urlopen
(
self
.
url
)
except
HTTPError
,
e
:
assert
e
.
code
==
500
,
e
assert
e
.
msg
==
'Internal Server Error'
,
e
self
.
urlopen
(
code
=
500
)
class
TestSendReplyLater
(
BoundTestCase
):
...
...
@@ -135,13 +139,7 @@ class TestSendReplyLater(BoundTestCase):
r
.
send_reply
(
200
,
'OK'
,
'hello world'
)
def
test
(
self
):
response
=
urlopen
(
self
.
url
)
#print 'connected to %s' % self.url
assert
response
.
code
==
200
,
response
assert
response
.
msg
==
'OK'
,
response
data
=
response
.
read
()
#print 'read data from %s' % self.url
assert
data
==
'hello world'
,
data
self
.
urlopen
(
body
=
'hello world'
)
def
test_client_closes_10
(
self
):
s
=
self
.
connect
()
...
...
@@ -171,13 +169,13 @@ class TestDetach(BoundTestCase):
assert
input
.
read
()
==
''
assert
output
.
read
()
==
''
self
.
handled
=
True
self
.
current
.
throw
(
Exception
(
'test done'
))
gevent
.
kill
(
self
.
current
,
Exception
(
'test done'
))
def
test
(
self
):
self
.
current
=
gevent
.
getcurrent
()
try
:
try
:
urlopen
(
self
.
url
)
self
.
urlopen
(
)
except
Exception
,
ex
:
assert
str
(
ex
)
==
'test done'
,
ex
finally
:
...
...
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