Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: port check storage command into Rust
Browse files Browse the repository at this point in the history
Co-authored by: Phil Jenvey <[email protected]>

Some components of CheckStorage are left in Python as they're used
by the delete tests.

Closes #1189
  • Loading branch information
bbangert committed May 4, 2018
1 parent 77dab57 commit a9f6fc2
Show file tree
Hide file tree
Showing 12 changed files with 722 additions and 333 deletions.
6 changes: 2 additions & 4 deletions autopush/tests/test_rs_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ def test_hello_only_has_three_calls(self):
result = yield client.hello()
assert result != {}
assert result["use_webpush"] is True
yield client.wait_for(lambda: len(db.DB_CALLS) == 4)
assert db.DB_CALLS == ['register_user', 'register_user',
'fetch_messages',
'fetch_timestamp_messages']
yield client.wait_for(lambda: len(db.DB_CALLS) == 2)
assert db.DB_CALLS == ['register_user', 'register_user']
db.DB_CALLS = []
db.TRACK_DB_CALLS = False

Expand Down
69 changes: 0 additions & 69 deletions autopush/tests/test_webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,75 +269,6 @@ def test_existing_newer_uaid(self):
assert result.uaid is None


class TestCheckStorageProcessor(BaseSetup):
def _makeFUT(self):
from autopush.webpush_server import CheckStorageCommand
return CheckStorageCommand(self.conf, self.db)

def test_no_messages(self):
p = self._makeFUT()
check = CheckStorageFactory(message_month=self.db.current_msg_month)
result = p.process(check)
assert len(result.messages) == 0

def test_five_messages(self):
p = self._makeFUT()
check = CheckStorageFactory(message_month=self.db.current_msg_month)
self._store_messages(check.uaid, num=5)
result = p.process(check)
assert len(result.messages) == 5

def test_many_messages(self):
"""Test many messages to fill the batches with topics and non-topic
This is a long test, intended to ensure that all the topic messages
properly come out and set whether to include the topic flag again or
proceed to get non-topic messages.
"""
p = self._makeFUT()
check = CheckStorageFactory(message_month=self.db.current_msg_month)
self._store_messages(check.uaid, topic=True, num=22)
self._store_messages(check.uaid, num=15)
result = p.process(check)
assert len(result.messages) == 10

# Delete all the messages returned
for msg in result.messages:
notif = msg.to_WebPushNotification()
self.db.message.delete_message(notif)

check.timestamp = result.timestamp
check.include_topic = result.include_topic
result = p.process(check)
assert len(result.messages) == 10

# Delete all the messages returned
for msg in result.messages:
notif = msg.to_WebPushNotification()
self.db.message.delete_message(notif)

check.timestamp = result.timestamp
check.include_topic = result.include_topic
result = p.process(check)
assert len(result.messages) == 2

# Delete all the messages returned
for msg in result.messages:
notif = msg.to_WebPushNotification()
self.db.message.delete_message(notif)

check.timestamp = result.timestamp
check.include_topic = result.include_topic
result = p.process(check)
assert len(result.messages) == 10

check.timestamp = result.timestamp
check.include_topic = result.include_topic
result = p.process(check)
assert len(result.messages) == 5


class TestDeleteMessageProcessor(BaseSetup):
def _makeFUT(self):
from autopush.webpush_server import DeleteMessageCommand
Expand Down
2 changes: 0 additions & 2 deletions autopush/webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ def __init__(self, conf, db):
self.store_messages_process = StoreMessagesUserCommand(conf, db)
self.deserialize = dict(
hello=Hello,
check_storage=CheckStorage,
delete_message=DeleteMessage,
drop_user=DropUser,
migrate_user=MigrateUser,
Expand All @@ -302,7 +301,6 @@ def __init__(self, conf, db):
)
self.command_dict = dict(
hello=self.hello_processor,
check_storage=self.check_storage_processor,
delete_message=self.delete_message_processor,
drop_user=self.drop_user_processor,
migrate_user=self.migrate_user_proocessor,
Expand Down
Loading

0 comments on commit a9f6fc2

Please sign in to comment.