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

Commit

Permalink
feat: fix asserts on client dis/connect and convert inc call to rust
Browse files Browse the repository at this point in the history
Removes the asserts when adding the uaid to the uaids hash, and issue
proper disconnect call to existing client. Ensure uaid removal removes
the right client indicated by a separate UUID per client object.

Convert IncrementStorage call to pure Rust async and remove Python
implementation.

Closes #1177
  • Loading branch information
bbangert committed Apr 17, 2018
1 parent 077b1e7 commit a481959
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -28,7 +28,7 @@ install:
- pip install tox ${CODECOV:+codecov}
- if [ ${WITH_RUST:-true} != "false" ]; then curl https://sh.rustup.rs | sh -s -- -y || travis_terminate 1; fi
- export PATH=$PATH:$HOME/.cargo/bin
- export AWS_SHARED_CREDENTIALS_FILE=./automock/credentials.cfg
- export AWS_SHARED_CREDENTIALS_FILE=./automock/boto.cfg
- export BOTO_CONFIG=./automock/boto.cfg
script:
- tox -- ${CODECOV:+--with-coverage --cover-xml --cover-package=autopush}
Expand Down
2 changes: 2 additions & 0 deletions automock/boto.cfg
@@ -1,4 +1,6 @@
[default]
aws_access_key_id=ASDFASDFASDFASDFASDFSD
aws_secret_access_key=ASDFASDFASDFASDFASDFASDFASDFASDFASDFASDFASDF
endpoint_url = http://localhost:8000

[Boto]
Expand Down
35 changes: 0 additions & 35 deletions autopush/tests/test_webpush_server.py
Expand Up @@ -29,7 +29,6 @@
DropUser,
Hello,
HelloResponse,
IncStoragePosition,
MigrateUser,
Register,
StoreMessages,
Expand Down Expand Up @@ -339,40 +338,6 @@ def test_many_messages(self):
assert len(result.messages) == 5


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

def test_inc_storage(self):
from autopush.webpush_server import CheckStorageCommand
inc_command = self._makeFUT()
check_command = CheckStorageCommand(self.conf, self.db)
check = CheckStorageFactory(message_month=self.db.current_msg_month)
uaid = check.uaid

# First store/register some messages
self._store_messages(check.uaid, num=15)

# Pull 10 out
check_result = check_command.process(check)
assert len(check_result.messages) == 10

# We should now have an updated timestamp returned, increment it
inc = IncStoragePosition(uaid=uaid.hex,
message_month=self.db.current_msg_month,
timestamp=check_result.timestamp)
inc_command.process(inc)

# Create a new check command, and verify we resume from 10 in
check = CheckStorageFactory(
uaid=uaid.hex,
message_month=self.db.current_msg_month
)
check_result = check_command.process(check)
assert len(check_result.messages) == 5


class TestDeleteMessageProcessor(BaseSetup):
def _makeFUT(self):
from autopush.webpush_server import DeleteMessageCommand
Expand Down
24 changes: 0 additions & 24 deletions autopush/webpush_server.py
Expand Up @@ -143,13 +143,6 @@ class CheckStorage(InputCommand):
timestamp = attrib(default=None) # type: Optional[int]


@attrs(slots=True)
class IncStoragePosition(InputCommand):
uaid = attrib(convert=uaid_from_str) # type: UUID
message_month = attrib() # type: str
timestamp = attrib() # type: int


@attrs(slots=True)
class DeleteMessage(InputCommand):
message_month = attrib() # type: str
Expand Down Expand Up @@ -202,11 +195,6 @@ class CheckStorageResponse(OutputCommand):
timestamp = attrib(default=None) # type: Optional[int]


@attrs(slots=True)
class IncStoragePositionResponse(OutputCommand):
success = attrib(default=True) # type: bool


@attrs(slots=True)
class DeleteMessageResponse(OutputCommand):
success = attrib(default=True) # type: bool
Expand Down Expand Up @@ -296,7 +284,6 @@ def __init__(self, conf, db):
self.db = db
self.hello_processor = HelloCommand(conf, db)
self.check_storage_processor = CheckStorageCommand(conf, db)
self.inc_storage_processor = IncrementStorageCommand(conf, db)
self.delete_message_processor = DeleteMessageCommand(conf, db)
self.drop_user_processor = DropUserCommand(conf, db)
self.migrate_user_proocessor = MigrateUserCommand(conf, db)
Expand All @@ -306,7 +293,6 @@ def __init__(self, conf, db):
self.deserialize = dict(
hello=Hello,
check_storage=CheckStorage,
inc_storage_position=IncStoragePosition,
delete_message=DeleteMessage,
drop_user=DropUser,
migrate_user=MigrateUser,
Expand All @@ -317,7 +303,6 @@ def __init__(self, conf, db):
self.command_dict = dict(
hello=self.hello_processor,
check_storage=self.check_storage_processor,
inc_storage_position=self.inc_storage_processor,
delete_message=self.delete_message_processor,
drop_user=self.drop_user_processor,
migrate_user=self.migrate_user_proocessor,
Expand Down Expand Up @@ -513,15 +498,6 @@ def _check_storage(self, command):
return timestamp, messages, False


class IncrementStorageCommand(ProcessorCommand):
def process(self, command):
# type: (IncStoragePosition) -> IncStoragePositionResponse
message = Message(command.message_month,
boto_resource=self.db.resource)
message.update_last_message_read(command.uaid, command.timestamp)
return IncStoragePositionResponse()


class DeleteMessageCommand(ProcessorCommand):
def process(self, command):
# type: (DeleteMessage) -> DeleteMessageResponse
Expand Down

0 comments on commit a481959

Please sign in to comment.