From 54fe738a0e12ffe98b9d7e80ad3c4eb5c015bbda Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Tue, 7 Mar 2017 13:39:53 +0000 Subject: [PATCH] Add assertions to test_reconstructor test_get_response Tighten up test to verify that 404 response results in a None return from reconstructor _get_response. Merge this test case into the test_get_response method to make use of the do_test() infrastructure. Add check for 503 response status. Also, use assertFalse to verify empty log lines, since a failure will then result in any log lines being shown in failure message. Related-Change: Iba86b495a14c15fc6eca8bf8a7df7d110256b0af Co-Authored-By: Clay Gerrard Change-Id: Ia83517e6d4c2f5eeb136abd4c04ddab639d40b9e --- test/unit/obj/test_reconstructor.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/unit/obj/test_reconstructor.py b/test/unit/obj/test_reconstructor.py index f0694bde9a..16881432f7 100644 --- a/test/unit/obj/test_reconstructor.py +++ b/test/unit/obj/test_reconstructor.py @@ -680,19 +680,21 @@ class TestGlobalSetupObjectReconstructor(unittest.TestCase): self.assertIn('Trying to GET', line) # sanity Timeout has extra message in the error log self.assertIn('Timeout', line) + self.logger.clear() - def test_reconstructor_does_not_log_on_404(self): - part = self.part_nums[0] - node = POLICIES[1].object_ring.get_part_nodes(int(part))[0] - with mocked_http_conn(404): - self.reconstructor._get_response(node, part, - path='some_path', - headers={}, - policy=POLICIES[1]) + # we should get a warning on 503 (sanity) + resp = do_test(503) + self.assertIsNone(resp) + warnings = self.logger.get_lines_for_level('warning') + self.assertEqual(1, len(warnings)) + self.assertIn('Invalid response 503', warnings[0]) + self.logger.clear() - # Make sure that no warnings are emitted for a 404 - len_warning_lines = len(self.logger.get_lines_for_level('warning')) - self.assertEqual(len_warning_lines, 0) + # ... but no messages should be emitted for 404 + resp = do_test(404) + self.assertIsNone(resp) + for level, msgs in self.logger.lines_dict.items(): + self.assertFalse(msgs) def test_reconstructor_skips_bogus_partition_dirs(self): # A directory in the wrong place shouldn't crash the reconstructor