コード例 #1
0
 def workspace(self):
     try:
         return self._workspace
     except AttributeError:
         self._workspace = Workspace()
         self.addCleanup(self._workspace.cleanup)
         return self._workspace
コード例 #2
0
ファイル: test_live_pydevd.py プロジェクト: 42B/ptvsd
 def workspace(self):
     try:
         return vars(self)['_workspace']
         #return self._workspace
     except KeyError:
         self._workspace = Workspace()
         self.addCleanup(self._workspace.cleanup)
         return self._workspace
コード例 #3
0
 def setUp(self):
     super(RawConnectionTests, self).setUp()
     self.workspace = Workspace()
     self.addCleanup(self.workspace.cleanup)
コード例 #4
0
class RawConnectionTests(unittest.TestCase):

    VERBOSE = False

    #VERBOSE = True

    def setUp(self):
        super(RawConnectionTests, self).setUp()
        self.workspace = Workspace()
        self.addCleanup(self.workspace.cleanup)

    def _propagate_verbose(self):
        if not self.VERBOSE:
            return

        def unset():
            Proc.VERBOSE = False
            ptvsd._util.DEBUG = False

        self.addCleanup(unset)
        Proc.VERBOSE = True
        ptvsd._util.DEBUG = True

    def _wait_for_ready(self, rpipe):
        if self.VERBOSE:
            print('waiting for ready')
        line = b''
        while True:
            c = os.read(rpipe, 1)
            line += c
            if c == b'\n':
                if self.VERBOSE:
                    print(line.decode('utf-8'), end='')
                if b'getting session socket' in line:
                    break
                line = b''

    @unittest.skip('there is a race here under travis')
    def test_repeated(self):
        def debug(msg):
            if not self.VERBOSE:
                return
            print(msg)

        def connect(addr, wait=None, closeonly=False):
            sock = create_client()
            try:
                sock.settimeout(1)
                sock.connect(addr)
                debug('>connected')
                if wait is not None:
                    debug('>waiting')
                    time.sleep(wait)
            finally:
                debug('>closing')
                if closeonly:
                    sock.close()
                else:
                    close_socket(sock)

        filename = self.workspace.write('spam.py',
                                        content="""
            raise Exception('should never run')
            """)
        addr = ('localhost', 5678)
        self._propagate_verbose()
        rpipe, wpipe = os.pipe()
        self.addCleanup(lambda: os.close(rpipe))
        self.addCleanup(lambda: os.close(wpipe))
        proc = Proc.start_python_module('ptvsd', [
            '--server',
            '--wait',
            '--port',
            '5678',
            '--file',
            filename,
        ],
                                        env={
                                            'PTVSD_DEBUG': '1',
                                            'PTVSD_SOCKET_TIMEOUT': '1',
                                        },
                                        stdout=wpipe)
        with proc:
            # Wait for the server to spin up.
            debug('>a')
            with _retrier(timeout=3, verbose=self.VERBOSE) as attempts:
                for _ in attempts:
                    try:
                        connect(addr)
                        break
                    except Exception:
                        pass
            self._wait_for_ready(rpipe)
            debug('>b')
            connect(addr)
            self._wait_for_ready(rpipe)
            # We should be able to handle more connections.
            debug('>c')
            connect(addr)
            self._wait_for_ready(rpipe)
            # Give ptvsd long enough to try sending something.
            debug('>d')
            connect(addr, wait=0.2)
            self._wait_for_ready(rpipe)
            debug('>e')
            connect(addr)
            self._wait_for_ready(rpipe)
            debug('>f')
            connect(addr, closeonly=True)
            self._wait_for_ready(rpipe)
            debug('>g')
            connect(addr)
            self._wait_for_ready(rpipe)
            debug('>h')
            connect(addr)
            self._wait_for_ready(rpipe)