Skip to content

Commit

Permalink
Fix MockTracker track bug
Browse files Browse the repository at this point in the history
There was a bug discovered in unittest/gui/simulation/test_run_dialog.py::test_large_snapshot, where the mock tracker would yield the EndEvent, then sleep. This incorrect order caused the run_dialog to get the end event and close the dialog window while the QThread was still running time.sleep(), resulting in the "Thread: Destroyed while thread is still running" error. The test itself was also flaky, as it would assume the experiment was finished when it saw the boxes being drawn; not waiting for the done-button to show.
  • Loading branch information
Jonathan Karlsen authored and eivindjahren committed Oct 19, 2023
1 parent 72f02b0 commit 330a610
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def killJobs(self):
# Normally this slot would be invoked by the signal/slot system,
# but the worker is busy tracking the evaluation.
self._tracker.request_termination()
self._worker_thread.quit()
self._worker_thread.wait()
self._on_finished()
self.reject()
return kill_job
Expand Down
7 changes: 5 additions & 2 deletions tests/unit_tests/gui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,20 @@ def runmodel(active_realizations) -> Mock:
class MockTracker:
def __init__(self, events) -> None:
self._events = events
self._is_running = True

def track(self):
for event in self._events:
yield event
if not self._is_running:
break
time.sleep(0.1)
yield event

def reset(self):
pass

def request_termination(self):
pass
self._is_running = False


@pytest.fixture
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def test_large_snapshot(
qtbot.waitUntil(
lambda: widget._tab_widget.count() == 2, timeout=timeout_per_iter
)
qtbot.waitUntil(
lambda: widget.done_button.isVisible(), timeout=timeout_per_iter
)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 330a610

Please sign in to comment.