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

Commit

Permalink
fix: clear only the node_id in the router record
Browse files Browse the repository at this point in the history
Closes #401
  • Loading branch information
bbangert authored and jrconlin committed Mar 12, 2016
1 parent 6b1b760 commit c206a29
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def clear_node(self, item):
cond = "(node_id = :node) and (connected_at = :conn)"
conn.put_item(
self.table.table_name,
item=item.get_raw_keys(),
item=self.encode(item),
condition_expression=cond,
expression_attribute_values=self.encode({
":node": node_id,
Expand Down
7 changes: 6 additions & 1 deletion autopush/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,23 @@ def test_node_clear(self):

# Register a node user
router.register_user(dict(uaid=dummy_uaid, node_id="asdf",
connected_at=1234))
connected_at=1234,
router_key="webpush"))

# Verify
user = router.get_uaid(dummy_uaid)
eq_(user["node_id"], "asdf")
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")

# Clear
router.clear_node(user)

# Verify
user = router.get_uaid(dummy_uaid)
eq_(user.get("node_id"), None)
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")

def test_node_clear_fail(self):
r = get_router_table()
Expand Down
10 changes: 10 additions & 0 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ def disconnect(self):
def sleep(self, duration):
time.sleep(duration)

def wait_for(self, func):
"""Waits several seconds for a function to return True"""
times = 0
while not func(): # pragma: nocover
time.sleep(1)
times += 1
if times > 9: # pragma: nocover
break


class IntegrationBase(unittest.TestCase):
track_objects = True
Expand Down Expand Up @@ -669,6 +678,7 @@ def test_hello_only_has_two_calls(self):
result = yield client.hello()
ok_(result != {})
eq_(result["use_webpush"], True)
yield client.wait_for(lambda: len(db.DB_CALLS) == 2)
eq_(db.DB_CALLS, ['register_user', 'fetch_messages'])
db.DB_CALLS = []
db.TRACK_DB_CALLS = False
Expand Down
1 change: 1 addition & 0 deletions autopush/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def check_result(msg):

def test_hello_webpush_uses_one_db_call(self):
db.TRACK_DB_CALLS = True
db.DB_CALLS = []
self._connect()
self._send_message(dict(messageType="hello", use_webpush=True,
channelIDs=[]))
Expand Down

0 comments on commit c206a29

Please sign in to comment.