コード例 #1
0
ファイル: test_socket.py プロジェクト: jhsmith/synapse
    def test_sock_plex_txbuf(self):

        # windows sockets seem to allow *huge* buffers in non-blocking
        # so triggering txbuf takes *way* too much ram to be a feasable test
        if s_thishost.get('platform') == 'windows':
            return

        plex = s_socket.Plex()

        s1,s2 = s_socket.socketpair()

        plex.addPlexSock(s2)

        s2.tx( tufo('hi',there='there') )

        self.assertEqual( s1.recvobj()[0], 'hi' )

        s2.tx( tufo('OMG', y='A'*409000) )

        self.assertIsNotNone( s2.txbuf )

        s2.tx( tufo('foo', bar='baz') )

        self.assertEqual( len(s2.txque), 1 )

        m1 = s1.recvobj()
        m2 = s1.recvobj()

        self.assertEqual( len(m1[1].get('y')), 409000 )
        self.assertEqual( m2[0], 'foo' )

        s1.fini()
        s2.fini()

        plex.fini()
コード例 #2
0
ファイル: test_socket.py プロジェクト: dwinings/synapse
    def test_sock_plex(self):

        def onmesg(event):
            sock = event[1].get('sock')
            mesg = event[1].get('mesg')

            sock.tx(tufo('hi:got', mesg=mesg))

        plex = s_socket.Plex()

        s1, s2 = s_socket.socketpair()
        s2.on('link:sock:mesg', onmesg)

        waiter = self.getTestWait(s2, 1, 'link:sock:mesg')

        plex.addPlexSock(s2)

        s1.tx(tufo('hi:there', whee='whee'))

        ret = s1.recvobj()
        mesg = ret[1].get('mesg')

        self.eq(ret[0], 'hi:got')

        s1.fini()
        plex.fini()
コード例 #3
0
ファイル: test_socket.py プロジェクト: jhsmith/synapse
    def test_sock_plex(self):

        def onmesg(event):
            sock = event[1].get('sock')
            mesg = event[1].get('mesg')

            sock.tx( tufo('hi:got', mesg=mesg) )

        plex = s_socket.Plex()

        s1,s2 = s_socket.socketpair()
        s2.on('link:sock:mesg', onmesg)

        waiter = self.getTestWait(s2, 1, 'link:sock:mesg')

        plex.addPlexSock(s2)

        s1.tx( tufo('hi:there', whee='whee') )

        ret = s1.recvobj()
        mesg = ret[1].get('mesg')

        self.assertEqual( ret[0], 'hi:got' )

        s1.fini()
        plex.fini()
コード例 #4
0
    def test_sock_plex_txbuf(self):

        # windows sockets seem to allow *huge* buffers in non-blocking
        # so triggering txbuf takes *way* too much ram to be a feasable test
        if s_thishost.get('platform') == 'windows':
            return

        plex = s_socket.Plex()

        s1, s2 = s_socket.socketpair()

        plex.addPlexSock(s2)

        s2.tx(tufo('hi', there='there'))

        self.assertEqual(s1.recvobj()[0], 'hi')

        s2.tx(tufo('OMG', y='A' * 409000))

        self.assertIsNotNone(s2.txbuf)

        s2.tx(tufo('foo', bar='baz'))

        self.assertEqual(len(s2.txque), 1)

        m1 = s1.recvobj()
        m2 = s1.recvobj()

        self.assertEqual(len(m1[1].get('y')), 409000)
        self.assertEqual(m2[0], 'foo')

        s1.fini()
        s2.fini()

        plex.fini()
コード例 #5
0
ファイル: test_lib_socket.py プロジェクト: thpatel/synapse
    def test_sock_plex_txbuf(self):
        # windows sockets seem to allow *huge* buffers in non-blocking
        # so triggering txbuf takes *way* too much ram to be a feasable test
        if s_thishost.get('platform') == 'windows':
            return

        plex = s_socket.Plex()

        s1, s2 = s_socket.socketpair()

        plex.addPlexSock(s2)
        self.eq(len(plex.getPlexSocks()), 2)

        # the rx socket is a blocking socket which cause calls to
        # rx() to block on the recv() call in the main thread of
        # the python program

        t0 = tufo('hi', there='there')
        t1 = tufo('OMG', y='A' * 409000)
        t2 = tufo('foo', bar='baz')

        s2.tx(t0)
        m0 = s1.recvobj()
        self.eq(m0[0], 'hi')

        # So this is pushing a large message which is going to be
        # transmitted in parts - hence the NEXT assertion statement
        s2.tx(t1)

        self.nn(s2.txbuf)

        s2.tx(t2)

        self.eq(len(s2.txque), 1)

        m1 = s1.recvobj()
        m2 = s1.recvobj()

        self.eq(len(m1[1].get('y')), 409000)
        self.eq(m2[0], 'foo')

        s1.fini()
        s2.fini()
        plex.fini()
コード例 #6
0
    def test_sock_xform(self):
        class Xor(s_socket.SockXform):
            def txform(self, byts):
                return xor(0x56, byts)

            def rxform(self, byts):
                return xor(0x56, byts)

        sock1, sock2 = s_socket.socketpair()

        sock1.sendall(b'woot')

        self.assertEqual(sock2.recvall(4), b'woot')

        xform = Xor()
        sock1.addSockXform(xform)
        sock2.addSockXform(xform)

        sock1.sendall(b'woot')
        self.assertEqual(sock2.recvall(4), b'woot')
コード例 #7
0
    def test_threads_cancelable(self):
        sock1, sock2 = s_socket.socketpair()

        data = []
        def echoloop():
            with s_threads.cancelable(sock1.fini):
                byts = sock1.recv(1024)
                data.append(byts)
                sock1.sendall(byts)

        thr = s_threads.worker(echoloop)

        sock2.sendall(b'hi')
        self.assertEqual( sock2.recv(1024), b'hi')

        thr.fini()
        thr.join()

        sock1.fini()
        sock2.fini()
コード例 #8
0
ファイル: test_lib_threads.py プロジェクト: e2-ibm/synapse
    def test_threads_cancelable(self):
        sock1, sock2 = s_socket.socketpair()

        data = []
        def echoloop():
            with s_threads.cancelable(sock1.fini):
                byts = sock1.recv(1024)
                data.append(byts)
                sock1.sendall(byts)

        thr = s_threads.worker(echoloop)

        sock2.sendall(b'hi')
        self.eq(sock2.recv(1024), b'hi')

        thr.fini()
        thr.join()

        sock1.fini()
        sock2.fini()
コード例 #9
0
ファイル: test_socket.py プロジェクト: jhsmith/synapse
    def test_sock_xform(self):

        class Xor(s_socket.SockXform):
            def txform(self, byts):
                return xor(0x56,byts)

            def rxform(self, byts):
                return xor(0x56,byts)

        sock1,sock2 = s_socket.socketpair()

        sock1.sendall(b'woot')

        self.assertEqual( sock2.recvall(4), b'woot' )

        xform = Xor()
        sock1.addSockXform(xform)
        sock2.addSockXform(xform)

        sock1.sendall(b'woot')
        self.assertEqual( sock2.recvall(4), b'woot' )