async def _reset_backend_state_manager(self):
        """Reset the StateManagerRedis event loop affinity.

        This is necessary when the backend is restarted and the state manager is a
        StateManagerRedis instance.

        Raises:
            RuntimeError: when the state manager cannot be reset
        """
        if (
            self.app_instance is not None
            and isinstance(
                self.app_instance._state_manager,
                StateManagerRedis,
            )
            and self.app_instance._state is not None
        ):
            with contextlib.suppress(RuntimeError):
                await self.app_instance._state_manager.close()
            self.app_instance._state_manager = StateManagerRedis.create(
                state=self.app_instance._state,
            )
            if not isinstance(self.app_instance.state_manager, StateManagerRedis):
                msg = "Failed to reset state manager."
                raise RuntimeError(msg)
Reset the StateManagerRedis event loop affinity.

        This is necessary when the backend is restarted and the state manager is a
        StateManagerRedis instance.

        Raises:
            RuntimeError: when the state manager cannot be reset
        
reflex/testing.py