-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.4" | ||
before_script: | ||
- pip install python-coveralls coverage | ||
# command to run tests | ||
script: coverage run --source kombu_redis_priority setup.py test | ||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# kombu-redis-priority | ||
|
||
[![Build Status](https://travis-ci.org/Captricity/kombu-redis-priority.svg?branch=master)](https://travis-ci.org/Captricity/kombu-redis-priority) [![Coverage Status](https://coveralls.io/repos/Captricity/kombu-redis-priority/badge.png?branch=master)](https://coveralls.io/r/Captricity/kombu-redis-priority?branch=master) | ||
|
||
Kombu Transport using Redis SortedSets | ||
|
||
## Running tests | ||
|
||
python setup.py test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
import mock | ||
import fakeredis | ||
import freezegun | ||
import json | ||
import time | ||
import six | ||
|
||
from kombu import Connection | ||
from kombu_redis_priority.transport.redis_priority_async import redis, Transport | ||
|
||
|
||
class TestSortedSetTransport(unittest.TestCase): | ||
def setUp(self): | ||
self.faker = fakeredis.FakeStrictRedis() | ||
with mock.patch.object(redis, 'StrictRedis', fakeredis.FakeStrictRedis): | ||
self.connection = self.create_connection() | ||
self.channel = self.connection.default_channel | ||
|
||
def tearDown(self): | ||
self.faker.flushall() | ||
|
||
def create_connection(self): | ||
return Connection(transport=Transport) | ||
|
||
def _prefixed_message(self, time_, msg_obj): | ||
return six.b('{:011d}:'.format(int(time_)) + json.dumps(msg_obj)) | ||
|
||
def test_default_message_add(self): | ||
raw_db = self.faker._db | ||
|
||
# assert no queues exist | ||
self.assertEqual(len(raw_db), 0) | ||
|
||
# put a blank message, locking the time | ||
with freezegun.freeze_time('1985-10-12'): | ||
faketime = time.time() | ||
self.channel._put('foo', {}) | ||
|
||
# verify queue is created | ||
self.assertEqual(len(raw_db), 1) | ||
|
||
# ... and verify queue has a message | ||
raw_queue = raw_db['foo'] | ||
self.assertEqual(len(raw_queue), 1) | ||
|
||
# verify message: | ||
# - a time prefix is appended to the message | ||
# - has default priority (0) | ||
enqueued_msg, priority = next(six.iteritems(raw_queue)) | ||
self.assertEqual(enqueued_msg, self._prefixed_message(faketime, {})) | ||
self.assertEqual(priority, 0.0) | ||
|
||
def test_prioritized_message_add(self): | ||
raw_db = self.faker._db | ||
msg = {'properties': {'priority': 5}} | ||
|
||
# assert no queues exist | ||
self.assertEqual(len(raw_db), 0) | ||
|
||
# put a blank message, locking the time | ||
with freezegun.freeze_time('1985-10-12'): | ||
faketime = time.time() | ||
self.channel._put('foo', msg) | ||
|
||
# verify queue is created | ||
self.assertEqual(len(raw_db), 1) | ||
|
||
# ... and verify queue has a message | ||
raw_queue = raw_db['foo'] | ||
self.assertEqual(len(raw_queue), 1) | ||
|
||
# verify message: | ||
# - a time prefix is appended to the message | ||
# - has default priority (0) | ||
enqueued_msg, priority = next(six.iteritems(raw_queue)) | ||
self.assertEqual(enqueued_msg, self._prefixed_message(faketime, msg)) | ||
self.assertEqual(priority, 5.0) |