Esempio n. 1
0
    def test_still_sends_on_error(self):

        bus = VoomBus()
        msgs = []
        bus.subscribe(bus.ALL, lambda m: msgs.append((m, bus.session, bus.trx)))
        d = dict(a=1)
        with nose.tools.assert_raises(ValueError):  # @UndefinedVariable
            with bus.transaction() as (nested, state):
                assert not nested
                with bus.using(d):
                    self.assertEqual(d, bus.session)
                    bus.publish(1)
                    # this should not send the message, until
                    # until we exit the transaction block
                    self.assertEqual([], msgs)
                self.assertEqual([], msgs)
                int("a")
                self.fail("how'd I get here")

        # ensure we didn't lose the message
        self.assertEqual(1, len(msgs))
        m, frame, trx = msgs[0]
        self.assertEqual(1, m)
        self.assertEqual(True, trx.is_queue_empty())
        self.assertEqual({}, bus.frame)
        self.assertEqual(d, frame)
Esempio n. 2
0
    def test_send_on_exit(self):
        bus = VoomBus()
        self.msgs = []
        bus.subscribe(bus.ALL, self.msgs.append)

        with bus.transaction() as (nested, state):
            with bus.using(dict(a=1)):
                bus.publish(1)
            assert not self.msgs
            assert isinstance(state, TrxState)
            assert not state.is_queue_empty()

        assert self.msgs == [1]
        assert state.is_queue_empty()
Esempio n. 3
0
    def test_send_on_exit(self):
        bus = VoomBus()
        self.msgs = []
        bus.subscribe(bus.ALL, self.msgs.append)

        with bus.transaction() as (nested, state):
            with bus.using(dict(a=1)):
                bus.publish(1)
            assert not self.msgs
            assert isinstance(state, TrxState)
            assert not state.is_queue_empty()

        assert self.msgs == [1]
        assert state.is_queue_empty()
Esempio n. 4
0
    def test_send_on_error(self):
        bus = VoomBus()
        self.msgs = []
        bus.subscribe(bus.ALL, self.msgs.append)

        with nose.tools.assert_raises(ValueError): #@UndefinedVariable
            with bus.transaction() as (nested, state):
                assert not nested
                with bus.using(dict(a=1)):
                    assert bus.session == dict(a=1), bus.session
                    bus.publish(1)
                assert not self.msgs
                int("a")
                with bus.using(dict(a=1)):
                    bus.publish(1)

        assert self.msgs == [1]
        assert state.is_queue_empty()
        assert state.session == dict(a=1), state.session
Esempio n. 5
0
    def test_send_on_error(self):
        bus = VoomBus()
        self.msgs = []
        bus.subscribe(bus.ALL, self.msgs.append)

        with nose.tools.assert_raises(ValueError):  #@UndefinedVariable
            with bus.transaction() as (nested, state):
                assert not nested
                with bus.using(dict(a=1)):
                    assert bus.session == dict(a=1), bus.session
                    bus.publish(1)
                assert not self.msgs
                int("a")
                with bus.using(dict(a=1)):
                    bus.publish(1)

        assert self.msgs == [1]
        assert state.is_queue_empty()
        assert state.session == dict(a=1), state.session
Esempio n. 6
0
    def test2(self):
        bus = VoomBus()
        data1 = {1: 2}
        data2 = {'a': True}

        def func3():
            bus.publish("1")

        def func2():
            with bus.using(data2):
                func3()

        def func1():
            with bus.using(data1):
                func2()

        session = {}

        bus.subscribe(bus.ALL, lambda _: session.update(bus.session))

        func1()
        data1.update(data2)
        assert session == data1, session
Esempio n. 7
0
    def test2(self):
        bus = VoomBus()
        data1 = {1: 2}
        data2 = {'a': True}

        def func3():
            bus.publish("1")

        def func2():
            with bus.using(data2):
                func3()

        def func1():
            with bus.using(data1):
                func2()

        session = {}

        bus.subscribe(bus.ALL, lambda _: session.update(bus.session))

        func1()
        data1.update(data2)
        assert session == data1, session