Exemplo n.º 1
0
class StubQApplication(QCoreApplication):
    bindEngine = pyqtSignal(int, bool)
    unbindEngine = pyqtSignal(int)

    def __init__(self, argv, test_case):
        super().__init__(argv)

        # Little trick here! See Application.__init__() for details.
        self.timer = QTimer()
        self.timer.timeout.connect(lambda: None)
        self.timer.start(100)

        self._test = test_case
        self.bindEngine.connect(self.bind_engine)
        self.unbindEngine.connect(self.unbind_engine)

        # Used by test_local_move_folders.py
        self.local_scan_count = 0

    @pyqtSlot()
    def local_scan_finished(self) -> None:
        """Count the number of local scan done."""
        self.local_scan_count += 1

    @pyqtSlot()
    def sync_completed(self):
        uid = getattr(self.sender(), "uid", None)
        log.info("Sync Completed slot for: %s", uid)
        if uid:
            self._test._wait_sync[uid] = False
        else:
            for uid in self._test._wait_sync.keys():
                self._test._wait_sync[uid] = False

    @pyqtSlot()
    def remote_scan_completed(self):
        uid = self.sender().engine.uid
        log.info("Remote scan completed for engine %s", uid)
        self._test._wait_remote_scan[uid] = False
        self._test._wait_sync[uid] = False

    @pyqtSlot(int)
    def remote_changes_found(self, change_count):
        uid = self.sender().engine.uid
        log.info("Remote changes slot for: %s", uid)
        self._test._remote_changes_count[uid] = change_count

    @pyqtSlot()
    def no_remote_changes_found(self):
        uid = self.sender().engine.uid
        log.debug("No remote changes slot for %s", uid)
        self._test._no_remote_changes[uid] = True

    @pyqtSlot(int, bool)
    def bind_engine(self, number, start_engine):
        self._test.bind_engine(number, start_engine=start_engine)

    @pyqtSlot(int)
    def unbind_engine(self, number):
        self._test.unbind_engine(number, purge=False)
Exemplo n.º 2
0
    def run(self, result=None):
        """
        I could not (yet?) migrate this method to pytest because I did not
        find a way to make tests pass.
        We need to start each test in a thread and call self.app.exec_() to
        let signals transit in the QApplication.
        """

        log.info("TEST run start")

        def launch_test():
            # Cleanup potential old report
            self._get_report_file().unlink(missing_ok=True)

            # Note: we cannot use super().run(result) here
            super(TwoUsersTest, self).run(result)

            # Generate a report if there are exceptions (failures or unexpected errors)
            if result._excinfo:
                try:
                    self.generate_report(result._excinfo)
                except Exception:
                    log.warning("Report generation failed", exc_info=True)

            with suppress(Exception):
                self.app.quit()

        # Ensure to kill the app if it is taking too long.
        # We need to do that because sometimes a thread get blocked and so the test suite.
        # Here, we set the default timeout to 2 minutes but use higher values for long-running tests.
        default_timeout = 60 * 2
        timeouts = {
            "test_nxdrive_903": 60 * 4,  # 4 minutes
            "test_nxdrive_947": 60 * 20,  # 20 minutes
            "test_nxdrive_1033": 60 * 6,  # 6 minutes
            "test_volume": 60 * 60 * 4,  # 4 hours
        }
        test_file = self.id().replace("tests.old_functional.",
                                      "").split(".")[0]
        timeout = timeouts.get(test_file, default_timeout)

        def kill_test():
            log.error(f"Killing {self.id()} after {timeout} seconds")
            self.app.exit(1)

        QTimer.singleShot(timeout * 1000, kill_test)

        # Start the app and let signals transit between threads!
        sync_thread = Thread(target=launch_test)

        with configure_scope() as scope:
            scope.set_tag("test", self._testMethodName)
            scope.set_tag("branch", os.getenv("BRANCH_NAME"))
            sync_thread.start()
            assert self.app.exec_() == 0
            sync_thread.join(30)

        log.info("TEST run end")
Exemplo n.º 3
0
    def __init__(self, argv, test_case):
        super().__init__(argv)

        # Little trick here! See Application.__init__() for details.
        self.timer = QTimer()
        self.timer.timeout.connect(lambda: None)
        self.timer.start(100)

        self._test = test_case
        self.bindEngine.connect(self.bind_engine)
        self.unbindEngine.connect(self.unbind_engine)

        # Used by test_local_move_folders.py
        self.local_scan_count = 0
Exemplo n.º 4
0
def app():
    """
    Fixture required to be able to process Qt events and quit smoothly the application.
    To use in "functional" and "unit" tests only.
    """
    from nxdrive.qt.imports import QCoreApplication, QTimer

    app = QCoreApplication([])

    # Little trick here! See Application.__init__() for details.
    timer = QTimer()
    timer.timeout.connect(lambda: None)
    timer.start(100)

    yield app