From bc58c1d2fb22b378736e33a3f406c5c4339ae8c6 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Fri, 25 Aug 2023 16:15:29 +0200 Subject: [PATCH] [functional]Fix remaining greenlet leaks We leak due to running background operations like server create, rebuild and in one case a sleeping claim. So this patch removes the leaks by making sure that the background operations stop before the test finishes. As there is no more leak in functional test too this patch makes the leak an error there too. Change-Id: I6905999050e8d09b772837034a212c534e9c3226 --- nova/tests/functional/compute/test_init_host.py | 8 +++++++- .../functional/test_legacy_v2_compatible_wrapper.py | 1 + nova/tests/functional/test_servers.py | 5 ++++- tox.ini | 10 +++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nova/tests/functional/compute/test_init_host.py b/nova/tests/functional/compute/test_init_host.py index f5c821e11617..f16117009751 100644 --- a/nova/tests/functional/compute/test_init_host.py +++ b/nova/tests/functional/compute/test_init_host.py @@ -10,9 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. +import threading import time from unittest import mock + from nova import context as nova_context from nova import objects from nova.tests.functional import integrated_helpers @@ -151,8 +153,10 @@ class TestComputeRestartInstanceStuckInBuild( image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6', networks='none') + stop = threading.Event() + def sleep_forever(*args, **kwargs): - time.sleep(1000000) + stop.wait(1000000) with mock.patch('nova.compute.resource_tracker.ResourceTracker.' 'instance_claim') as mock_instance_claim: @@ -176,3 +180,5 @@ class TestComputeRestartInstanceStuckInBuild( 'Instance spawn was interrupted before instance_claim, setting ' 'instance to ERROR state', instance=mock.ANY) + + stop.set() diff --git a/nova/tests/functional/test_legacy_v2_compatible_wrapper.py b/nova/tests/functional/test_legacy_v2_compatible_wrapper.py index a0909077ac40..765b0865358d 100644 --- a/nova/tests/functional/test_legacy_v2_compatible_wrapper.py +++ b/nova/tests/functional/test_legacy_v2_compatible_wrapper.py @@ -80,3 +80,4 @@ class LegacyV2CompatibleTestBase(integrated_helpers._IntegratedTestBase): 'x' * 300: 'y', 'h' * 300: 'i'}) self.assertEqual(exc.response.status_code, 400) + self.api.delete_server(created_server['id']) diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index ab608995b38b..a9c3d9acbf3e 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -1086,7 +1086,8 @@ class ServersTestV219(integrated_helpers._IntegratedTestBase): # Update and rebuild servers with invalid descriptions. # These throw 400. - server_id = self._create_server(True, "desc")[1]['id'] + server = self._create_server(True, "desc")[1] + server_id = server['id'] # Invalid unicode with non-printable control char self._update_assertRaisesRegex(server_id, u'invalid\u0604string') self._rebuild_assertRaisesRegex(server_id, u'invalid\u0604string') @@ -1094,6 +1095,8 @@ class ServersTestV219(integrated_helpers._IntegratedTestBase): self._update_assertRaisesRegex(server_id, 'x' * 256) self._rebuild_assertRaisesRegex(server_id, 'x' * 256) + self._delete_server(server) + class ServerTestV220(integrated_helpers._IntegratedTestBase): api_major_version = 'v2.1' diff --git a/tox.ini b/tox.ini index 49cf8cf5d427..7d93ff9438b4 100644 --- a/tox.ini +++ b/tox.ini @@ -36,9 +36,8 @@ passenv = # greenlet leaks will be annotated in the test details but will not cause a # failure. if you want to make them raise set # NOVA_RAISE_ON_GREENLET_LEAK=1|true|yes -# All simiple leaks of green threads have been resolved the remaining 7 -# functional test failures where greenlet leaks happen are non trivial -# to address as there is no obvious cause so they are ignored for now. +# All leaks of green threads have been resolved in the unit and functional +# suite NOVA_RAISE_ON_GREENLET_LEAK # NOTE(sean-k-mooney) optimization is enabled by default and when enabled # asserts are complied out. Disable optimization to allow asserts in @@ -62,6 +61,11 @@ setenv = [testenv:functional{,-py38,-py39,-py310,-py311}] description = Run functional tests. +setenv = + {[testenv]setenv} +# we do not have any greenlet leaks in functional tests so enforce that +# by making greenlet leaks a failure. + NOVA_RAISE_ON_GREENLET_LEAK=True # As nova functional tests import the PlacementFixture from the placement # repository these tests are, by default, set up to run with openstack-placement # from pypi. In the gate, Zuul will use the installed version of placement (stable