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

Commit

Permalink
feat: retain date when checking message tables
Browse files Browse the repository at this point in the history
Ensures the date argument is passed along with the table name
when creating the rotating message table during the
get_rotating_message_table call.

Closes #722
  • Loading branch information
bbangert committed Nov 8, 2016
1 parent 94ad8cf commit 4c1a377
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def make_rotating_tablename(prefix, delta=0, date=None):


def create_rotating_message_table(prefix="message", read_throughput=5,
write_throughput=5, delta=0):
write_throughput=5, delta=0, date=None):
# type: (str, int, int, int) -> Table
"""Create a new message table for webpush style message storage"""
tablename = make_rotating_tablename(prefix, delta)
tablename = make_rotating_tablename(prefix, delta, date)
return Table.create(tablename,
schema=[HashKey("uaid"),
RangeKey("chidmessageid")],
Expand All @@ -153,7 +153,9 @@ def get_rotating_message_table(prefix="message", delta=0, date=None,
return create_rotating_message_table(
prefix=prefix, delta=delta,
read_throughput=message_read_throughput,
write_throughput=message_write_throughput)
write_throughput=message_write_throughput,
date=date,
)
else:
return Table(tablename)

Expand Down
12 changes: 10 additions & 2 deletions autopush/tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import uuid
from datetime import datetime
from datetime import datetime, timedelta

from autopush.websocket import ms_time
from boto.dynamodb2.exceptions import (
Expand All @@ -25,7 +25,7 @@
Message,
Router,
generate_last_connect,
)
make_rotating_tablename)
from autopush.exceptions import AutopushException
from autopush.metrics import SinkMetrics
from autopush.utils import WebPushNotification
Expand Down Expand Up @@ -360,6 +360,14 @@ def raise_condition(*args, **kwargs):
result = message.delete_message(notif)
eq_(result, False)

def test_message_rotate_table_with_date(self):
prefix = "message" + uuid.uuid4().hex
future = datetime.today() + timedelta(days=32)
tbl_name = make_rotating_tablename(prefix, date=future)

m = get_rotating_message_table(prefix=prefix, date=future)
eq_(m.table_name, tbl_name)


class RouterTestCase(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 4c1a377

Please sign in to comment.