Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
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
shrapnel
Commits
52961ff1
Commit
52961ff1
authored
Jul 08, 2013
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new unit test for socket.accept_many()
pull coro_unittest into this directory
parent
f70fcfc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
test/coro_unittest.py
test/coro_unittest.py
+0
-0
test/test_accept_many.py
test/test_accept_many.py
+67
-0
No files found.
old
/coro_unittest.py
→
test
/coro_unittest.py
View file @
52961ff1
File moved
test/test_accept_many.py
0 → 100644
View file @
52961ff1
# -*- Mode: Python -*-
"""Unittest for socket.accept_many() call."""
import
socket
import
sys
import
unittest
import
coro
import
coro_unittest
do_sleeps
=
False
class
TestServer
:
def
serve
(
self
,
family
,
address
):
self
.
s
=
coro
.
make_socket
(
family
,
socket
.
SOCK_STREAM
)
self
.
s
.
bind
((
address
,
0
))
self
.
port
=
self
.
s
.
getsockname
()[
1
]
self
.
s
.
set_reuse_addr
()
self
.
s
.
listen
(
5
)
while
1
:
try
:
coro
.
write_stderr
(
'accepting...
\
n
'
)
conns
=
self
.
s
.
accept_many
(
5
)
coro
.
write_stderr
(
'...after: conns=%r
\
n
'
%
(
conns
,))
except
coro
.
Shutdown
:
break
for
s
,
addr
in
conns
:
session
=
TestSession
(
s
,
addr
)
coro
.
spawn
(
session
.
run
)
class
TestSession
:
def
__init__
(
self
,
s
,
addr
):
self
.
s
=
s
self
.
addr
=
addr
def
run
(
self
):
self
.
s
.
send
(
'howdy!
\
r
\
n
'
)
self
.
s
.
close
()
class
Test
(
unittest
.
TestCase
):
def
test_accept_many
(
self
):
global
count
server
=
TestServer
()
coro
.
spawn
(
server
.
serve
,
coro
.
AF
.
INET
,
'127.0.0.1'
)
coro
.
yield_slice
()
def
connect
():
s
=
coro
.
make_socket
(
coro
.
AF
.
INET
,
socket
.
SOCK_STREAM
)
coro
.
with_timeout
(
5
,
s
.
connect
,
(
'127.0.0.1'
,
server
.
port
))
howdy
=
coro
.
with_timeout
(
5
,
s
.
recv
,
100
)
self
.
assertEqual
(
howdy
,
'howdy!
\
r
\
n
'
)
count
-=
1
if
count
==
0
:
server_thread
.
raise_exception
(
coro
.
Shutdown
)
coro
.
spawn
(
connect
)
coro
.
spawn
(
connect
)
coro
.
spawn
(
connect
)
count
=
3
if
__name__
==
'__main__'
:
coro_unittest
.
run_tests
()
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