def test_queue_only_logs_once_when_backing_off(self, logger):
        (logger
            .expects('info')
            .with_args(
                'backing off hotqueue:nicey on '
                '127.0.0.1 (queue size: 10001)')
            .next_call()
            .with_args(
                'inserting into hotqueue:nicey on '
                '127.0.0.1 again (queue size: 10001)')
        )
        fake_queue = FakeStaysFullQueue()
        fake_queue.put = fudge.Fake('put').is_callable().expects_call()

        queue = NiceHotQueue(fake_queue)
        queue.backOffABit = (
            fudge.Fake('backOffABit')
                .is_callable()
                .expects_call()
                .times_called(3)
            )
        queue.queueIsTooFull = (
            fudge.Fake('queueIsTooFull')
                .is_callable()
                .returns(True)
                .next_call()
                .returns(True)
                .next_call()
                .returns(True)
                .next_call()
                .returns(False))
        queue.put('something')
    def test_put_doesnt_sleep_if_the_queue_is_empty(self):
        fake_queue = FakeEmptyQueue()
        fake_queue.put = fudge.Fake('put').is_callable().expects_call()

        queue = NiceHotQueue(fake_queue)
        queue.backOffABit = fudge.Fake('backOffABit')
        queue.put("something")
    def test_smaller_queue(self):
        fake_queue = FakeSmallQueue()
        fake_queue.put = fudge.Fake('put').is_callable().expects_call()

        queue = NiceHotQueue(fake_queue, max_queue_size=1)
        queue.backOffABit = fudge.Fake('backOffABit').is_callable().expects_call().times_called(1)
        queue.put("something")
    def test_put_sleeps_if_the_queue_is_too_full(self):
        fake_queue = FakeFullQueue()
        fake_queue.put = fudge.Fake('put').is_callable().expects_call()

        queue = NiceHotQueue(fake_queue)
        queue.backOffABit = fudge.Fake('backOffABit').is_callable().expects_call().times_called(1)
        queue.put("something")