From b16ef6d0212b27cc53fdd88d505f344a6195badd Mon Sep 17 00:00:00 2001 From: git-harry Date: Thu, 13 Nov 2014 21:50:23 +0000 Subject: [PATCH] Mock cinder.wsgi.Server in TestWSGIService The fixed tests were binding to port 8776. These unit tests should not be starting the wsgi app and so the class has been mocked. Change-Id: I52b8ce4788741a0802d4d91d413474101542a3e0 Closes-bug: #1392498 --- cinder/tests/test_service.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cinder/tests/test_service.py b/cinder/tests/test_service.py index e7d1560df..e82e1c51c 100644 --- a/cinder/tests/test_service.py +++ b/cinder/tests/test_service.py @@ -232,26 +232,31 @@ class TestWSGIService(test.TestCase): self.assertEqual(test_service.server._pool.size, 1000) - def test_workers_set_default(self): + @mock.patch('cinder.wsgi.Server') + def test_workers_set_default(self, wsgi_server): test_service = service.WSGIService("osapi_volume") self.assertEqual(test_service.workers, processutils.get_worker_count()) - def test_workers_set_good_user_setting(self): + @mock.patch('cinder.wsgi.Server') + def test_workers_set_good_user_setting(self, wsgi_server): self.override_config('osapi_volume_workers', 8) test_service = service.WSGIService("osapi_volume") self.assertEqual(test_service.workers, 8) - def test_workers_set_zero_user_setting(self): + @mock.patch('cinder.wsgi.Server') + def test_workers_set_zero_user_setting(self, wsgi_server): self.override_config('osapi_volume_workers', 0) test_service = service.WSGIService("osapi_volume") # If a value less than 1 is used, defaults to number of procs available self.assertEqual(test_service.workers, processutils.get_worker_count()) - def test_workers_set_negative_user_setting(self): + @mock.patch('cinder.wsgi.Server') + def test_workers_set_negative_user_setting(self, wsgi_server): self.override_config('osapi_volume_workers', -1) self.assertRaises(exception.InvalidInput, service.WSGIService, "osapi_volume") + self.assertFalse(wsgi_server.called) class OSCompatibilityTestCase(test.TestCase): -- 2.45.2