Пример #1
0
 def onLeave(self, details):
     print("Realm left (WAMP session ended).")
     self.count += 1
     if self.count < 3:
         self.join("kotori-realm")
     else:
         self.disconnect()
     ApplicationSession.onLeave(self, details)
        def test_reject_pending(self):
            handler = ApplicationSession()
            MockTransport(handler)

            # This could happen if the task waiting on a request gets cancelled
            deferred = fail(Exception())
            handler._call_reqs[1] = CallRequest(1, 'foo', deferred, {})
            handler.onLeave(CloseDetails())
Пример #3
0
 def onLeave(self, details):
     print("Realm left (WAMP session ended).")
     self.count += 1
     if self.count < 3:
         self.join("kotori-realm")
     else:
         self.disconnect()
     ApplicationSession.onLeave(self, details)
Пример #4
0
        def test_reject_pending(self):
            handler = ApplicationSession()
            MockTransport(handler)

            # This could happen if the task waiting on a request gets cancelled
            deferred = fail(Exception())
            handler._call_reqs[1] = CallRequest(1, 'foo', deferred, {})
            handler.onLeave(CloseDetails())
Пример #5
0
 def onLeave(self, details):
     # print("onLeave", details)
     d = self.config.extra['running']
     if not d.called:
         d.errback(RuntimeError("onLeave: {}".format(details.message)))
     all_done = self.config.extra.get('all_done', None)
     if all_done:
         all_done.callback(self)
     ApplicationSession.onLeave(self, details)
Пример #6
0
 def onLeave(self, details):
     # XXX note to self: this is the solution to the "illegal
     # switch in blockon" problem I was having -- the ultimate
     # reason, though, is because autobahn/wamp/protocol.py:426 or
     # so is aborting from the other side (missing import in my
     # case) and so we simply never call/errback on our
     # Deferred. But this bring up an interesting issue: how *is*
     # one supposed to deal with this sort of thing in client-code?
     d = self.config.extra['running']
     if not d.called:
         d.errback(RuntimeError("onLeave: {}".format(details.message)))
     ApplicationSession.onLeave(self, details)
     all_done = self.config.extra.get('all_done', None)
     if all_done:
         all_done.callback(details)
Пример #7
0
    def test_router_session_goodbye_custom_message(self):
        """
        Reason should be propagated properly from Goodbye message
        """

        from crossbar.router.session import RouterApplicationSession
        session = ApplicationSession()
        session.onLeave = mock.Mock()
        session._realm = 'realm'
        router = Router(
            factory=mock.Mock(),
            realm=RouterRealm(
                controller=MockContainer(),
                id='realm',
                config=dict(name='realm'),
            )
        )
        rap = RouterApplicationSession(session, router)

        rap.send(message.Goodbye('wamp.reason.logout', 'some custom message'))

        leaves = session.onLeave.mock_calls
        self.assertEqual(1, len(leaves))
        details = leaves[0][1][0]
        self.assertEqual('wamp.reason.logout', details.reason)
        self.assertEqual('some custom message', details.message)
Пример #8
0
    def test_router_session_goodbye_onLeave_error(self):
        """
        Reason should be propagated properly from Goodbye message
        """
        from crossbar.router.session import RouterApplicationSession
        session = ApplicationSession()
        the_exception = RuntimeError("onLeave fails")

        def boom(*args, **kw):
            raise the_exception

        session.onLeave = mock.Mock(side_effect=boom)
        session._realm = 'realm'
        router = Router(factory=mock.Mock(),
                        realm=RouterRealm(
                            controller=None,
                            id='realm',
                            config=dict(name='realm'),
                        ))
        rap = RouterApplicationSession(session, router)

        rap.send(message.Goodbye('wamp.reason.logout', 'some custom message'))

        errors = self.flushLoggedErrors()
        self.assertEqual(1, len(errors))
        self.assertEqual(the_exception, errors[0].value)
Пример #9
0
        def test_publish_outstanding_errors_async_errback(self):
            handler = ApplicationSession()
            MockTransport(handler)
            error_d = Deferred()

            # this publish will "hang" because 'noreply.' URI is
            # handled specially in MockTransport; so this request will
            # be outstanding
            publication_d = handler.publish(
                u'noreply.foo',
                options=types.PublishOptions(acknowledge=True),
            )
            # further, we add an errback that does some arbitrary async work
            got_errors = []

            def errback(fail):
                got_errors.append(fail)
                return error_d

            publication_d.addErrback(errback)
            # "leave" the session, which should trigger errbacks on
            # all outstanding requests.
            details = types.CloseDetails(reason=u'testing',
                                         message=u'how are you?')
            handler.onLeave(details)

            # since our errback is async, onLeave should not have
            # completed yet but we should have already failed the
            # publication
            self.assertEqual(1, len(got_errors))
            # ...now let the async errback continue by completing the
            # Deferred we returned in our errback (could be fail or
            # success, shoudln't matter)
            error_d.callback(None)

            # ensure we (now) get our errback
            try:
                yield publication_d
            except ApplicationError as e:
                self.assertEqual(u'testing', e.error)
                self.assertEqual(u'how are you?', e.message)
Пример #10
0
        def test_publish_outstanding_errors_async_errback(self):
            handler = ApplicationSession()
            MockTransport(handler)
            error_d = Deferred()

            # this publish will "hang" because 'noreply.' URI is
            # handled specially in MockTransport; so this request will
            # be outstanding
            publication_d = handler.publish(
                u'noreply.foo',
                options=types.PublishOptions(acknowledge=True),
            )
            # further, we add an errback that does some arbitrary async work
            got_errors = []

            def errback(fail):
                got_errors.append(fail)
                return error_d
            publication_d.addErrback(errback)
            # "leave" the session, which should trigger errbacks on
            # all outstanding requests.
            details = types.CloseDetails(reason=u'testing', message=u'how are you?')
            handler.onLeave(details)

            # since our errback is async, onLeave should not have
            # completed yet but we should have already failed the
            # publication
            self.assertEqual(1, len(got_errors))
            # ...now let the async errback continue by completing the
            # Deferred we returned in our errback (could be fail or
            # success, shoudln't matter)
            error_d.callback(None)

            # ensure we (now) get our errback
            try:
                yield publication_d
            except ApplicationError as e:
                self.assertEqual(u'testing', e.error)
                self.assertEqual(u'how are you?', e.message)
Пример #11
0
        def test_publish_outstanding_errors(self):
            handler = ApplicationSession()
            MockTransport(handler)

            # this publish will "hang" because 'noreply.' URI is
            # handled specially in MockTransport; so this request will
            # be outstanding
            publication = handler.publish(
                u'noreply.foo',
                options=types.PublishOptions(acknowledge=True),
            )
            # "leave" the session, which should trigger errbacks on
            # all outstanding requests.
            details = types.CloseDetails(reason=u'testing', message=u'how are you?')
            yield handler.onLeave(details)

            # ensure we got our errback
            try:
                yield publication
            except ApplicationError as e:
                self.assertEqual(u'testing', e.error)
                self.assertEqual(u'how are you?', e.message)
        def test_publish_outstanding_errors(self):
            handler = ApplicationSession()
            MockTransport(handler)

            # this publish will "hang" because 'noreply.' URI is
            # handled specially in MockTransport; so this request will
            # be outstanding
            publication = handler.publish(
                'noreply.foo',
                options=types.PublishOptions(acknowledge=True),
            )
            # "leave" the session, which should trigger errbacks on
            # all outstanding requests.
            details = types.CloseDetails(reason='testing', message='how are you?')
            yield handler.onLeave(details)

            # ensure we got our errback
            try:
                yield publication
            except ApplicationError as e:
                self.assertEqual('testing', e.error)
                self.assertEqual('how are you?', e.message)
Пример #13
0
 def onLeave(self, details):
     print("Realm left (WAMP session ended).")
     ApplicationSession.onLeave(self, details)
Пример #14
0
 def onLeave(self, *args, **kwargs):
     self.logger.info("Leaving WAMP Broker")
     ApplicationSession.onLeave(self, *args, **kwargs)
Пример #15
0
 def onLeave(self, *args, **kwargs):
     self.logger.info("Leaving WAMP Broker")
     ApplicationSession.onLeave(self, *args, **kwargs)
Пример #16
0
 def onLeave(self, details):
     ApplicationSession.onLeave(self, details)
     if(hasattr(self, "_loop") and self._loop):
         self._loop.stop()
     print("session left")
Пример #17
0
 def onLeave(self, details):
     self.log.info('MySession.onLeave(details={details})', details=details)
     ApplicationSession.onLeave(self, details)
Пример #18
0
 def onLeave(self, details):
     self.log.info('session left: {details}', details=details)
     ApplicationSession.onLeave(self, details)
Пример #19
0
 def onLeave(self, details):
     log.info("Realm left (WAMP session ended).")
     ApplicationSession.onLeave(self, details)