Skip to content

Commit

Permalink
tests: reduce segmentation faults during testing (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed May 23, 2024
1 parent 267e82a commit f2feb58
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- enh: add logging tab in GUI
- docs: improve doc strings
- ref: improve logging
- tests: reduce segmentation faults during testing (#14)
0.14.1
- setup: fix build pipeline (remove editable install)
0.14.0
Expand Down
4 changes: 3 additions & 1 deletion dcoraid/gui/download/widget_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def download_resource(self, resource_id, condensed=False):
dl_path = self.settings.value("downloads/default path", fallback)
self.widget_jobs.jobs.new_job(resource_id, dl_path, condensed)

def stop_timers(self):
def prepare_quit(self):
"""Should be called before the application quits"""
self.init_timer.stop()
if self.widget_jobs.timer is not None:
self.widget_jobs.timer.stop()
if self.jobs is not None:
self.jobs.__del__()


class DownloadTableWidget(QtWidgets.QTableWidget):
Expand Down
2 changes: 2 additions & 0 deletions dcoraid/gui/logs/widget_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


class StringSignalLogHandler(logging.Handler):
new_message = QtCore.pyqtSignal(str)

def __init__(self, signal, *args, **kwargs):
super(StringSignalLogHandler, self).__init__(*args, **kwargs)
self.signal = signal
Expand Down
10 changes: 7 additions & 3 deletions dcoraid/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ def __init__(self, *args, **kwargs):
self.status_widget.request_status_update()

def closeEvent(self, event):
self.panel_upload.stop_timers()
self.panel_download.stop_timers()
self.status_widget.stop_timers()
root_logger = logging.getLogger()
while len(root_logger.handlers) > 0:
h = root_logger.handlers[0]
root_logger.removeHandler(h)
self.panel_upload.prepare_quit()
self.panel_download.prepare_quit()
self.status_widget.prepare_quit()
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents,
300)
event.accept()
Expand Down
2 changes: 1 addition & 1 deletion dcoraid/gui/status_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def set_status(self, text, tooltip, icon, server):
self.toolButton_user.setToolTip(tooltip)
self.toolButton_user.setIcon(QtGui.QIcon.fromTheme(icon))

def stop_timers(self):
def prepare_quit(self):
if self.timer is not None:
self.timer.stop()

Expand Down
4 changes: 3 additions & 1 deletion dcoraid/gui/upload/widget_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,13 @@ def on_upload_task(
"\n\n".join(messages),
)

def stop_timers(self):
def prepare_quit(self):
"""Should be called before the application quits"""
self.init_timer.stop()
if self.widget_jobs.timer is not None:
self.widget_jobs.timer.stop()
if self._jobs is not None:
self._jobs.__del__()


class UploadTableWidget(QtWidgets.QTableWidget):
Expand Down
3 changes: 0 additions & 3 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pathlib
import shutil
import tempfile
import time
from unittest import mock

import uuid
Expand Down Expand Up @@ -42,7 +41,6 @@ def mw(qtbot):
# Make sure that all daemons are gone
mw.close()
# It is extremely weird, but this seems to be important to avoid segfaults!
time.sleep(1)
QtTest.QTest.qWait(100)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 5000)

Expand Down Expand Up @@ -86,7 +84,6 @@ def test_gui_anonymous(qtbot):
spath.unlink()
shutil.copy2(stmp, spath)
mw.close()
time.sleep(1)
QtTest.QTest.qWait(500)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 500)

Expand Down

0 comments on commit f2feb58

Please sign in to comment.