コード例 #1
0
    def test_no_deadlock(self):
        self.url.path = b'/client_close/engine.io/'
        engineio, handler = self._mkengineio()

        yield engineio.start()

        ping_ds = []

        for _ in range(10):
            ping_ds.append(engineio.sendeiopacket(EIO_TYPE_PING, 'probe'))

        for ping_d in ping_ds:
            yield txrc.deferredtimeout(reactor, 10, ping_d)

        yield engineio.stop()

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(engineio.running)
        self.assertIsNone(engineio._transport_context.session_id) # pylint: disable=protected-access

        call_args_list = [ i for i in handler.call_args_list if i[0][0] not in ( 'noop', 'pong' ) ]

        expected = [
            mock.call('open'),
        ]

        self.assertEqual(call_args_list[0], expected[0])
コード例 #2
0
    def test_echo_ack(self):
        self.url.path = b'/echo_ack/socket.io/'
        socketio, handler = self._mksocketio()

        yield socketio.start()
        self.assertTrue(socketio.running)

        callback_d = t_defer.Deferred()

        def _callback(path, *args, **kw):
            callback_d.callback(( path, args, kw ))

        yield socketio.emit('msg', 'Hey')
        yield socketio.emit('msg', 'you')
        yield socketio.emit('msg', 'guys!', callback=_callback)
        yield txrc.deferredtimeout(reactor, 5, callback_d)
        self.assertTrue(callback_d.called)
        self.assertEqual(callback_d.result, ( '/', ( [], ), {} ))

        yield socketio.stop()
        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(socketio.running)

        self.assertGreaterEqual(len(handler.call_args_list), 4)
        self.assertIn(mock.call('open'), handler.call_args_list)
        self.assertIn(mock.call('connect', '/', ''), handler.call_args_list)
        self.assertIn(mock.call('event', '/', [ 'msg', 'Hey' ]), handler.call_args_list)
        self.assertIn(mock.call('event', '/', [ 'msg', 'you' ]), handler.call_args_list)
        self.assertIn(mock.call('event', '/', [ 'msg', 'guys!' ]), handler.call_args_list)
        self.assertIn(mock.call('ack', '/', []), handler.call_args_list)
        self.assertIn(mock.call('close'), handler.call_args_list)
コード例 #3
0
    def test_close_packet_after_started_delay(self):
        self.url.path = b'/client_close/engine.io/'
        engineio, handler = self._mkengineio()

        def _sendclose(event): # pylint: disable=unused-argument
            reactor.callLater(1, engineio.sendeiopacket, EIO_TYPE_CLOSE)

        engineio.register('open', _sendclose)

        yield engineio.start()
        self.assertTrue(engineio.running)

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(engineio.running)
        self.assertIsNone(engineio._transport_context.session_id) # pylint: disable=protected-access

        call_args_list = [ i for i in handler.call_args_list if i[0][0] not in ( 'noop', 'pong' ) ]

        expected = [
            mock.call('open'),
            mock.call('message', b'Hello!'),
            mock.call('close'),
        ]

        self.assertEqual(call_args_list, expected)
コード例 #4
0
    def test_close_packet_after_upgrade_to_self(self):
        self.url.path = b'/client_close/engine.io/'
        tc = TransportContext(self.url)
        connect_d = self.transport.connect(tc)
        self.assertIn(self.transport.state, ( TRANSPORT_STATE_CONNECTING, TRANSPORT_STATE_CONNECTED ))

        yield connect_d
        self.assertEqual(self.transport.state, TRANSPORT_STATE_CONNECTED)
        self.assertIsNotNone(tc.session_id)

        disconnect_d = self.transport.standby()
        self.assertIn(self.transport.state, ( TRANSPORT_STATE_DISCONNECTED, TRANSPORT_STATE_DISCONNECTING ))

        yield disconnect_d
        self.assertEqual(self.transport.state, TRANSPORT_STATE_DISCONNECTED)
        self.assertIsNotNone(tc.session_id)

        old_session_id = tc.session_id
        connect_d = self.transport.connect(tc)
        self.assertIn(self.transport.state, ( TRANSPORT_STATE_CONNECTING, TRANSPORT_STATE_RECEIVING ))

        yield connect_d
        self.assertEqual(self.transport.state, TRANSPORT_STATE_RECEIVING)
        self.assertEqual(tc.session_id, old_session_id)

        send_d = self.transport.sendpacket(EIO_TYPE_CLOSE, '')
        yield send_d

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertEqual(self.transport.state, TRANSPORT_STATE_DISCONNECTED)
        self.assertIsNone(tc.session_id)
コード例 #5
0
    def test_insight(self):
        socketio, handler = self._mksocketio(b'https://insight.bitpay.com/socket.io/')

        yield socketio.start()
        self.assertTrue(socketio.running)

        yield socketio.emit('subscribe', 'inv')
        from twisted.internet import task as t_task
        yield t_task.deferLater(reactor, 30, lambda: None)
        yield socketio.stop()
        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(socketio.running)

        txs = [ i[0][2][1] for i in handler.call_args_list if i[0][0] == 'event' and i[0][2][0] == 'tx' ]

        if len(txs) == 0:
            try:
                import debug # TODO pylint: disable=reimported,unused-variable,useless-suppression
            except ImportError:
                self.assertGreater(len(txs), 0)

        for tx in txs:
            self.assertIsInstance(tx.get('valueOut'), decimal.Decimal)
            self.assertGreater(tx.get('valueOut', 0), 0)
            self.assertGreater(len(tx.get('vout', ())), 0)
            self.assertRegexpMatches(tx.get('txid', ''), r'^[0-9A-Fa-f]{64}$')
コード例 #6
0
    def test_hello_delay(self):
        self.url.path = b'/hello_delay/engine.io/'
        engineio, handler = self._mkengineio()

        yield engineio.start()
        self.assertTrue(engineio.running)

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(engineio.running)
        self.assertIsNone(engineio._transport_context.session_id) # pylint: disable=protected-access

        call_args_list = [ i for i in handler.call_args_list if i[0][0] not in ( 'noop', 'pong' ) ]

        expected = [
            mock.call('open'),
            mock.call('message', b'Hello!'),
            mock.call('close'),
        ]

        self.assertEqual(call_args_list, expected)
コード例 #7
0
    def test_stop_after_started(self):
        self.url.path = b'/client_close/engine.io/'
        engineio, handler = self._mkengineio()

        yield engineio.start()
        self.assertTrue(engineio.running)

        engineio.stop()
        self.assertRaises(TransportStateError, engineio.stop)

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(engineio.running)
        self.assertIsNone(engineio._transport_context.session_id) # pylint: disable=protected-access

        call_args_list = [ i for i in handler.call_args_list if i[0][0] not in ( 'noop', 'pong' ) ]

        expected = [
            mock.call('open'),
        ]

        self.assertEqual(call_args_list[0], expected[0])
コード例 #8
0
    def test_disconnect_after_connected(self):
        self.url.path = b'/client_close/engine.io/'
        tc = TransportContext(self.url)

        connect_d = self.transport.connect(tc)
        self.assertIn(self.transport.state, ( TRANSPORT_STATE_CONNECTING, TRANSPORT_STATE_CONNECTED ))

        yield connect_d
        self.assertEqual(self.transport.state, TRANSPORT_STATE_CONNECTED)
        self.assertIsNotNone(tc.session_id)

        disconnect_d = self.transport.disconnect()
        self.assertIn(self.transport.state, ( TRANSPORT_STATE_DISCONNECTED, TRANSPORT_STATE_DISCONNECTING ))
        self.assertRaises(TransportStateError, self.transport.standby)
        self.assertRaises(TransportStateError, self.transport.disconnect)

        yield disconnect_d
        self.assertEqual(self.transport.state, TRANSPORT_STATE_DISCONNECTED)
        self.assertIsNone(tc.session_id)

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
コード例 #9
0
    def test_close_packet_after_started(self):
        self.url.path = b'/client_close/engine.io/'
        engineio, handler = self._mkengineio()

        yield engineio.start()
        self.assertTrue(engineio.running)

        send_d = engineio.sendeiopacket(EIO_TYPE_CLOSE)
        yield send_d

        yield txrc.deferredtimeout(reactor, 10, self.close_d)
        self.assertTrue(self.close_d.called)
        self.assertFalse(engineio.running)
        self.assertIsNone(engineio._transport_context.session_id) # pylint: disable=protected-access

        call_args_list = [ i for i in handler.call_args_list if i[0][0] not in ( 'noop', 'pong' ) ]

        expected = [
            mock.call('open'),
            mock.call('close'),
        ]

        self.assertEqual(call_args_list[0], expected[0])
        self.assertEqual(call_args_list[-1], expected[-1])