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
23d4f62a
Commit
23d4f62a
authored
Jul 14, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the tests with regard to the lates socket changes (no makeGreenFile() method anymore)
parent
9967fdb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
86 deletions
+70
-86
greentest/api_test.py
greentest/api_test.py
+5
-5
greentest/greenio_test.py
greentest/greenio_test.py
+15
-12
greentest/wsgi_test.py
greentest/wsgi_test.py
+50
-69
No files found.
greentest/api_test.py
View file @
23d4f62a
...
...
@@ -44,7 +44,7 @@ class TestApi(TestCase):
def
accept_once
(
listenfd
):
try
:
conn
,
addr
=
listenfd
.
accept
()
fd
=
conn
.
make
GreenF
ile
()
fd
=
conn
.
make
f
ile
()
conn
.
close
()
fd
.
write
(
'hello
\
n
'
)
fd
.
close
()
...
...
@@ -55,7 +55,7 @@ class TestApi(TestCase):
g
=
gevent
.
spawn
(
accept_once
,
server
)
try
:
client
=
socket
.
connect_tcp
((
'127.0.0.1'
,
server
.
getsockname
()[
1
]))
fd
=
client
.
make
GreenF
ile
()
fd
=
client
.
make
f
ile
()
client
.
close
()
assert
fd
.
readline
()
==
'hello
\
n
'
assert
fd
.
read
()
==
''
...
...
@@ -67,7 +67,7 @@ class TestApi(TestCase):
def
accept_once
(
listenfd
):
try
:
conn
,
addr
=
listenfd
.
accept
()
fl
=
conn
.
make
GreenF
ile
(
'w'
)
fl
=
conn
.
make
f
ile
(
'w'
)
fl
.
write
(
'hello
\
r
\
n
'
)
fl
.
close
()
conn
.
close
()
...
...
@@ -79,7 +79,7 @@ class TestApi(TestCase):
client
=
socket
.
wrap_ssl
(
socket
.
connect_tcp
((
'127.0.0.1'
,
server
.
getsockname
()[
1
])))
client
=
client
.
make
GreenF
ile
()
client
=
client
.
make
f
ile
()
assert
client
.
readline
()
==
'hello
\
r
\
n
'
assert
client
.
read
()
==
''
...
...
@@ -154,7 +154,7 @@ class TestApi(TestCase):
finally
:
gevent
.
sleep
(
0
)
def
test_timeout_and_final_write
(
self
):
def
XXX_
test_timeout_and_final_write
(
self
):
# This test verifies that a write on a socket that we've
# stopped listening for doesn't result in an incorrect switch
rpipe
,
wpipe
=
os
.
pipe
()
...
...
greentest/greenio_test.py
View file @
23d4f62a
...
...
@@ -28,11 +28,12 @@ class TestGreenIo(TestCase):
# by closing the socket prior to using the made file
try
:
conn
,
addr
=
listener
.
accept
()
fd
=
conn
.
make
GreenF
ile
()
fd
=
conn
.
make
f
ile
()
conn
.
close
()
fd
.
write
(
'hello
\
n
'
)
fd
.
close
()
self
.
assertRaises
(
socket
.
error
,
fd
.
write
,
'a'
)
r
=
fd
.
write
(
'a'
)
assert
r
is
None
,
r
self
.
assertRaises
(
socket
.
error
,
conn
.
send
,
'b'
)
finally
:
listener
.
close
()
...
...
@@ -42,33 +43,34 @@ class TestGreenIo(TestCase):
# by closing the made file and then sending a character
try
:
conn
,
addr
=
listener
.
accept
()
fd
=
conn
.
make
GreenF
ile
()
fd
=
conn
.
make
f
ile
()
fd
.
write
(
'hello'
)
fd
.
close
()
conn
.
send
(
'
\
n
'
)
conn
.
close
()
self
.
assertRaises
(
socket
.
error
,
fd
.
write
,
'a'
)
r
=
fd
.
write
(
'a'
)
assert
r
is
None
,
r
self
.
assertRaises
(
socket
.
error
,
conn
.
send
,
'b'
)
finally
:
listener
.
close
()
def
did_it_work
(
server
):
client
=
socket
.
connect_tcp
((
'127.0.0.1'
,
server
.
getsockname
()[
1
]))
fd
=
client
.
make
GreenF
ile
()
fd
=
client
.
make
f
ile
()
client
.
close
()
assert
fd
.
readline
()
==
'hello
\
n
'
assert
fd
.
read
()
==
''
fd
.
close
()
server
=
socket
.
tcp_listener
((
'0.0.0.0'
,
0
))
killer
=
gevent
.
spawn
(
accept_close_early
,
server
)
server_greenlet
=
gevent
.
spawn
(
accept_close_early
,
server
)
did_it_work
(
server
)
gevent
.
kill
(
killer
)
gevent
.
kill
(
server_greenlet
,
wait
=
True
)
server
=
socket
.
tcp_listener
((
'0.0.0.0'
,
0
))
killer
=
gevent
.
spawn
(
accept_close_late
,
server
)
server_greenlet
=
gevent
.
spawn
(
accept_close_late
,
server
)
did_it_work
(
server
)
gevent
.
kill
(
killer
)
gevent
.
kill
(
server_greenlet
,
wait
=
True
)
def
test_del_closes_socket
(
self
):
...
...
@@ -79,16 +81,17 @@ class TestGreenIo(TestCase):
# closing the file object should close everything
try
:
conn
,
addr
=
listener
.
accept
()
conn
=
conn
.
make
GreenF
ile
()
conn
=
conn
.
make
f
ile
()
conn
.
write
(
'hello
\
n
'
)
conn
.
close
()
self
.
assertRaises
(
socket
.
error
,
conn
.
write
,
'a'
)
r
=
conn
.
write
(
'a'
)
assert
r
is
None
,
r
finally
:
listener
.
close
()
server
=
socket
.
tcp_listener
((
'0.0.0.0'
,
0
))
killer
=
gevent
.
spawn
(
accept_once
,
server
)
client
=
socket
.
connect_tcp
((
'127.0.0.1'
,
server
.
getsockname
()[
1
]))
fd
=
client
.
make
GreenF
ile
()
fd
=
client
.
make
f
ile
()
client
.
close
()
assert
fd
.
read
()
==
'hello
\
n
'
assert
fd
.
read
()
==
''
...
...
greentest/wsgi_test.py
View file @
23d4f62a
...
...
@@ -102,18 +102,26 @@ class ConnectionClosed(Exception):
pass
def
read_http
(
sock
):
fd
=
sock
.
makeGreenFile
()
def
read_headers
(
fd
):
response_line
=
fd
.
readline
()
if
not
response_line
:
raise
ConnectionClosed
raw_headers
=
fd
.
readuntil
(
'
\
r
\
n
\
r
\
n
'
).
strip
()
#print "R", response_line, raw_headers
headers
=
dict
()
for
x
in
raw_headers
.
split
(
'
\
r
\
n
'
):
#print "X", x
key
,
value
=
x
.
split
(
': '
,
1
)
headers
=
{}
while
True
:
line
=
fd
.
readline
().
strip
()
if
not
line
:
break
try
:
key
,
value
=
line
.
split
(
': '
,
1
)
except
:
print
'bad line:'
,
`line`
raise
headers
[
key
.
lower
()]
=
value
return
response_line
,
headers
def
read_http
(
fd
):
response_line
,
headers
=
read_headers
(
fd
)
if
CONTENT_LENGTH
in
headers
:
num
=
int
(
headers
[
CONTENT_LENGTH
])
...
...
@@ -140,30 +148,24 @@ class TestHttpd(TestCase):
def
test_001_server
(
self
):
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
.
write
(
'GET / HTTP/1.0
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
result
=
fd
.
read
()
fd
.
close
()
sock
.
sendall
(
'GET / HTTP/1.0
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
result
=
sock
.
makefile
().
read
()
sock
.
close
()
## The server responds with the maximum version it supports
self
.
assert_
(
result
.
startswith
(
'HTTP'
),
result
)
self
.
assert_
(
result
.
endswith
(
'hello world'
))
def
test_002_keepalive
(
self
):
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
read_http
(
sock
)
read_http
(
fd
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
read_http
(
sock
)
read_http
(
fd
)
fd
.
close
()
def
test_003_passing_non_int_to_read
(
self
):
# This should go in greenio_test
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
cancel
=
gevent
.
Timeout
(
1
,
RuntimeError
)
self
.
assertRaises
(
TypeError
,
fd
.
read
,
"This shouldn't work"
)
...
...
@@ -171,15 +173,13 @@ class TestHttpd(TestCase):
fd
.
close
()
def
test_004_close_keepalive
(
self
):
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
read_http
(
sock
)
read_http
(
fd
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
read_http
(
sock
)
read_http
(
fd
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
self
.
assertRaises
(
ConnectionClosed
,
read_http
,
sock
)
self
.
assertRaises
(
ConnectionClosed
,
read_http
,
fd
)
fd
.
close
()
def
skip_test_005_run_apachebench
(
self
):
...
...
@@ -191,13 +191,12 @@ class TestHttpd(TestCase):
print
out
.
read
()
def
test_006_reject_long_urls
(
self
):
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)
)
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
path_parts
=
[]
for
ii
in
range
(
3000
):
path_parts
.
append
(
'path'
)
path
=
'/'
.
join
(
path_parts
)
request
=
'GET /%s HTTP/1.0
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
%
path
fd
=
sock
.
makeGreenFile
()
fd
.
write
(
request
)
result
=
fd
.
readline
()
status
=
result
.
split
(
' '
)[
1
]
...
...
@@ -212,64 +211,50 @@ class TestHttpd(TestCase):
start_response
(
'200 OK'
,
[(
'Content-type'
,
'text/plain'
)])
return
[
'a is %s, body is %s'
%
(
a
,
body
)]
self
.
site
.
application
=
new_app
sock
=
socket
.
connect_tcp
(
(
'127.0.0.1'
,
12346
))
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
request
=
'
\
r
\
n
'
.
join
((
'POST / HTTP/1.0'
,
'Host: localhost'
,
'Content-Length: 3'
,
''
,
'a=a'
))
fd
=
sock
.
makeGreenFile
()
fd
.
write
(
request
)
# send some junk after the actual request
fd
.
write
(
'01234567890123456789'
)
reqline
,
headers
,
body
=
read_http
(
sock
)
reqline
,
headers
,
body
=
read_http
(
fd
)
self
.
assertEqual
(
body
,
'a is a, body is a=a'
)
fd
.
close
()
def
test_008_correctresponse
(
self
):
sock
=
socket
.
connect_tcp
(
(
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
response_line_200
,
_
,
_
=
read_http
(
sock
)
response_line_200
,
_
,
_
=
read_http
(
fd
)
fd
.
write
(
'GET /notexist HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
response_line_404
,
_
,
_
=
read_http
(
sock
)
response_line_404
,
_
,
_
=
read_http
(
fd
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
\
r
\
n
'
)
response_line_test
,
_
,
_
=
read_http
(
sock
)
response_line_test
,
_
,
_
=
read_http
(
fd
)
self
.
assertEqual
(
response_line_200
,
response_line_test
)
fd
.
close
()
def
test_009_chunked_response
(
self
):
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
self
.
site
.
application
=
chunked_app
sock
=
socket
.
connect_tcp
(
(
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
self
.
assert_
(
'Transfer-Encoding: chunked'
in
fd
.
read
())
def
test_010_no_chunked_http_1_0
(
self
):
self
.
site
.
application
=
chunked_app
sock
=
socket
.
connect_tcp
(
(
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.0
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
self
.
assert_
(
'Transfer-Encoding: chunked'
not
in
fd
.
read
())
def
test_011_multiple_chunks
(
self
):
self
.
site
.
application
=
big_chunks
sock
=
socket
.
connect_tcp
(
(
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
headers
=
fd
.
readuntil
(
'
\
r
\
n
\
r
\
n
'
)
self
.
assert_
(
'Transfer-Encoding: chunked'
in
headers
)
_
,
headers
=
read_headers
(
fd
)
assert
(
'transfer-encoding'
,
'chunked'
)
in
headers
.
items
(),
headers
chunks
=
0
chunklen
=
int
(
fd
.
readline
(),
16
)
while
chunklen
:
...
...
@@ -281,45 +266,41 @@ class TestHttpd(TestCase):
def
test_014_chunked_post
(
self
):
self
.
site
.
application
=
chunked_post
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'PUT /a HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
'
'Transfer-Encoding: chunked
\
r
\
n
\
r
\
n
'
'2
\
r
\
n
oh
\
r
\
n
4
\
r
\
n
hai
\
r
\
n
0
\
r
\
n
\
r
\
n
'
)
fd
.
readuntil
(
'
\
r
\
n
\
r
\
n
'
)
read_headers
(
fd
)
response
=
fd
.
read
()
self
.
assert_
(
response
==
'oh hai'
,
'invalid response %s'
%
response
)
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'PUT /b HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
'
'Transfer-Encoding: chunked
\
r
\
n
\
r
\
n
'
'2
\
r
\
n
oh
\
r
\
n
4
\
r
\
n
hai
\
r
\
n
0
\
r
\
n
\
r
\
n
'
)
fd
.
readuntil
(
'
\
r
\
n
\
r
\
n
'
)
read_headers
(
fd
)
response
=
fd
.
read
()
self
.
assert_
(
response
==
'oh hai'
,
'invalid response %s'
%
response
)
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'PUT /c HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
'
'Transfer-Encoding: chunked
\
r
\
n
\
r
\
n
'
'2
\
r
\
n
oh
\
r
\
n
4
\
r
\
n
hai
\
r
\
n
0
\
r
\
n
\
r
\
n
'
)
fd
.
readuntil
(
'
\
r
\
n
\
r
\
n
'
)
#fd.readuntil('\r\n\r\n')
read_headers
(
fd
)
response
=
fd
.
read
(
8192
)
self
.
assert_
(
response
==
'oh hai'
,
'invalid response %s'
%
response
)
def
test_015_write
(
self
):
self
.
site
.
application
=
use_write
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET /a HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
response_line
,
headers
,
body
=
read_http
(
sock
)
response_line
,
headers
,
body
=
read_http
(
fd
)
self
.
assert_
(
'content-length'
in
headers
)
sock
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
))
fd
=
sock
.
makeGreenFile
()
fd
=
socket
.
connect_tcp
((
'127.0.0.1'
,
12346
)).
makefile
(
bufsize
=
1
)
fd
.
write
(
'GET /b HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Connection: close
\
r
\
n
\
r
\
n
'
)
response_line
,
headers
,
body
=
read_http
(
sock
)
response_line
,
headers
,
body
=
read_http
(
fd
)
self
.
assert_
(
'transfer-encoding'
in
headers
)
self
.
assert_
(
headers
[
'transfer-encoding'
]
==
'chunked'
)
...
...
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