Source

pypy / pypy / module / transaction / test / test_epoll.py

import py
from pypy.conftest import gettestobjspace


class AppTestEpoll: 
    def setup_class(cls):
        cls.space = gettestobjspace(usemodules=['transaction', 'select'])

    def test_non_transactional(self):
        import select, posix as os
        fd_read, fd_write = os.pipe()
        epoller = select.epoll()
        epoller.register(fd_read)
        os.write(fd_write, 'x')
        [(fd, events)] = epoller.poll()
        assert fd == fd_read
        assert events & select.EPOLLIN
        got = os.read(fd_read, 1)
        assert got == 'x'

    def test_simple(self):
        import transaction, select, posix as os

        steps = []

        fd_read, fd_write = os.pipe()

        epoller = select.epoll()
        epoller.register(fd_read)

        def write_stuff():
            os.write(fd_write, 'x')
            steps.append('write_stuff')

        class Done(Exception):
            pass

        def callback(fd, events):
            assert fd == fd_read
            assert events & select.EPOLLIN
            got = os.read(fd_read, 1)
            assert got == 'x'
            steps.append('callback')
            raise Done

        transaction.add_epoll(epoller, callback)
        transaction.add(write_stuff)

        assert steps == []
        raises(Done, transaction.run)
        assert steps == ['write_stuff', 'callback']


class AppTestEpollEmulator(AppTestEpoll):
    def setup_class(cls):
        # test for lib_pypy/transaction.py
        cls.space = gettestobjspace(usemodules=['select'])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.