From 59c767fd46ad985f45e905c467e61f4128f449ba Mon Sep 17 00:00:00 2001 From: Florian Scherf Date: Fri, 10 Feb 2023 14:58:56 +0100 Subject: [PATCH] views: fix handling of `View.is_daemon` This patch is a fixup for 94587cc8627e ("views: fix handling of `View.is_daemon`") The original patch did not fix the bug entirely. This patch adds a test to reproduce the original problem, and fixes it by adding a check for the feature flag. Signed-off-by: Florian Scherf --- lona/view_runtime.py | 10 +++++++--- tests/test_daemon_views.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lona/view_runtime.py b/lona/view_runtime.py index 231fd46c..2a5f6acb 100644 --- a/lona/view_runtime.py +++ b/lona/view_runtime.py @@ -482,9 +482,13 @@ def remove_connection(self, connection, window_id=None): # if the last connection gets closed and the view should # not continue running in background, it gets stopped - if (not self.connections and - self.stop_daemon_when_view_finishes and - not self.is_daemon): + if not self.connections and not self.is_daemon: + self.stop() + + # TODO: remove in 2.0 + elif (self.stop_daemon_when_view_finishes and + self.is_stopped and + not self.connections): self.stop() diff --git a/tests/test_daemon_views.py b/tests/test_daemon_views.py index aa039fa2..41d75029 100644 --- a/tests/test_daemon_views.py +++ b/tests/test_daemon_views.py @@ -86,6 +86,16 @@ def handle_request(self, request): assert message3 == 'view stopped' + # check if views got removed from the server + await page.goto('about:blank') + + for attempt in eventually(): + async with attempt: + view_runtime_count = len( + context.server._view_runtime_controller._view_runtimes) + + assert view_runtime_count == 0 + async def test_multi_tab_daemon_view(lona_app_context): """