|  | @@ -239,31 +239,6 @@ class test_AMQPBackend(AppCase):
 | 
	
		
			
				|  |  |                  'Returns cache if no new states',
 | 
	
		
			
				|  |  |              )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    def test_wait_for(self):
 | 
	
		
			
				|  |  | -        b = self.create_backend()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        tid = uuid()
 | 
	
		
			
				|  |  | -        with self.assertRaises(TimeoutError):
 | 
	
		
			
				|  |  | -            b.wait_for(tid, timeout=0.1)
 | 
	
		
			
				|  |  | -        b.store_result(tid, None, states.STARTED)
 | 
	
		
			
				|  |  | -        with self.assertRaises(TimeoutError):
 | 
	
		
			
				|  |  | -            b.wait_for(tid, timeout=0.1)
 | 
	
		
			
				|  |  | -        b.store_result(tid, None, states.RETRY)
 | 
	
		
			
				|  |  | -        with self.assertRaises(TimeoutError):
 | 
	
		
			
				|  |  | -            b.wait_for(tid, timeout=0.1)
 | 
	
		
			
				|  |  | -        b.store_result(tid, 42, states.SUCCESS)
 | 
	
		
			
				|  |  | -        self.assertEqual(b.wait_for(tid, timeout=1)['result'], 42)
 | 
	
		
			
				|  |  | -        b.store_result(tid, 56, states.SUCCESS)
 | 
	
		
			
				|  |  | -        self.assertEqual(b.wait_for(tid, timeout=1)['result'], 42,
 | 
	
		
			
				|  |  | -                         'result is cached')
 | 
	
		
			
				|  |  | -        self.assertEqual(b.wait_for(tid, timeout=1, cache=False)['result'], 56)
 | 
	
		
			
				|  |  | -        b.store_result(tid, KeyError('foo'), states.FAILURE)
 | 
	
		
			
				|  |  | -        res = b.wait_for(tid, timeout=1, cache=False)
 | 
	
		
			
				|  |  | -        self.assertEqual(res['status'], states.FAILURE)
 | 
	
		
			
				|  |  | -        b.store_result(tid, KeyError('foo'), states.PENDING)
 | 
	
		
			
				|  |  | -        with self.assertRaises(TimeoutError):
 | 
	
		
			
				|  |  | -            b.wait_for(tid, timeout=0.01, cache=False)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      def test_drain_events_decodes_exceptions_in_meta(self):
 | 
	
		
			
				|  |  |          tid = uuid()
 | 
	
		
			
				|  |  |          b = self.create_backend(serializer="json")
 | 
	
	
		
			
				|  | @@ -276,122 +251,6 @@ class test_AMQPBackend(AppCase):
 | 
	
		
			
				|  |  |          self.assertEqual(cm.exception.__class__.__name__, "RuntimeError")
 | 
	
		
			
				|  |  |          self.assertEqual(str(cm.exception), "aap")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    def test_drain_events_remaining_timeouts(self):
 | 
	
		
			
				|  |  | -        class Connection(object):
 | 
	
		
			
				|  |  | -            def drain_events(self, timeout=None):
 | 
	
		
			
				|  |  | -                pass
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        b = self.create_backend()
 | 
	
		
			
				|  |  | -        with self.app.pool.acquire_channel(block=False) as (_, channel):
 | 
	
		
			
				|  |  | -            binding = b._create_binding(uuid())
 | 
	
		
			
				|  |  | -            consumer = b.Consumer(channel, binding, no_ack=True)
 | 
	
		
			
				|  |  | -            callback = Mock()
 | 
	
		
			
				|  |  | -            with self.assertRaises(socket.timeout):
 | 
	
		
			
				|  |  | -                b.drain_events(Connection(), consumer, timeout=0.1,
 | 
	
		
			
				|  |  | -                               on_interval=callback)
 | 
	
		
			
				|  |  | -                callback.assert_called_with()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def test_get_many(self):
 | 
	
		
			
				|  |  | -        b = self.create_backend(max_cached_results=10)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        tids = []
 | 
	
		
			
				|  |  | -        for i in range(10):
 | 
	
		
			
				|  |  | -            tid = uuid()
 | 
	
		
			
				|  |  | -            b.store_result(tid, i, states.SUCCESS)
 | 
	
		
			
				|  |  | -            tids.append(tid)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        res = list(b.get_many(tids, timeout=1))
 | 
	
		
			
				|  |  | -        expected_results = [
 | 
	
		
			
				|  |  | -            (_tid, {'status': states.SUCCESS,
 | 
	
		
			
				|  |  | -                    'result': i,
 | 
	
		
			
				|  |  | -                    'traceback': None,
 | 
	
		
			
				|  |  | -                    'task_id': _tid,
 | 
	
		
			
				|  |  | -                    'children': None})
 | 
	
		
			
				|  |  | -            for i, _tid in enumerate(tids)
 | 
	
		
			
				|  |  | -        ]
 | 
	
		
			
				|  |  | -        self.assertEqual(sorted(res), sorted(expected_results))
 | 
	
		
			
				|  |  | -        self.assertDictEqual(b._cache[res[0][0]], res[0][1])
 | 
	
		
			
				|  |  | -        cached_res = list(b.get_many(tids, timeout=1))
 | 
	
		
			
				|  |  | -        self.assertEqual(sorted(cached_res), sorted(expected_results))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        # times out when not ready in cache (this shouldn't happen)
 | 
	
		
			
				|  |  | -        b._cache[res[0][0]]['status'] = states.RETRY
 | 
	
		
			
				|  |  | -        with self.assertRaises(socket.timeout):
 | 
	
		
			
				|  |  | -            list(b.get_many(tids, timeout=0.01))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        # times out when result not yet ready
 | 
	
		
			
				|  |  | -        with self.assertRaises(socket.timeout):
 | 
	
		
			
				|  |  | -            tids = [uuid()]
 | 
	
		
			
				|  |  | -            b.store_result(tids[0], i, states.PENDING)
 | 
	
		
			
				|  |  | -            list(b.get_many(tids, timeout=0.01))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def test_get_many_on_message(self):
 | 
	
		
			
				|  |  | -        b = self.create_backend(max_cached_results=10)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        tids = []
 | 
	
		
			
				|  |  | -        for i in range(10):
 | 
	
		
			
				|  |  | -            tid = uuid()
 | 
	
		
			
				|  |  | -            b.store_result(tid, '', states.PENDING)
 | 
	
		
			
				|  |  | -            b.store_result(tid, 'comment_%i_1' % i, states.STARTED)
 | 
	
		
			
				|  |  | -            b.store_result(tid, 'comment_%i_2' % i, states.STARTED)
 | 
	
		
			
				|  |  | -            b.store_result(tid, 'final result %i' % i, states.SUCCESS)
 | 
	
		
			
				|  |  | -            tids.append(tid)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        expected_messages = {}
 | 
	
		
			
				|  |  | -        for i, _tid in enumerate(tids):
 | 
	
		
			
				|  |  | -            expected_messages[_tid] = []
 | 
	
		
			
				|  |  | -            expected_messages[_tid].append((states.PENDING, ''))
 | 
	
		
			
				|  |  | -            expected_messages[_tid].append(
 | 
	
		
			
				|  |  | -                (states.STARTED, 'comment_%i_1' % i),
 | 
	
		
			
				|  |  | -            )
 | 
	
		
			
				|  |  | -            expected_messages[_tid].append(
 | 
	
		
			
				|  |  | -                (states.STARTED, 'comment_%i_2' % i),
 | 
	
		
			
				|  |  | -            )
 | 
	
		
			
				|  |  | -            expected_messages[_tid].append(
 | 
	
		
			
				|  |  | -                (states.SUCCESS, 'final result %i' % i),
 | 
	
		
			
				|  |  | -            )
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        on_message_results = {}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        def on_message(body):
 | 
	
		
			
				|  |  | -            if not body['task_id'] in on_message_results:
 | 
	
		
			
				|  |  | -                on_message_results[body['task_id']] = []
 | 
	
		
			
				|  |  | -            on_message_results[body['task_id']].append(
 | 
	
		
			
				|  |  | -                (body['status'], body['result']),
 | 
	
		
			
				|  |  | -            )
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        list(b.get_many(tids, timeout=1, on_message=on_message))
 | 
	
		
			
				|  |  | -        self.assertEqual(sorted(on_message_results), sorted(expected_messages))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def test_get_many_raises_outer_block(self):
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        class Backend(AMQPBackend):
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            def Consumer(*args, **kwargs):
 | 
	
		
			
				|  |  | -                raise KeyError('foo')
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        b = Backend(self.app)
 | 
	
		
			
				|  |  | -        with self.assertRaises(KeyError):
 | 
	
		
			
				|  |  | -            next(b.get_many(['id1']))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def test_get_many_raises_inner_block(self):
 | 
	
		
			
				|  |  | -        with patch('kombu.connection.Connection.drain_events') as drain:
 | 
	
		
			
				|  |  | -            drain.side_effect = KeyError('foo')
 | 
	
		
			
				|  |  | -            b = AMQPBackend(self.app)
 | 
	
		
			
				|  |  | -            with self.assertRaises(KeyError):
 | 
	
		
			
				|  |  | -                next(b.get_many(['id1']))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def test_consume_raises_inner_block(self):
 | 
	
		
			
				|  |  | -        with patch('kombu.connection.Connection.drain_events') as drain:
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            def se(*args, **kwargs):
 | 
	
		
			
				|  |  | -                drain.side_effect = ValueError()
 | 
	
		
			
				|  |  | -                raise KeyError('foo')
 | 
	
		
			
				|  |  | -            drain.side_effect = se
 | 
	
		
			
				|  |  | -            b = AMQPBackend(self.app)
 | 
	
		
			
				|  |  | -            with self.assertRaises(ValueError):
 | 
	
		
			
				|  |  | -                next(b.consume('id1'))
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      def test_no_expires(self):
 | 
	
		
			
				|  |  |          b = self.create_backend(expires=None)
 | 
	
		
			
				|  |  |          app = self.app
 |