offset = random.randint(0, filesize) self.assertRaises(OSError, coro.aio_read, self.fd, size, offset) self.assertEqual(event_size, len(coro.event_map)) def test_error(self): """Test error return.""" fd = os.open('test_aio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC) data = os.urandom(1024 * 1024) r = coro.aio_write(fd, data, 0) self.assertEqual(r, len(data)) self.assertEqual(coro.aio_read(fd, len(data), 0), data) # Rip away the file descriptor. os.close(fd) # Verify it fails. self.assertRaises(oserrors.EBADF, coro.aio_read, fd, len(data), 0) # Try a test that will fail from aio_return. # (NOTE: On FreeBSD before 7, this would actually show up as an # error immediately from aio_error, but in FreeBSD 7 it now appears to # go through the kqueue code path.) soft, hard = resource.getrlimit(resource.RLIMIT_FSIZE) fd = os.open('test_aio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC) self.assertRaises(oserrors.EFBIG, coro.aio_write, fd, data, soft) os.close(fd) if __name__ == '__main__': coro_unittest.run_tests()
self._fired_blocker_socket.close() _fired_blocker_socket = None def test_fired(self): s = coro.tcp_sock() s.connect(('127.0.0.1', self.port)) self._fired_blocker_socket = s # We need to somehow schedule two threads to both wake up on kevent at # the same time in a particular order. The first one will call close # on the socket of the second one. f = open('test_fire', 'w') coro.set_handler((f.fileno(), coro.EVFILT.VNODE), self._fired_closer, fflags=coro.NOTE.DELETE ) t2 = coro.spawn(self._fired_blocker) #t2.set_max_selfish_acts(1) # Yield to allow fired blocker to block. coro.yield_slice() # Now, cause threads blocked on kevents to get scheduled in a specific # order. os.unlink('test_fire') s.send('force send') # Let those threads run. coro.yield_slice() if __name__ == '__main__': coro_unittest.run_tests()