Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Tweak test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Apr 14, 2023
1 parent 9445960 commit 67e864c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def test_create_room(self) -> None:
self.assertIsNone(room_alias)

def test_on_logged_out(self) -> None:
"""Test that on_logged_out module hook is properly call when logging out
"""Test that on_logged_out module hook is properly called when logging out
a device, and that related pushers are still available at this time.
"""
device_id = "AAAAAAA"
Expand All @@ -796,27 +796,32 @@ def test_on_logged_out(self) -> None:
)
)

self.nb_of_pushers_in_callback: Optional[int] = None
# Setup a callback counting the number of pushers.
number_of_pushers_in_callback: Optional[int] = None

async def _on_logged_out_mock(
user_id: str, device_id: Optional[str], access_token: str
) -> None:
nonlocal number_of_pushers_in_callback
number_of_pushers_in_callback = len(
self.hs.get_pusherpool().pushers[user_id].values()
)

self.module_api.register_password_auth_provider_callbacks(
on_logged_out=self._on_logged_out_mock
on_logged_out=_on_logged_out_mock
)

# Delete the device.
device_handler = self.hs.get_device_handler()
assert isinstance(device_handler, DeviceHandler)
self.get_success(device_handler.delete_devices(user_id, [device_id]))

self.assertEqual(self.nb_of_pushers_in_callback, 1)
# Check that the callback was called and the pushers still existed.
self.assertEqual(number_of_pushers_in_callback, 1)

# Ensure the pushers were deleted after the callback.
self.assertEqual(len(self.hs.get_pusherpool().pushers[user_id].values()), 0)

async def _on_logged_out_mock(
self, user_id: str, device_id: Optional[str], access_token: str
) -> None:
self.nb_of_pushers_in_callback = len(
self.hs.get_pusherpool().pushers[user_id].values()
)


class ModuleApiWorkerTestCase(BaseModuleApiTestCase, BaseMultiWorkerStreamTestCase):
"""For testing ModuleApi functionality in a multi-worker setup"""
Expand Down

0 comments on commit 67e864c

Please sign in to comment.