def test_exit_with_stop(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = [_helper_threads.STOP, queue.Empty()] rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = True generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == []
def test_exit_with_stop(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = [helper_threads.STOP, queue.Empty()] rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = True generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == []
def test_exit_when_inactive_empty(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue.Empty() rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == []
def test_exit_when_inactive_empty(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue.Empty() rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == []
def test_yield_initial_and_exit(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue.Empty() rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator( q, initial_request=mock.sentinel.A) generator.rpc = rpc items = list(generator) assert items == [mock.sentinel.A]
def test_yield_initial_and_exit(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue.Empty() rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator( q, initial_request=mock.sentinel.A) generator.rpc = rpc items = list(generator) assert items == [mock.sentinel.A]
def test_exit_when_inactive_with_item(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = [mock.sentinel.A, queue.Empty()] rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == [] # Make sure it put the item back. q.put.assert_called_once_with(mock.sentinel.A)
def test_exit_when_inactive_with_item(self): q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = [mock.sentinel.A, queue.Empty()] rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = False generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == [] # Make sure it put the item back. q.put.assert_called_once_with(mock.sentinel.A)
def test_bounded_consume(self): rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = True def queue_generator(rpc): yield mock.sentinel.A yield queue.Empty() yield mock.sentinel.B rpc.is_active.return_value = False yield mock.sentinel.C q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue_generator(rpc) generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == [mock.sentinel.A, mock.sentinel.B]
def test_bounded_consume(self): rpc = mock.create_autospec(grpc.RpcContext, instance=True) rpc.is_active.return_value = True def queue_generator(rpc): yield mock.sentinel.A yield queue.Empty() yield mock.sentinel.B rpc.is_active.return_value = False yield mock.sentinel.C q = mock.create_autospec(queue.Queue, instance=True) q.get.side_effect = queue_generator(rpc) generator = _consumer._RequestQueueGenerator(q) generator.rpc = rpc items = list(generator) assert items == [mock.sentinel.A, mock.sentinel.B]