def test_run_notifications_with_routing_keys(self):
     mock_logger = self._create_mock_logger()
     stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)
     self._mock_exchange_create_and_connect(
         self.verifier_with_notifications)
     self.mox.StubOutWithMock(self.verifier_with_notifications, '_run')
     self.verifier_with_notifications._run(callback=mox.Not(mox.Is(None)))
     self.mox.ReplayAll()
     self.verifier_with_notifications.run()
     self.mox.VerifyAll()
    def test_run_full(self):
        mock_logger = self._create_mock_logger()
        mock_logger.info('exchange: N: None, P: 0, S: 2, E: 0')
        stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)
        stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)

        self.mox.StubOutWithMock(transaction, 'commit_on_success')
        tran = self.mox.CreateMockAnything()
        tran.__enter__().AndReturn(tran)
        tran.__exit__(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        transaction.commit_on_success().AndReturn(tran)
        self._mock_exchange_create_and_connect(
            self.verifier_with_notifications)
        self.verifier_with_notifications.exchange().AndReturn('exchange')
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 '_keep_running')
        self.verifier_with_notifications._keep_running().AndReturn(True)
        start = datetime.datetime.utcnow()
        self.mox.StubOutWithMock(self.verifier_with_notifications, '_utcnow')
        self.verifier_with_notifications._utcnow().AndReturn(start)
        self.verifier_with_notifications._utcnow().AndReturn(start)
        settle_offset = {SETTLE_UNITS: SETTLE_TIME}
        ending_max = start - datetime.timedelta(**settle_offset)
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 'verify_for_range')
        self.verifier_with_notifications.verify_for_range(ending_max,
                                                          callback=mox.Not(
                                                              mox.Is(None)))
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 'reconcile_failed')
        result1 = self.mox.CreateMockAnything()
        result2 = self.mox.CreateMockAnything()
        self.verifier_with_notifications.results = [result1, result2]
        result1.ready().AndReturn(True)
        result1.successful().AndReturn(True)
        result1.get().AndReturn((True, None))
        result2.ready().AndReturn(True)
        result2.successful().AndReturn(True)
        result2.get().AndReturn((True, None))
        self.verifier_with_notifications.reconcile_failed()
        self.mox.StubOutWithMock(time, 'sleep', use_mock_anything=True)
        time.sleep(TICK_TIME)
        self.verifier_with_notifications._keep_running().AndReturn(False)
        self.mox.ReplayAll()

        self.verifier_with_notifications.run()

        self.mox.VerifyAll()