def test_node_errors(self): self.app.sort_nodes = lambda n: n for method in ('PUT', 'DELETE', 'POST'): def test_status_map(statuses, expected): self.app._error_limiting = {} req = Request.blank('/v1/a/c', method=method) with mocked_http_conn(*statuses) as fake_conn: print 'a' * 50 resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) for req in fake_conn.requests: self.assertEqual(req['method'], method) self.assert_(req['path'].endswith('/a/c')) base_status = [201] * 3 # test happy path test_status_map(list(base_status), 201) for i in range(3): self.assertEqual( node_error_count(self.app, self.container_ring.devs[i]), 0) # single node errors and test isolation for i in range(3): status_list = list(base_status) status_list[i] = 503 status_list.append(201) test_status_map(status_list, 201) for j in range(3): expected = 1 if j == i else 0 self.assertEqual( node_error_count(self.app, self.container_ring.devs[j]), expected) # timeout test_status_map((201, Timeout(), 201, 201), 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[1]), 1) # exception test_status_map((Exception('kaboom!'), 201, 201, 201), 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[0]), 1) # insufficient storage test_status_map((201, 201, 507, 201), 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[2]), self.app.error_suppression_limit + 1)
def test_PUT_connect_exceptions(self): object_ring = self.app.get_object_ring(None) self.app.sort_nodes = lambda n: n # disable shuffle def test_status_map(statuses, expected): self.app._error_limiting = {} req = swob.Request.blank('/v1/a/c/o.jpg', method='PUT', body='test body') with set_http_connect(*statuses): resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) base_status = [201] * 3 # test happy path test_status_map(list(base_status), 201) for i in range(3): self.assertEqual(node_error_count( self.app, object_ring.devs[i]), 0) # single node errors and test isolation for i in range(3): status_list = list(base_status) status_list[i] = 503 test_status_map(status_list, 201) for j in range(3): self.assertEqual(node_error_count( self.app, object_ring.devs[j]), 1 if j == i else 0) # connect errors test_status_map((201, Timeout(), 201, 201), 201) self.assertEqual(node_error_count( self.app, object_ring.devs[1]), 1) test_status_map((Exception('kaboom!'), 201, 201, 201), 201) self.assertEqual(node_error_count( self.app, object_ring.devs[0]), 1) # expect errors test_status_map((201, 201, (503, None), 201), 201) self.assertEqual(node_error_count( self.app, object_ring.devs[2]), 1) test_status_map(((507, None), 201, 201, 201), 201) self.assertEqual( node_error_count(self.app, object_ring.devs[0]), self.app.error_suppression_limit + 1) # response errors test_status_map(((100, Timeout()), 201, 201), 201) self.assertEqual( node_error_count(self.app, object_ring.devs[0]), 1) test_status_map((201, 201, (100, Exception())), 201) self.assertEqual( node_error_count(self.app, object_ring.devs[2]), 1) test_status_map((201, (100, 507), 201), 201) self.assertEqual( node_error_count(self.app, object_ring.devs[1]), self.app.error_suppression_limit + 1)
def test_node_errors(self): self.app.sort_nodes = lambda n: n for method in ('PUT', 'DELETE', 'POST'): def test_status_map(statuses, expected): self.app._error_limiting = {} req = Request.blank('/v1/a/c', method=method) with mocked_http_conn(*statuses) as fake_conn: print('a' * 50) resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) for req in fake_conn.requests: self.assertEqual(req['method'], method) self.assertTrue(req['path'].endswith('/a/c')) base_status = [201] * 3 # test happy path test_status_map(list(base_status), 201) for i in range(3): self.assertEqual(node_error_count( self.app, self.container_ring.devs[i]), 0) # single node errors and test isolation for i in range(3): status_list = list(base_status) status_list[i] = 503 status_list.append(201) test_status_map(status_list, 201) for j in range(3): expected = 1 if j == i else 0 self.assertEqual(node_error_count( self.app, self.container_ring.devs[j]), expected) # timeout test_status_map((201, Timeout(), 201, 201), 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[1]), 1) # exception test_status_map((Exception('kaboom!'), 201, 201, 201), 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[0]), 1) # insufficient storage test_status_map((201, 201, 507, 201), 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[2]), self.app.error_suppression_limit + 1)
def test_node_errors(self): self.app.sort_nodes = lambda n, *args, **kwargs: n for method in ('PUT', 'DELETE', 'POST'): def test_status_map(statuses, expected): self.app._error_limiting = {} req = Request.blank('/v1/a/c', method=method) with mocked_http_conn(*statuses) as fake_conn: resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) for req in fake_conn.requests: self.assertEqual(req['method'], method) self.assertTrue(req['path'].endswith('/a/c')) base_status = [201] * self.CONTAINER_REPLICAS # test happy path test_status_map(list(base_status), 201) for i in range(self.CONTAINER_REPLICAS): self.assertEqual( node_error_count(self.app, self.container_ring.devs[i]), 0) # single node errors and test isolation for i in range(self.CONTAINER_REPLICAS): test_status_map(base_status[:i] + [503] + base_status[i:], 201) for j in range(self.CONTAINER_REPLICAS): expected = 1 if j == i else 0 self.assertEqual( node_error_count(self.app, self.container_ring.devs[j]), expected) # timeout test_status_map(base_status[:1] + [Timeout()] + base_status[1:], 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[1]), 1) # exception test_status_map([Exception('kaboom!')] + base_status, 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[0]), 1) # insufficient storage test_status_map(base_status[:2] + [507] + base_status[2:], 201) self.assertEqual( node_error_count(self.app, self.container_ring.devs[2]), self.app.error_suppression_limit + 1)
def test_node_errors(self): self.app.sort_nodes = lambda n, *args, **kwargs: n for method in ('PUT', 'DELETE', 'POST'): def test_status_map(statuses, expected): self.app._error_limiting = {} req = Request.blank('/v1/a/c', method=method) with mocked_http_conn(*statuses) as fake_conn: resp = req.get_response(self.app) self.assertEqual(resp.status_int, expected) for req in fake_conn.requests: self.assertEqual(req['method'], method) self.assertTrue(req['path'].endswith('/a/c')) base_status = [201] * self.CONTAINER_REPLICAS # test happy path test_status_map(list(base_status), 201) for i in range(self.CONTAINER_REPLICAS): self.assertEqual(node_error_count( self.app, self.container_ring.devs[i]), 0) # single node errors and test isolation for i in range(self.CONTAINER_REPLICAS): test_status_map(base_status[:i] + [503] + base_status[i:], 201) for j in range(self.CONTAINER_REPLICAS): expected = 1 if j == i else 0 self.assertEqual(node_error_count( self.app, self.container_ring.devs[j]), expected) # timeout test_status_map(base_status[:1] + [Timeout()] + base_status[1:], 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[1]), 1) # exception test_status_map([Exception('kaboom!')] + base_status, 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[0]), 1) # insufficient storage test_status_map(base_status[:2] + [507] + base_status[2:], 201) self.assertEqual(node_error_count( self.app, self.container_ring.devs[2]), self.app.error_suppression_limit + 1)