Fix bug in mongodb backend for dead letter queue
In the function{ClaimController:create} for mongodb backend, there is an error when a message is inserted to the dead letter queue.Because a mongodb collection(messages) is shared by many queues, we need to delete first and then insert, otherwise insert_one will cause the following error: pymongo.errors.DuplicateKeyError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: admin.test.$_id_ dup key: { : ObjectId('xxxxxxxxxxxxxxxxxxxxxx') } Depends-On: I1ee88a8963e2bc80172710da5ab60313952495e4 Depends-On: I8c3642f3883ecc68853735636fc3a748b9c780b6 Closes-Bug: #1707814 Change-Id: If7824d135ecd6999716954e6fa4fa000434c4ed4
This commit is contained in:
parent
490a44b733
commit
570baba42b
@ -13,6 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib.common.utils import data_utils
|
from tempest.lib.common.utils import data_utils
|
||||||
@ -108,6 +110,44 @@ class TestClaims(base.BaseV2MessagingTest):
|
|||||||
message_uri = urlparse.urlparse(claim_uri).path
|
message_uri = urlparse.urlparse(claim_uri).path
|
||||||
self.client.delete_messages(message_uri)
|
self.client.delete_messages(message_uri)
|
||||||
|
|
||||||
|
@decorators.idempotent_id('c1975970-66e7-11e7-a771-fa163e40e1ff')
|
||||||
|
def test_dead_letter_queue(self):
|
||||||
|
# Post Messages
|
||||||
|
QueueName = "QueueWithDLQ"
|
||||||
|
DLQ_name = "DLQ"
|
||||||
|
meta = {'ttl': 60, 'grace': 60}
|
||||||
|
# Set dead letter queeu metadata
|
||||||
|
op1 = {"op": "add",
|
||||||
|
"path": "/metadata/_max_claim_count", "value": 2}
|
||||||
|
op2 = {"op": "add",
|
||||||
|
"path": "/metadata/_dead_letter_queue", "value": DLQ_name}
|
||||||
|
op3 = {"op": "add",
|
||||||
|
"path": "/metadata/_dead_letter_queue_messages_ttl",
|
||||||
|
"value": 7799}
|
||||||
|
metadata = [op1, op2, op3]
|
||||||
|
self.client.create_queue(QueueName)
|
||||||
|
self.client.create_queue(DLQ_name)
|
||||||
|
self.set_queue_metadata(QueueName, metadata)
|
||||||
|
message_body = self.generate_message_body(repeat=1)
|
||||||
|
self.client.post_messages(queue_name=QueueName,
|
||||||
|
rbody=message_body)
|
||||||
|
|
||||||
|
for i in range(3):
|
||||||
|
resp, body = self.client.post_claims(
|
||||||
|
queue_name=QueueName,
|
||||||
|
rbody=meta)
|
||||||
|
if(i == 2):
|
||||||
|
self.assertEqual('204', resp['status'])
|
||||||
|
else:
|
||||||
|
self.assertEqual('201', resp['status'])
|
||||||
|
self.assertEqual(1, len(body["messages"]))
|
||||||
|
time.sleep(70)
|
||||||
|
|
||||||
|
resp, body = self.client.list_messages(DLQ_name)
|
||||||
|
self.assertEqual('200', resp['status'])
|
||||||
|
self.client.delete_queue(DLQ_name)
|
||||||
|
self.client.delete_queue(QueueName)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resource_cleanup(cls):
|
def resource_cleanup(cls):
|
||||||
cls.delete_queue(cls.queue_name)
|
cls.delete_queue(cls.queue_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user