Add Tests for Queue Stats
This patch adds tests for Queue Stats. Change-Id: I7842eef98e6ed0a9809bea1a9b9d194c41b29d08
This commit is contained in:
parent
e96cee8b97
commit
dd17355a7f
@ -84,14 +84,30 @@ class FunctionalTestBase(testing.TestBase):
|
|||||||
self.assertTrue(required_values.issubset(actual_values),
|
self.assertTrue(required_values.issubset(actual_values),
|
||||||
msg=form.format((required_values - actual_values)))
|
msg=form.format((required_values - actual_values)))
|
||||||
|
|
||||||
def assertMessageCount(self, expectedCount, actualCount):
|
def assertMessageCount(self, actualCount, expectedCount):
|
||||||
"""Checks if number of messages returned <= limit
|
"""Checks if number of messages returned <= limit
|
||||||
|
|
||||||
:param expectedCount: limit value passed in the url (OR) default(10).
|
:param expectedCount: limit value passed in the url (OR) default(10).
|
||||||
:param actualCount: number of messages returned in the API response.
|
:param actualCount: number of messages returned in the API response.
|
||||||
"""
|
"""
|
||||||
self.assertTrue(actualCount <= expectedCount,
|
msg = 'More Messages returned than allowed: expected count = {0}' \
|
||||||
msg='More Messages returned than allowed')
|
', actual count = {1}'.format(expectedCount, actualCount)
|
||||||
|
self.assertTrue(actualCount <= expectedCount, msg)
|
||||||
|
|
||||||
|
def assertQueueStats(self, result_json, claimed):
|
||||||
|
"""Checks the Queue Stats results
|
||||||
|
|
||||||
|
:param result_json: json response returned for Queue Stats.
|
||||||
|
:param claimed: expected number of claimed messages.
|
||||||
|
"""
|
||||||
|
total = self.limits.message_paging_uplimit
|
||||||
|
free = total - claimed
|
||||||
|
|
||||||
|
self.assertEqual(result_json['messages']['claimed'], claimed)
|
||||||
|
self.assertEqual(result_json['messages']['free'],
|
||||||
|
free)
|
||||||
|
self.assertEqual(result_json['messages']['total'],
|
||||||
|
total)
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server(object):
|
||||||
|
@ -92,7 +92,7 @@ def single_message_body(**kwargs):
|
|||||||
return message_body
|
return message_body
|
||||||
|
|
||||||
|
|
||||||
def get_message_body(**kwargs):
|
def create_message_body(**kwargs):
|
||||||
"""Returns request body for post message tests.
|
"""Returns request body for post message tests.
|
||||||
|
|
||||||
:param **kwargs: can be {messagecount: x} , x is the # of messages.
|
:param **kwargs: can be {messagecount: x} , x is the # of messages.
|
||||||
|
@ -42,7 +42,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
|
|
||||||
#Post Messages
|
#Post Messages
|
||||||
url = self.queue_url + '/messages'
|
url = self.queue_url + '/messages'
|
||||||
doc = helpers.get_message_body(messagecount=
|
doc = helpers.create_message_body(messagecount=
|
||||||
self.limits.message_paging_uplimit)
|
self.limits.message_paging_uplimit)
|
||||||
for i in range(25):
|
for i in range(25):
|
||||||
self.client.post(url, data=doc)
|
self.client.post(url, data=doc)
|
||||||
@ -58,7 +58,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
actual_message_count = len(result.json())
|
actual_message_count = len(result.json())
|
||||||
self.assertMessageCount(message_count, actual_message_count)
|
self.assertMessageCount(actual_message_count, message_count)
|
||||||
|
|
||||||
response_headers = set(result.headers.keys())
|
response_headers = set(result.headers.keys())
|
||||||
self.assertIsSubset(self.headers_response_with_body, response_headers)
|
self.assertIsSubset(self.headers_response_with_body, response_headers)
|
||||||
|
@ -45,7 +45,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
This test also verifies that claimed messages are
|
This test also verifies that claimed messages are
|
||||||
retuned (or not) depending on the include_claimed flag.
|
retuned (or not) depending on the include_claimed flag.
|
||||||
"""
|
"""
|
||||||
doc = helpers.get_message_body(messagecount=1)
|
doc = helpers.create_message_body(messagecount=1)
|
||||||
|
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -87,8 +87,8 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def test_message_bulk_insert(self):
|
def test_message_bulk_insert(self):
|
||||||
"""Bulk Insert Messages into the Queue."""
|
"""Bulk Insert Messages into the Queue."""
|
||||||
message_count = 10
|
message_count = self.limits.message_paging_uplimit
|
||||||
doc = helpers.get_message_body(messagecount=message_count)
|
doc = helpers.create_message_body(messagecount=message_count)
|
||||||
|
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -119,7 +119,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
expected_msg_count = params.get('limit', 10)
|
expected_msg_count = params.get('limit', 10)
|
||||||
|
|
||||||
# Test Setup
|
# Test Setup
|
||||||
doc = helpers.get_message_body(messagecount=
|
doc = helpers.create_message_body(messagecount=
|
||||||
self.limits.message_paging_uplimit)
|
self.limits.message_paging_uplimit)
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -146,7 +146,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
def test_message_delete(self):
|
def test_message_delete(self):
|
||||||
"""Delete Message."""
|
"""Delete Message."""
|
||||||
# Test Setup
|
# Test Setup
|
||||||
doc = helpers.get_message_body(messagecount=1)
|
doc = helpers.create_message_body(messagecount=1)
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def test_message_bulk_delete(self):
|
def test_message_bulk_delete(self):
|
||||||
"""Bulk Delete Messages."""
|
"""Bulk Delete Messages."""
|
||||||
doc = helpers.get_message_body(messagecount=10)
|
doc = helpers.create_message_body(messagecount=10)
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -191,7 +191,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def test_message_partial_delete(self):
|
def test_message_partial_delete(self):
|
||||||
"""Delete Messages will be partially successful."""
|
"""Delete Messages will be partially successful."""
|
||||||
doc = helpers.get_message_body(messagecount=3)
|
doc = helpers.create_message_body(messagecount=3)
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -207,7 +207,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def test_message_partial_get(self):
|
def test_message_partial_get(self):
|
||||||
"""Get Messages will be partially successful."""
|
"""Get Messages will be partially successful."""
|
||||||
doc = helpers.get_message_body(messagecount=3)
|
doc = helpers.create_message_body(messagecount=3)
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
@ -226,7 +226,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
Marconi allows a maximum of 50 message per POST.
|
Marconi allows a maximum of 50 message per POST.
|
||||||
"""
|
"""
|
||||||
doc = helpers.get_message_body(messagecount=60)
|
doc = helpers.create_message_body(messagecount=60)
|
||||||
|
|
||||||
result = self.client.post(data=doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
@ -18,6 +18,7 @@ import ddt
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from marconi.tests.functional import base # noqa
|
from marconi.tests.functional import base # noqa
|
||||||
|
from marconi.tests.functional import helpers
|
||||||
|
|
||||||
|
|
||||||
class mystring(str):
|
class mystring(str):
|
||||||
@ -219,9 +220,14 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
|
|
||||||
self.client.set_base_url(self.base_url)
|
self.client.set_base_url(self.base_url)
|
||||||
|
|
||||||
|
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
|
||||||
|
|
||||||
def test_list_queues(self):
|
def test_list_queues(self):
|
||||||
"""List Queues."""
|
"""List Queues."""
|
||||||
|
|
||||||
|
self.client.put(self.queue_url)
|
||||||
|
self.addCleanup(self.client.delete, self.queue_url)
|
||||||
|
|
||||||
result = self.client.get('/queues')
|
result = self.client.get('/queues')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
@ -234,6 +240,9 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
def test_list_queues_detailed(self):
|
def test_list_queues_detailed(self):
|
||||||
"""List Queues with detailed = True."""
|
"""List Queues with detailed = True."""
|
||||||
|
|
||||||
|
self.client.put(self.queue_url)
|
||||||
|
self.addCleanup(self.client.delete, self.queue_url)
|
||||||
|
|
||||||
params = {'detailed': True}
|
params = {'detailed': True}
|
||||||
result = self.client.get('/queues', params=params)
|
result = self.client.get('/queues', params=params)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
@ -265,12 +274,12 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
def test_check_queue_exists(self):
|
def test_check_queue_exists(self):
|
||||||
"""Checks if queue exists."""
|
"""Checks if queue exists."""
|
||||||
|
|
||||||
path = '/queues/testqueue'
|
self.client.put(self.queue_url)
|
||||||
self.client.put(path)
|
self.addCleanup(self.client.delete, self.queue_url)
|
||||||
result = self.client.get(path)
|
result = self.client.get(self.queue_url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
result = self.client.head(path)
|
result = self.client.head(self.queue_url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_check_queue_exists.tags = ['positive']
|
test_check_queue_exists.tags = ['positive']
|
||||||
@ -294,3 +303,54 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_get_queue_malformed_marker.tags = ['negative']
|
test_get_queue_malformed_marker.tags = ['negative']
|
||||||
|
|
||||||
|
def test_get_stats_empty_queue(self):
|
||||||
|
"""Get queue stats on an empty queue."""
|
||||||
|
|
||||||
|
result = self.client.put(self.queue_url)
|
||||||
|
self.addCleanup(self.client.delete, self.queue_url)
|
||||||
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
|
stats_url = self.queue_url + '/stats'
|
||||||
|
|
||||||
|
#Get stats on an empty queue
|
||||||
|
result = self.client.get(stats_url)
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
expected_response = {'messages':
|
||||||
|
{'claimed': 0, 'total': 0, 'free': 0}}
|
||||||
|
self.assertEqual(result.json(), expected_response)
|
||||||
|
|
||||||
|
test_get_stats_empty_queue.tags = ['positive']
|
||||||
|
|
||||||
|
@ddt.data(0, 1)
|
||||||
|
def test_get_queue_stats_claimed(self, claimed):
|
||||||
|
"""Get stats on a queue."""
|
||||||
|
result = self.client.put(self.queue_url)
|
||||||
|
self.addCleanup(self.client.delete, self.queue_url)
|
||||||
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
|
#Post Messages to the test queue
|
||||||
|
doc = helpers.create_message_body(messagecount=
|
||||||
|
self.limits.message_paging_uplimit)
|
||||||
|
message_url = self.queue_url + '/messages'
|
||||||
|
result = self.client.post(message_url, data=doc)
|
||||||
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
|
if claimed > 0:
|
||||||
|
claim_url = self.queue_url + '/claims?limit=' + str(claimed)
|
||||||
|
doc = {'ttl': 300, 'grace': 300}
|
||||||
|
result = self.client.post(claim_url, data=doc)
|
||||||
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
|
#Get stats on the queue.
|
||||||
|
stats_url = self.queue_url + '/stats'
|
||||||
|
result = self.client.get(stats_url)
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
self.assertQueueStats(result.json(), claimed)
|
||||||
|
|
||||||
|
test_get_queue_stats_claimed.tags = ['positive']
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super(TestQueueMisc, self).tearDown()
|
||||||
|
Loading…
Reference in New Issue
Block a user