Add test for two messages with the same key. Fixes to clean shutdown and server-side message duplication.

This commit is contained in:
Ian Gulliver
2014-05-15 16:30:08 +03:00
parent 1e755c9693
commit 3f0b7db9dd
3 changed files with 69 additions and 5 deletions

View File

@@ -135,14 +135,26 @@ class Subject(db.Model):
return None
@db.transactional()
def SendMessage(self, message, sender, key=None):
def PutMessage(self, message, sender, key=None):
"""Internal helper for SendMessage().
Unless/until channel.send_message becomes transactional, we have to finish
the datastore work (and any retries) before we start transmitting to
channels.
"""
obj = Message(parent=self, message=message, sender=sender, key_=key)
obj.put()
event = obj.ToEvent()
return (
obj,
[Subscription.client.get_value_for_datastore(subscription)
for subscription in Subscription.all().ancestor(self)])
for subscription in Subscription.all().ancestor(self):
Client.SendByKey(Subscription.client.get_value_for_datastore(subscription), event)
def SendMessage(self, message, sender, key=None):
obj, subscriptions = self.PutMessage(message, sender, key)
event = obj.ToEvent()
for subscription in subscriptions:
Client.SendByKey(subscription, event)
class Subscription(db.Model):