
Eventlet now deprecate TimeoutError exception [1]. Updating eventlet to latest 0.21.0 can cause UT fail because of misunderstood between deprecated exception and the new exception class Timeout. [2] This patch remove deprecated exception usage, fix the UT failure with eventlet 0.21.0 in order to upgrade eventlet upper-constraint to latest version. [1]. https://github.com/eventlet/eventlet/blob/master/eventlet/__init__.py#L55 [2]. https://review.openstack.org/#/c/460424/ Change-Id: I48179953ef19ec6b2f3f6706337a1dae1b3830bd
92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
# Copyright 2014 OpenStack Foundation
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""Tests to test the test framework"""
|
|
|
|
import sys
|
|
|
|
import eventlet.timeout
|
|
import unittest2
|
|
|
|
from neutron.tests import base
|
|
|
|
|
|
class BrokenExceptionHandlerTestCase(base.DietTestCase):
|
|
# Embedded to hide from the regular test discovery
|
|
class MyTestCase(base.DietTestCase):
|
|
def setUp(self):
|
|
super(BrokenExceptionHandlerTestCase.MyTestCase, self).setUp()
|
|
self.addOnException(self._diag_collect)
|
|
|
|
def _diag_collect(self, exc_info):
|
|
raise ValueError('whoopsie daisy')
|
|
|
|
def runTest(self):
|
|
raise IndexError("Thou shalt not pass by reference")
|
|
|
|
def test_broken_exception_handler(self):
|
|
result = self.MyTestCase().run()
|
|
# ensure both exceptions are logged
|
|
self.assertIn('Thou shalt', result.errors[0][1])
|
|
self.assertIn('whoopsie', result.errors[0][1])
|
|
self.assertFalse(result.wasSuccessful())
|
|
|
|
|
|
class SystemExitTestCase(base.DietTestCase):
|
|
# Embedded to hide from the regular test discovery
|
|
class MyTestCase(base.DietTestCase):
|
|
def __init__(self, exitcode):
|
|
super(SystemExitTestCase.MyTestCase, self).__init__()
|
|
self.exitcode = exitcode
|
|
|
|
def runTest(self):
|
|
if self.exitcode is not None:
|
|
sys.exit(self.exitcode)
|
|
|
|
def test_no_sysexit(self):
|
|
result = self.MyTestCase(exitcode=None).run()
|
|
self.assertTrue(result.wasSuccessful())
|
|
|
|
def test_sysexit(self):
|
|
expectedFails = [self.MyTestCase(exitcode) for exitcode in (0, 1)]
|
|
|
|
suite = unittest2.TestSuite(tests=expectedFails)
|
|
result = self.defaultTestResult()
|
|
try:
|
|
suite.run(result)
|
|
except SystemExit:
|
|
self.fail('SystemExit escaped!')
|
|
|
|
self.assertEqual([], result.errors)
|
|
self.assertItemsEqual(set(id(t) for t in expectedFails),
|
|
set(id(t) for (t, traceback) in result.failures))
|
|
|
|
|
|
class CatchTimeoutTestCase(base.DietTestCase):
|
|
# Embedded to hide from the regular test discovery
|
|
class MyTestCase(base.DietTestCase):
|
|
def test_case(self):
|
|
raise eventlet.Timeout()
|
|
|
|
def runTest(self):
|
|
return self.test_case()
|
|
|
|
def test_catch_timeout(self):
|
|
try:
|
|
result = self.MyTestCase().run()
|
|
self.assertFalse(result.wasSuccessful())
|
|
except eventlet.Timeout:
|
|
self.fail('Timeout escaped!')
|