Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
test.test_epoll.TestEPoll Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_create
def test_badcreate
def test_add
def test_fromfd
def test_control_and_wait
def test_errors
def test_unregister_closed

Public Attributes

 serverSocket
 connections

Private Member Functions

def _connected_pair

Detailed Description

Definition at line 40 of file test_epoll.py.


Member Function Documentation

Definition at line 53 of file test_epoll.py.

00053 
00054     def _connected_pair(self):
00055         client = socket.socket()
00056         client.setblocking(False)
00057         try:
00058             client.connect(('127.0.0.1', self.serverSocket.getsockname()[1]))
00059         except socket.error as e:
00060             self.assertEqual(e.args[0], errno.EINPROGRESS)
00061         else:
00062             raise AssertionError("Connect should have raised EINPROGRESS")
00063         server, addr = self.serverSocket.accept()
00064 
00065         self.connections.extend((client, server))
00066         return client, server

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 42 of file test_epoll.py.

00042 
00043     def setUp(self):
00044         self.serverSocket = socket.socket()
00045         self.serverSocket.bind(('127.0.0.1', 0))
00046         self.serverSocket.listen(1)
00047         self.connections = [self.serverSocket]
00048 

Here is the caller graph for this function:

Definition at line 49 of file test_epoll.py.

00049 
00050     def tearDown(self):
00051         for skt in self.connections:
00052             skt.close()

Here is the caller graph for this function:

Definition at line 86 of file test_epoll.py.

00086 
00087     def test_add(self):
00088         server, client = self._connected_pair()
00089 
00090         ep = select.epoll(2)
00091         try:
00092             ep.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
00093             ep.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)
00094         finally:
00095             ep.close()
00096 
00097         # adding by object w/ fileno works, too.
00098         ep = select.epoll(2)
00099         try:
00100             ep.register(server, select.EPOLLIN | select.EPOLLOUT)
00101             ep.register(client, select.EPOLLIN | select.EPOLLOUT)
00102         finally:
00103             ep.close()
00104 
00105         ep = select.epoll(2)
00106         try:
00107             # TypeError: argument must be an int, or have a fileno() method.
00108             self.assertRaises(TypeError, ep.register, object(),
00109                 select.EPOLLIN | select.EPOLLOUT)
00110             self.assertRaises(TypeError, ep.register, None,
00111                 select.EPOLLIN | select.EPOLLOUT)
00112             # ValueError: file descriptor cannot be a negative integer (-1)
00113             self.assertRaises(ValueError, ep.register, -1,
00114                 select.EPOLLIN | select.EPOLLOUT)
00115             # IOError: [Errno 9] Bad file descriptor
00116             self.assertRaises(IOError, ep.register, 10000,
00117                 select.EPOLLIN | select.EPOLLOUT)
00118             # registering twice also raises an exception
00119             ep.register(server, select.EPOLLIN | select.EPOLLOUT)
00120             self.assertRaises(IOError, ep.register, server,
00121                 select.EPOLLIN | select.EPOLLOUT)
00122         finally:
00123             ep.close()

Here is the call graph for this function:

Definition at line 78 of file test_epoll.py.

00078 
00079     def test_badcreate(self):
00080         self.assertRaises(TypeError, select.epoll, 1, 2, 3)
00081         self.assertRaises(TypeError, select.epoll, 'foo')
00082         self.assertRaises(TypeError, select.epoll, None)
00083         self.assertRaises(TypeError, select.epoll, ())
00084         self.assertRaises(TypeError, select.epoll, ['foo'])
00085         self.assertRaises(TypeError, select.epoll, {})

Here is the call graph for this function:

Definition at line 146 of file test_epoll.py.

00146 
00147     def test_control_and_wait(self):
00148         client, server = self._connected_pair()
00149 
00150         ep = select.epoll(16)
00151         ep.register(server.fileno(),
00152                    select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
00153         ep.register(client.fileno(),
00154                    select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
00155 
00156         now = time.time()
00157         events = ep.poll(1, 4)
00158         then = time.time()
00159         self.assertFalse(then - now > 0.1, then - now)
00160 
00161         events.sort()
00162         expected = [(client.fileno(), select.EPOLLOUT),
00163                     (server.fileno(), select.EPOLLOUT)]
00164         expected.sort()
00165 
00166         self.assertEqual(events, expected)
00167         self.assertFalse(then - now > 0.01, then - now)
00168 
00169         now = time.time()
00170         events = ep.poll(timeout=2.1, maxevents=4)
00171         then = time.time()
00172         self.assertFalse(events)
00173 
00174         client.send(b"Hello!")
00175         server.send(b"world!!!")
00176 
00177         now = time.time()
00178         events = ep.poll(1, 4)
00179         then = time.time()
00180         self.assertFalse(then - now > 0.01)
00181 
00182         events.sort()
00183         expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
00184                     (server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
00185         expected.sort()
00186 
00187         self.assertEqual(events, expected)
00188 
00189         ep.unregister(client.fileno())
00190         ep.modify(server.fileno(), select.EPOLLOUT)
00191         now = time.time()
00192         events = ep.poll(1, 4)
00193         then = time.time()
00194         self.assertFalse(then - now > 0.01)
00195 
00196         expected = [(server.fileno(), select.EPOLLOUT)]
00197         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 67 of file test_epoll.py.

00067 
00068     def test_create(self):
00069         try:
00070             ep = select.epoll(16)
00071         except OSError as e:
00072             raise AssertionError(str(e))
00073         self.assertTrue(ep.fileno() > 0, ep.fileno())
00074         self.assertTrue(not ep.closed)
00075         ep.close()
00076         self.assertTrue(ep.closed)
00077         self.assertRaises(ValueError, ep.fileno)

Here is the call graph for this function:

Definition at line 198 of file test_epoll.py.

00198 
00199     def test_errors(self):
00200         self.assertRaises(ValueError, select.epoll, -2)
00201         self.assertRaises(ValueError, select.epoll().register, -1,
00202                           select.EPOLLIN)

Here is the call graph for this function:

Definition at line 124 of file test_epoll.py.

00124 
00125     def test_fromfd(self):
00126         server, client = self._connected_pair()
00127 
00128         ep = select.epoll(2)
00129         ep2 = select.epoll.fromfd(ep.fileno())
00130 
00131         ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
00132         ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)
00133 
00134         events = ep.poll(1, 4)
00135         events2 = ep2.poll(0.9, 4)
00136         self.assertEqual(len(events), 2)
00137         self.assertEqual(len(events2), 2)
00138 
00139         ep.close()
00140         try:
00141             ep2.poll(1, 4)
00142         except IOError as e:
00143             self.assertEqual(e.args[0], errno.EBADF, e)
00144         else:
00145             self.fail("epoll on closed fd didn't raise EBADF")

Here is the call graph for this function:

Definition at line 203 of file test_epoll.py.

00203 
00204     def test_unregister_closed(self):
00205         server, client = self._connected_pair()
00206         fd = server.fileno()
00207         ep = select.epoll(16)
00208         ep.register(server)
00209 
00210         now = time.time()
00211         events = ep.poll(1, 4)
00212         then = time.time()
00213         self.assertFalse(then - now > 0.01)
00214 
00215         server.close()
00216         ep.unregister(fd)

Here is the call graph for this function:


Member Data Documentation

Definition at line 46 of file test_epoll.py.

Definition at line 43 of file test_epoll.py.


The documentation for this class was generated from the following file: