'Test that we wait for loopcalls only if stop succeeds.'

@mock.patch('cinder.service.Service.is_svc_upgrading_to_n', return_value=False)
@mock.patch('cinder.service.Service.report_state')
@mock.patch('cinder.service.Service.periodic_tasks')
@mock.patch.object(service.loopingcall, 'FixedIntervalLoopingCall')
@mock.patch.object(rpc, 'get_server')
@mock.patch('cinder.db')
def test_service_stop_waits_for_timers(self, mock_db, mock_rpc, mock_loopcall, mock_periodic, mock_report, is_upgrading_mock):

    serv = service.Service(self.host, self.binary, self.topic, 'cinder.tests.unit.test_service.FakeManager', report_interval=5, periodic_interval=10)
    mock_loopcall.side_effect = (mock.Mock(**{'stop.side_effect': Exception}), mock.Mock())
    serv.start()
    serv.stop()
    serv.wait()
    serv.rpcserver.start.assert_called_once_with()
    serv.rpcserver.stop.assert_called_once_with()
    serv.rpcserver.wait.assert_called_once_with()
    self.assertEqual(1, serv.timers[0].start.call_count)
    self.assertEqual(1, serv.timers[0].stop.call_count)
    self.assertFalse(serv.timers[0].wait.called)
    self.assertEqual(1, serv.timers[1].start.call_count)
    self.assertEqual(1, serv.timers[1].stop.call_count)
    self.assertEqual(1, serv.timers[1].wait.call_count)
