diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-08-28 16:43:55 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-08-28 16:43:55 +0100 |
commit | efc5f3440dc033d9d1713eaa7159b75689704d6c (patch) | |
tree | a9724d7c7191bc8ec6e6acfd5268540c66016c96 /tests | |
parent | Ability to assert a DeferredMockCallable has received no calls (diff) | |
download | synapse-efc5f3440dc033d9d1713eaa7159b75689704d6c.tar.xz |
Only send presence "poll"/"unpoll" EDUs when changing from/to zero remotes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/handlers/test_presence.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index 13217d456b..8d094fd1f9 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -15,7 +15,7 @@ from twisted.trial import unittest -from twisted.internet import defer +from twisted.internet import defer, reactor from mock import Mock, call, ANY import logging @@ -853,6 +853,7 @@ class PresencePollingTestCase(unittest.TestCase): 'apple': [ "@banana:test", "@clementine:test" ], 'banana': [ "@apple:test" ], 'clementine': [ "@apple:test", "@potato:remote" ], + 'fig': [ "@potato:remote" ], } @@ -902,9 +903,10 @@ class PresencePollingTestCase(unittest.TestCase): # Mocked database state # Local users always start offline self.current_user_state = { - "apple": OFFLINE, - "banana": OFFLINE, - "clementine": OFFLINE, + "apple": OFFLINE, + "banana": OFFLINE, + "clementine": OFFLINE, + "fig": OFFLINE, } def get_presence_state(user_localpart): @@ -934,6 +936,7 @@ class PresencePollingTestCase(unittest.TestCase): self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test") self.u_clementine = hs.parse_userid("@clementine:test") + self.u_fig = hs.parse_userid("@fig:test") # Remote users self.u_potato = hs.parse_userid("@potato:remote") @@ -1023,10 +1026,32 @@ class PresencePollingTestCase(unittest.TestCase): yield put_json.await_calls() # Gut-wrenching tests - self.assertTrue(self.u_potato in self.handler._remote_recvmap) + self.assertTrue(self.u_potato in self.handler._remote_recvmap, + msg="expected potato to be in _remote_recvmap" + ) self.assertTrue(self.u_clementine in self.handler._remote_recvmap[self.u_potato]) + # fig goes online; shouldn't send a second poll + yield self.handler.set_state( + target_user=self.u_fig, auth_user=self.u_fig, + state={"state": ONLINE} + ) + + reactor.iterate(delay=0) + + put_json.assert_had_no_calls() + + # fig goes offline + yield self.handler.set_state( + target_user=self.u_fig, auth_user=self.u_fig, + state={"state": OFFLINE} + ) + + reactor.iterate(delay=0) + + put_json.assert_had_no_calls() + put_json.expect_call_and_return( call("remote", path="/matrix/federation/v1/send/1000001/", @@ -1046,7 +1071,9 @@ class PresencePollingTestCase(unittest.TestCase): put_json.await_calls() - self.assertFalse(self.u_potato in self.handler._remote_recvmap) + self.assertFalse(self.u_potato in self.handler._remote_recvmap, + msg="expected potato not to be in _remote_recvmap" + ) @defer.inlineCallbacks def test_remote_poll_receive(self): |