From 8556b06bf75e46369088f1cc6e2aa5d6cc00251b Mon Sep 17 00:00:00 2001 From: Christian Schwede Date: Wed, 20 Sep 2017 10:56:41 +0200 Subject: [PATCH] Add test to ensure cache cleared after container PUT The parent commit fixes a race condition. Let's make sure there won't be a regression in the future, thus testing the order to ensure the cache is cleared after the request is executed. Related-Bug: #1715177 Change-Id: I4f6750b7c556b498da0a2b56aa6c8cee5e42a90c --- test/unit/proxy/controllers/test_container.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index 548e3342cf..03d53c2fde 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.py @@ -21,7 +21,7 @@ from eventlet import Timeout from swift.common.swob import Request from swift.proxy import server as proxy_server -from swift.proxy.controllers.base import headers_to_container_info +from swift.proxy.controllers.base import headers_to_container_info, Controller from test.unit import fake_http_connect, FakeRing, FakeMemcache from swift.common.storage_policy import StoragePolicy from swift.common.request_helpers import get_sys_meta_prefix @@ -111,6 +111,24 @@ class TestContainerController(TestRingBase): from_memcache = self.app.memcache.get('container/a/c') self.assertTrue(from_memcache) + @mock.patch('swift.proxy.controllers.container.clear_info_cache') + @mock.patch.object(Controller, 'make_requests') + def test_container_cache_cleared_after_PUT( + self, mock_make_requests, mock_clear_info_cache): + parent_mock = mock.Mock() + parent_mock.attach_mock(mock_make_requests, 'make_requests') + parent_mock.attach_mock(mock_clear_info_cache, 'clear_info_cache') + controller = proxy_server.ContainerController(self.app, 'a', 'c') + callback = self._make_callback_func({}) + req = Request.blank('/v1/a/c') + with mock.patch('swift.proxy.controllers.base.http_connect', + fake_http_connect(200, 200, give_connect=callback)): + controller.PUT(req) + + # Ensure cache is cleared after the PUT request + self.assertEqual(parent_mock.mock_calls[0][0], 'make_requests') + self.assertEqual(parent_mock.mock_calls[1][0], 'clear_info_cache') + def test_swift_owner(self): owner_headers = { 'x-container-read': 'value', 'x-container-write': 'value',