Exemplo n.º 1
0
 def test_on_message_ready(self):
     channel = Mock(name='channel')
     msg = Mock(name='msg')
     callback = Mock(name='callback')
     self.transport._callbacks = {'q1': callback}
     self.transport.on_message_ready(channel, msg, queue='q1')
     callback.assert_called_with(msg)
Exemplo n.º 2
0
 def test_register_with_event_loop(self):
     conn = Mock(name='conn')
     loop = Mock(name='loop')
     self.T.register_with_event_loop(conn, loop)
     loop.add_reader.assert_called_with(
         conn.fileno(), self.T.on_readable, conn, loop,
     )
Exemplo n.º 3
0
    def test_call_repeatedly(self):
        t = Timer()
        try:
            t.schedule.enter_after = Mock()

            myfun = Mock()
            myfun.__name__ = bytes_if_py2("myfun")
            t.call_repeatedly(0.03, myfun)

            self.assertEqual(t.schedule.enter_after.call_count, 1)
            args1, _ = t.schedule.enter_after.call_args_list[0]
            sec1, tref1, _ = args1
            self.assertEqual(sec1, 0.03)
            tref1()

            self.assertEqual(t.schedule.enter_after.call_count, 2)
            args2, _ = t.schedule.enter_after.call_args_list[1]
            sec2, tref2, _ = args2
            self.assertEqual(sec2, 0.03)
            tref2.canceled = True
            tref2()

            self.assertEqual(t.schedule.enter_after.call_count, 2)
        finally:
            t.stop()
Exemplo n.º 4
0
    def test_enter__exit(self):
        P = self.hub.poller = Mock()
        on_close = Mock()
        self.hub.on_close.add(on_close)

        try:
            read_A = Mock()
            read_B = Mock()
            self.hub.add_reader(10, read_A)
            self.hub.add_reader(File(11), read_B)
            write_A = Mock()
            write_B = Mock()
            self.hub.add_writer(20, write_A)
            self.hub.add_writer(File(21), write_B)
            self.assertTrue(self.hub.readers)
            self.assertTrue(self.hub.writers)
        finally:
            assert self.hub.poller
            self.hub.close()
        self.assertFalse(self.hub.readers)
        self.assertFalse(self.hub.writers)

        P.unregister.assert_has_calls([
            call(10), call(11), call(20), call(21),
        ], any_order=True)

        on_close.assert_called_with(self.hub)
Exemplo n.º 5
0
    def test_close_connection(self):
        connection = Mock()
        connection.client = Mock()
        self.transport.close_connection(connection)

        self.assertIsNone(connection.client)
        connection.close.assert_called_with()
Exemplo n.º 6
0
def passthrough(*args, **kwargs):
    m = Mock(*args, **kwargs)

    def side_effect(ret):
        return ret
    m.side_effect = side_effect
    return m
Exemplo n.º 7
0
    def test_getresponse__real_response(self):
        client = Mock(name='client')
        client.add_request = passthrough(name='client.add_request')
        callback = PromiseMock(name='callback')
        x = AsyncHTTPConnection('aws.vandelay.com', http_client=client)
        request = x.getresponse(callback)
        x.http_client.add_request.assert_called_with(request)

        buf = WhateverIO()
        buf.write('The quick brown fox jumps')

        headers = http.Headers({'X-Foo': 'Hello', 'X-Bar': 'World'})

        response = http.Response(request, 200, headers, buf)
        request.on_ready(response)
        self.assertTrue(callback.called)
        wresponse = callback.call_args[0][0]

        self.assertEqual(wresponse.read(), 'The quick brown fox jumps')
        self.assertEqual(wresponse.status, 200)
        self.assertEqual(wresponse.getheader('X-Foo'), 'Hello')
        self.assertDictEqual(dict(wresponse.getheaders()), headers)
        self.assertTrue(wresponse.msg)
        self.assertTrue(wresponse.msg)
        self.assertTrue(repr(wresponse))
Exemplo n.º 8
0
    def test_verify_connection(self):
        connection = Mock()
        connection.channels = None
        self.assertFalse(self.transport.verify_connection(connection))

        connection.channels = {1: 1, 2: 2}
        self.assertTrue(self.transport.verify_connection(connection))
Exemplo n.º 9
0
 def test_repr(self):
     obj = Mock(name='cb')
     self.assertIn(
         'promise',
         repr(utils.ChannelPromise(obj)),
     )
     obj.assert_not_called()
Exemplo n.º 10
0
    def test_on_poll_start(self):
        p = self.Poller()
        p._channels = []
        p.on_poll_start()
        p._register_BRPOP = Mock(name='_register_BRPOP')
        p._register_LISTEN = Mock(name='_register_LISTEN')

        chan1 = Mock(name='chan1')
        p._channels = [chan1]
        chan1.active_queues = []
        chan1.active_fanout_queues = []
        p.on_poll_start()

        chan1.active_queues = ['q1']
        chan1.active_fanout_queues = ['q2']
        chan1.qos.can_consume.return_value = False

        p.on_poll_start()
        p._register_LISTEN.assert_called_with(chan1)
        self.assertFalse(p._register_BRPOP.called)

        chan1.qos.can_consume.return_value = True
        p._register_LISTEN.reset_mock()
        p.on_poll_start()

        p._register_BRPOP.assert_called_with(chan1)
        p._register_LISTEN.assert_called_with(chan1)
Exemplo n.º 11
0
    def test_with_error(self):
        r = Mock(name='response')
        r.error = HttpError(404, 'NotFound')
        x = AsyncHTTPResponse(r)
        self.assertEqual(x.reason, 'NotFound')

        r.error = None
        self.assertFalse(x.reason)
Exemplo n.º 12
0
 def test_enter_after(self):
     t = Timer()
     t._enter = Mock()
     fun = Mock(name="fun")
     time = Mock(name="time")
     time.return_value = 10
     t.enter_after(10, fun, time=time)
     time.assert_called_with()
     t._enter.assert_called_with(20, 0, fun)
Exemplo n.º 13
0
    def test_apply_entry_error_not_handled(self, stdout, stderr):
        t = Timer()
        t.schedule.on_error = Mock()

        fun = Mock()
        fun.side_effect = ValueError()
        t.schedule.apply_entry(fun)
        fun.assert_called_with()
        self.assertFalse(stderr.getvalue())
Exemplo n.º 14
0
    def test_apply_entry_error_handled(self, logger):
        t = Timer()
        t.schedule.on_error = None

        fun = Mock()
        fun.side_effect = ValueError()

        t.schedule.apply_entry(fun)
        logger.error.assert_called()
Exemplo n.º 15
0
    def test_connect_to_region(self):
        with patch('kombu.async.aws.sqs.regions') as regions:
            region = Mock(name='region')
            region.name = 'us-west-1'
            regions.return_value = [region]
            conn = connect_to_region('us-west-1', kw=3.33)
            self.assertIs(conn, region.connect.return_value)
            region.connect.assert_called_with(kw=3.33)

            self.assertIsNone(connect_to_region('foo'))
Exemplo n.º 16
0
    def test_acquire_release(self):
        x = LaxBoundedSemaphore(2)

        c1 = Mock()
        x.acquire(c1, 1)
        self.assertEqual(x.value, 1)
        c1.assert_called_with(1)

        c2 = Mock()
        x.acquire(c2, 2)
        self.assertEqual(x.value, 0)
        c2.assert_called_with(2)

        c3 = Mock()
        x.acquire(c3, 3)
        self.assertEqual(x.value, 0)
        self.assertFalse(c3.called)

        x.release()
        self.assertEqual(x.value, 0)
        x.release()
        self.assertEqual(x.value, 1)
        x.release()
        self.assertEqual(x.value, 2)
        c3.assert_called_with(3)
Exemplo n.º 17
0
 def test_mexe__with_sender(self, _):
     x = AsyncAWSAuthConnection('aws.vandelay.com',
                                http_client=Mock(name='client'))
     Conn = x.get_http_connection = Mock(name='get_http_connection')
     request = x.build_base_http_request('GET', 'foo', '/auth')
     sender = Mock(name='sender')
     callback = PromiseMock(name='callback')
     x._mexe(request, sender=sender, callback=callback)
     sender.assert_called_with(
         Conn.return_value, request.method, request.path,
         request.body, request.headers, callback,
     )
Exemplo n.º 18
0
    def test_getresponse(self):
        client = Mock(name='client')
        client.add_request = passthrough(name='client.add_request')
        x = AsyncHTTPConnection('aws.vandelay.com', http_client=client)
        x.Response = Mock(name='x.Response')
        request = x.getresponse()
        x.http_client.add_request.assert_called_with(request)
        self.assertIsInstance(request, Thenable)
        self.assertIsInstance(request.on_ready, Thenable)

        response = Mock(name='Response')
        request.on_ready(response)
        x.Response.assert_called_with(response)
Exemplo n.º 19
0
    def MockMessage(self, id=None, receipt_handle=None, body=None):
        m = Mock(name='message')
        m.id = id or uuid()
        m.receipt_handle = receipt_handle or uuid()
        m._body = body

        def _get_body():
            return m._body
        m.get_body.side_effect = _get_body

        def _set_body(value):
            m._body = value
        m.set_body.side_effect = _set_body

        return m
Exemplo n.º 20
0
    def test_register_BRPOP(self):
        p = self.Poller()
        channel = Mock()
        channel.client.connection._sock = None
        p._register = Mock()

        channel._in_poll = False
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)

        channel.client.connection._sock = Mock()
        p._chan_to_sock[(channel, channel.client, 'BRPOP')] = True
        channel._in_poll = True
        p._register_BRPOP(channel)
        self.assertEqual(channel._brpop_start.call_count, 1)
        self.assertEqual(p._register.call_count, 1)
Exemplo n.º 21
0
    def create_get(self, events=None, queues=None, fanouts=None):
        _pr = [] if events is None else events
        _aq = [] if queues is None else queues
        _af = [] if fanouts is None else fanouts
        p = self.Poller()
        p.poller = Mock()
        p.poller.poll.return_value = _pr

        p._register_BRPOP = Mock()
        p._register_LISTEN = Mock()

        channel = Mock()
        p._channels = [channel]
        channel.active_queues = _aq
        channel.active_fanout_queues = _af

        return p, channel
Exemplo n.º 22
0
 def test_simple(self):
     prev_count, utils.count = utils.count, Mock()
     try:
         utils.count.return_value = list(range(1))
         x = utils.retry_over_time(self.myfun, self.Predicate,
                                   errback=None, interval_max=14)
         self.assertIsNone(x)
         utils.count.return_value = list(range(10))
         cb = Mock()
         x = utils.retry_over_time(self.myfun, self.Predicate,
                                   errback=self.errback, callback=cb,
                                   interval_max=14)
         self.assertEqual(x, 42)
         self.assertEqual(self.index, 9)
         cb.assert_called_with()
     finally:
         utils.count = prev_count
Exemplo n.º 23
0
    def test_register_LISTEN(self):
        p = self.Poller()
        channel = Mock()
        channel.subclient.connection._sock = None
        channel._in_listen = False
        p._register = Mock()

        p._register_LISTEN(channel)
        p._register.assert_called_with(channel, channel.subclient, 'LISTEN')
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)

        channel._in_listen = True
        channel.subclient.connection._sock = Mock()
        p._register_LISTEN(channel)
        self.assertEqual(p._register.call_count, 1)
        self.assertEqual(channel._subscribe.call_count, 1)
Exemplo n.º 24
0
    def test_handle_event(self):
        p = self.Poller()
        chan = Mock(name='chan')
        p._fd_to_chan[13] = chan, 'BRPOP'
        chan.handlers = {'BRPOP': Mock(name='BRPOP')}

        chan.qos.can_consume.return_value = False
        p.handle_event(13, redis.READ)
        self.assertFalse(chan.handlers['BRPOP'].called)

        chan.qos.can_consume.return_value = True
        p.handle_event(13, redis.READ)
        chan.handlers['BRPOP'].assert_called_with()

        p.handle_event(13, redis.ERR)
        chan._poll_error.assert_called_with('BRPOP')

        p.handle_event(13, ~(redis.READ | redis.ERR))
Exemplo n.º 25
0
    def test_mutex(self, lock_id='xxx'):
        client = Mock(name='client')
        with patch('kombu.transport.redis.uuid') as uuid:
            # Won
            uuid.return_value = lock_id
            client.setnx.return_value = True
            client.pipeline = ContextMock()
            pipe = client.pipeline.return_value
            pipe.get.return_value = lock_id
            held = False
            with redis.Mutex(client, 'foo1', 100):
                held = True
            self.assertTrue(held)
            client.setnx.assert_called_with('foo1', lock_id)
            pipe.get.return_value = 'yyy'
            held = False
            with redis.Mutex(client, 'foo1', 100):
                held = True
            self.assertTrue(held)

            # Did not win
            client.expire.reset_mock()
            pipe.get.return_value = lock_id
            client.setnx.return_value = False
            with self.assertRaises(redis.MutexHeld):
                held = False
                with redis.Mutex(client, 'foo1', '100'):
                    held = True
                self.assertFalse(held)
            client.ttl.return_value = 0
            with self.assertRaises(redis.MutexHeld):
                held = False
                with redis.Mutex(client, 'foo1', '100'):
                    held = True
                self.assertFalse(held)
            self.assertTrue(client.expire.called)

            # Wins but raises WatchError (and that is ignored)
            client.setnx.return_value = True
            pipe.watch.side_effect = redis.redis.WatchError()
            held = False
            with redis.Mutex(client, 'foo1', 100):
                held = True
            self.assertTrue(held)
Exemplo n.º 26
0
    def test_fire_timers_raises(self):
        eback = Mock()
        eback.side_effect = KeyError('foo')
        self.hub.timer = Mock()
        self.hub.scheduler = iter([(0, eback)])
        with self.assertRaises(KeyError):
            self.hub.fire_timers(propagate=(KeyError,))

        eback.side_effect = ValueError('foo')
        self.hub.scheduler = iter([(0, eback)])
        with patch('kombu.async.hub.logger') as logger:
            with self.assertRaises(StopIteration):
                self.hub.fire_timers()
            self.assertTrue(logger.error.called)

        eback.side_effect = MemoryError('foo')
        self.hub.scheduler = iter([(0, eback)])
        with self.assertRaises(MemoryError):
            self.hub.fire_timers()

        eback.side_effect = OSError()
        eback.side_effect.errno = errno.ENOMEM
        self.hub.scheduler = iter([(0, eback)])
        with self.assertRaises(OSError):
            self.hub.fire_timers()

        eback.side_effect = OSError()
        eback.side_effect.errno = errno.ENOENT
        self.hub.scheduler = iter([(0, eback)])
        with patch('kombu.async.hub.logger') as logger:
            with self.assertRaises(StopIteration):
                self.hub.fire_timers()
            self.assertTrue(logger.error.called)
Exemplo n.º 27
0
    def test_collect__with_conn(self):
        self.T.client.drain_events = 1234
        conn = Mock(name='connection')
        chans = conn.channels = {1: Mock(name='chan1'), 2: Mock(name='chan2')}
        conn.callbacks = {'foo': Mock(name='cb1'), 'bar': Mock(name='cb2')}
        for i, chan in enumerate(conn.channels.values()):
            chan.connection = i

        with patch('os.close') as close:
            self.T._collect(conn)
            close.assert_called_with(conn.fileno())
        self.assertFalse(conn.channels)
        self.assertFalse(conn.callbacks)
        for chan in chans.values():
            self.assertIsNone(chan.connection)
        self.assertIsNone(self.client.drain_events)
        self.assertIsNone(self.T.client)

        with patch('os.close') as close:
            self.T.client = self.client
            close.side_effect = OSError()
            self.T._collect(conn)
            close.assert_called_with(conn.fileno())
Exemplo n.º 28
0
    def test_grow_shrink(self):
        x = LaxBoundedSemaphore(1)
        self.assertEqual(x.initial_value, 1)
        cb1 = Mock()
        x.acquire(cb1, 1)
        cb1.assert_called_with(1)
        self.assertEqual(x.value, 0)

        cb2 = Mock()
        x.acquire(cb2, 2)
        self.assertFalse(cb2.called)
        self.assertEqual(x.value, 0)

        cb3 = Mock()
        x.acquire(cb3, 3)
        self.assertFalse(cb3.called)

        x.grow(2)
        cb2.assert_called_with(2)
        cb3.assert_called_with(3)
        self.assertEqual(x.value, 2)
        self.assertEqual(x.initial_value, 3)

        self.assertFalse(x._waiting)
        x.grow(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        x.clear()

        x.shrink(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        self.assertEqual(x.value, 0)

        for i in range(100):
            x.release()
        self.assertEqual(x.value, x.initial_value)
Exemplo n.º 29
0
    def test_subscribe_no_queues(self):
        self.channel.subclient = Mock()
        self.channel.active_fanout_queues.clear()
        self.channel._subscribe()

        self.assertFalse(self.channel.subclient.subscribe.called)
Exemplo n.º 30
0
 def test_qos_reject(self):
     p, channel = self.create_get()
     qos = redis.QoS(channel)
     qos.ack = Mock(name='Qos.ack')
     qos.reject(1234)
     qos.ack.assert_called_with(1234)
Exemplo n.º 31
0
 def _get_pool(self):
     return Mock()
Exemplo n.º 32
0
 def test_close_when_unregister_raises_KeyError(self):
     p = self.Poller()
     p.poller = Mock()
     p._chan_to_sock.update({1: 1})
     p.poller.unregister.side_effect = KeyError(1)
     p.close()
Exemplo n.º 33
0
 def after_connected():
     client.connection._sock = Mock()
Exemplo n.º 34
0
 def test_stop(self):
     self.hub.call_soon = Mock(name='call_soon')
     self.hub.stop()
     self.hub.call_soon.assert_called_with(_raise_stop_error)
Exemplo n.º 35
0
 def test_run_forever(self):
     self.hub.run_once = Mock(name='hub.run_once')
     self.hub.run_once.side_effect = Stop()
     self.hub.run_forever()
Exemplo n.º 36
0
 def test_verify_connection(self):
     conn = Mock(name='connection')
     conn.connected = True
     self.assertTrue(self.T.verify_connection(conn))
Exemplo n.º 37
0
 def test_call_at(self):
     callback = Mock(name='callback')
     self.hub.timer = Mock(name='hub.timer')
     self.hub.call_at(21231122, callback, 1, 2)
     self.hub.timer.call_at.assert_called_with(21231122, callback, (1, 2))
Exemplo n.º 38
0
    def test_grow_shrink(self):
        x = LaxBoundedSemaphore(1)
        self.assertEqual(x.initial_value, 1)
        cb1 = Mock()
        x.acquire(cb1, 1)
        cb1.assert_called_with(1)
        self.assertEqual(x.value, 0)

        cb2 = Mock()
        x.acquire(cb2, 2)
        cb2.assert_not_called()
        self.assertEqual(x.value, 0)

        cb3 = Mock()
        x.acquire(cb3, 3)
        cb3.assert_not_called()

        x.grow(2)
        cb2.assert_called_with(2)
        cb3.assert_called_with(3)
        self.assertEqual(x.value, 2)
        self.assertEqual(x.initial_value, 3)

        self.assertFalse(x._waiting)
        x.grow(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        x.clear()

        x.shrink(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        self.assertEqual(x.value, 0)

        for i in range(100):
            x.release()
        self.assertEqual(x.value, x.initial_value)
Exemplo n.º 39
0
    def test_receive_empty(self):
        s = self.channel.subclient = Mock()
        s.parse_response.return_value = None

        with self.assertRaises(redis.Empty):
            self.channel._receive()
Exemplo n.º 40
0
    def test_remove__unregister_raises(self):
        self.hub.poller = Mock()
        self.hub.poller.unregister.side_effect = OSError()

        self.hub.remove(313)
Exemplo n.º 41
0
 def test_can_remove_unknown_fds(self):
     self.hub.poller = Mock()
     self.hub.remove(30)
     self.hub.remove(File(301))
Exemplo n.º 42
0
 def _create_client(self):
     self._client = Mock(name='client')
Exemplo n.º 43
0
 def test_on_callback_error(self, logger):
     self.hub.on_callback_error(Mock(name='callback'), KeyError())
     logger.error.assert_called()
Exemplo n.º 44
0
 def test_add__consolidate(self):
     self.hub.poller = Mock(name='hub.poller')
     self.hub.add(2, Mock(), WRITE, consolidate=True)
     self.assertIn(2, self.hub.consolidate)
     self.assertIsNone(self.hub.writers[2])
Exemplo n.º 45
0
 def test_call_soon(self, promise):
     callback = Mock(name='callback')
     ret = self.hub.call_soon(callback, 1, 2, 3)
     promise.assert_called_with(callback, (1, 2, 3))
     self.assertIn(promise(), self.hub._ready)
     self.assertIs(ret, promise())
Exemplo n.º 46
0
 def test_call_later(self):
     callback = Mock(name='callback')
     self.hub.timer = Mock(name='hub.timer')
     self.hub.call_later(10.0, callback, 1, 2)
     self.hub.timer.call_after.assert_called_with(10.0, callback, (1, 2))
Exemplo n.º 47
0
 def test_reset(self):
     self.hub.close = Mock(name='close')
     self.hub._create_poller = Mock(name='_create_poller')
     self.hub.reset()
     self.hub.close.assert_called_with()
     self.hub._create_poller.assert_called_with()
Exemplo n.º 48
0
 def test_loop_property(self):
     self.hub._loop = None
     self.hub.create_loop = Mock(name='hub.create_loop')
     self.assertIs(self.hub.loop, self.hub.create_loop())
     self.assertIs(self.hub._loop, self.hub.create_loop())
Exemplo n.º 49
0
 def test_remove_reader__not_writeable(self):
     self.hub.poller = Mock(name='hub.poller')
     self.hub.add(2, Mock(), READ)
     self.hub.remove_reader(2)
     self.assertNotIn(2, self.hub.readers)
Exemplo n.º 50
0
 def test_remove_writer__not_readable(self):
     self.hub.poller = Mock(name='hub.poller')
     self.hub.add(2, Mock(), WRITE)
     self.hub.remove_writer(2)
     self.assertNotIn(2, self.hub.writers)
Exemplo n.º 51
0
 def test__close_poller(self):
     poller = self.hub.poller = Mock(name='poller')
     self.hub._close_poller()
     poller.close.assert_called_with()
     self.assertIsNone(self.hub.poller)
Exemplo n.º 52
0
    def test_deliver_when_fanout_unsupported(self):
        self.e.channel = Mock()
        self.e.channel.supports_fanout = False

        self.e.deliver(Mock(), 'exchange', None)
        self.assertFalse(self.e.channel._put_fanout.called)
Exemplo n.º 53
0
 def test_message_to_python(self):
     message = Mock()
     message.headers = {}
     message.properties = {}
     self.assertTrue(self.channel.message_to_python(message))
Exemplo n.º 54
0
    def test_avail_client_when_not_in_poll(self):
        self.channel._in_poll = False
        c = self.channel.client = Mock()

        with self.channel.conn_or_acquire() as client:
            self.assertIs(client, c)
Exemplo n.º 55
0
    def test_receive_different_message_Type(self):
        s = self.channel.subclient = Mock()
        s.parse_response.return_value = ['message', '/foo/', 0, 'data']

        with self.assertRaises(redis.Empty):
            self.channel._receive()
Exemplo n.º 56
0
 def test_call_soon__promise_argument(self):
     callback = promise(Mock(name='callback'), (1, 2, 3))
     ret = self.hub.call_soon(callback)
     self.assertIs(ret, callback)
     self.assertIn(ret, self.hub._ready)
Exemplo n.º 57
0
    def test_brpop_read_gives_None(self):
        c = self.channel.client = Mock()
        c.parse_response.return_value = None

        with self.assertRaises(redis.Empty):
            self.channel._brpop_read()
Exemplo n.º 58
0
    def test_close_client_close_raises(self):
        c = self.channel.client = Mock()
        c.connection.disconnect.side_effect = self.channel.ResponseError()

        self.channel.close()
        c.connection.disconnect.assert_called_with()
Exemplo n.º 59
0
    def test_acquire_release(self):
        x = LaxBoundedSemaphore(2)

        c1 = Mock()
        x.acquire(c1, 1)
        self.assertEqual(x.value, 1)
        c1.assert_called_with(1)

        c2 = Mock()
        x.acquire(c2, 2)
        self.assertEqual(x.value, 0)
        c2.assert_called_with(2)

        c3 = Mock()
        x.acquire(c3, 3)
        self.assertEqual(x.value, 0)
        c3.assert_not_called()

        x.release()
        self.assertEqual(x.value, 0)
        x.release()
        self.assertEqual(x.value, 1)
        x.release()
        self.assertEqual(x.value, 2)
        c3.assert_called_with(3)
Exemplo n.º 60
0
 def test_connection(self):
     x = connect_sqs('AAKI', 'ASAK', http_client=Mock())
     self.assertTrue(x)
     self.assertTrue(x.connection)