Skip to content
Snippets Groups Projects
test_sync.py 39.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
        def test_wait_for_invalid_future_sync_token(self) -> None:
            """Like the previous test, except we give a token that has a stream
            position ahead of what is in the DB, i.e. its invalid and we shouldn't
            wait for the stream to advance (as it may never do so).
    
            This can happen due to older versions of Synapse giving out stream
            positions without persisting them in the DB, and so on restart the
            stream would get reset back to an older position.
            """
            user = self.register_user("alice", "password")
    
            # Create a token and arbitrarily advance one of the streams.
            current_token = self.hs.get_event_sources().get_current_token()
            since_token = current_token.copy_and_advance(
                StreamKeyType.PRESENCE, current_token.presence_key + 1
            )
    
            sync_d = defer.ensureDeferred(
                self.sync_handler.wait_for_sync_for_user(
                    create_requester(user),
                    generate_sync_config(user),
                    sync_version=SyncVersion.SYNC_V2,
                    request_key=generate_request_key(),
                    since_token=since_token,
                    timeout=0,
                )
            )
    
            # We should return without waiting for the presence stream to advance.
            self.get_success(sync_d)
    
    
        user_id: str,
        device_id: Optional[str] = "device_id",
        filter_collection: Optional[FilterCollection] = None,
    
        """Generate a sync config (with a unique request key).
    
        Args:
            user_id: user who is syncing.
            device_id: device that is syncing. Defaults to "device_id".
            filter_collection: filter to apply. Defaults to the default filter (ie,
               return everything, with a default limit)
        """
        if filter_collection is None:
            filter_collection = Filtering(Mock()).DEFAULT_FILTER_COLLECTION
    
    
            filter_collection=filter_collection,