Skip to content

Commit

Permalink
Merge pull request googleapis#2533 from tseaver/2529-pubsub-fix-serve…
Browse files Browse the repository at this point in the history
…r-side-timestamp

Use correct 'publishTime' field name for server-set message timestamp.
  • Loading branch information
tseaver authored Oct 12, 2016
2 parents afcafd8 + f5480fe commit bc4a021
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pubsub/google/cloud/pubsub/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ def from_api_repr(cls, api_repr):
instance = cls(
data=data, message_id=api_repr['messageId'],
attributes=api_repr.get('attributes'))
instance._service_timestamp = api_repr.get('publishTimestamp')
instance._service_timestamp = api_repr.get('publishTime')
return instance
4 changes: 2 additions & 2 deletions pubsub/unit_tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_from_api_repr_no_attributes(self):
api_repr = {
'data': B64_DATA,
'messageId': MESSAGE_ID,
'publishTimestamp': TIMESTAMP,
'publishTime': TIMESTAMP,
}
message = self._getTargetClass().from_api_repr(api_repr)
self.assertEqual(message.data, DATA)
Expand All @@ -116,7 +116,7 @@ def test_from_api_repr_w_attributes(self):
api_repr = {
'data': B64_DATA,
'messageId': MESSAGE_ID,
'publishTimestamp': TIMESTAMP,
'publishTime': TIMESTAMP,
'attributes': ATTRS,
}
message = self._getTargetClass().from_api_repr(api_repr)
Expand Down
4 changes: 4 additions & 0 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ def suction(self):

message1, message2 = sorted(hoover.received,
key=operator.attrgetter('timestamp'))

self.assertEqual(message1.data, MESSAGE_1)
self.assertEqual(message1.attributes['extra'], EXTRA_1)
self.assertIsNotNone(message1.service_timestamp)

self.assertEqual(message2.data, MESSAGE_2)
self.assertEqual(message2.attributes['extra'], EXTRA_2)
self.assertIsNotNone(message2.service_timestamp)

def _maybe_emulator_skip(self):
# NOTE: This method is necessary because ``Config.IN_EMULATOR``
Expand Down

0 comments on commit bc4a021

Please sign in to comment.