diff --git a/tests/playwright/shiny/session/flush/app.py b/tests/playwright/shiny/session/flush/app.py index a6591e31d..39c046887 100644 --- a/tests/playwright/shiny/session/flush/app.py +++ b/tests/playwright/shiny/session/flush/app.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +from typing import List from shiny import App, Inputs, Outputs, Session, reactive, render, ui @@ -37,8 +38,10 @@ ui.output_text_verbatim("all_txt", placeholder=True), ui.tags.span("Flush events: "), ui.output_text_verbatim("flush_txt", placeholder=True), - ui.tags.span("Flushed: "), + ui.tags.span("Flushed events: "), ui.output_text_verbatim("flushed_txt", placeholder=True), + ui.tags.span("Session end events (refresh App to add events): "), + ui.output_text_verbatim("session_end_txt", placeholder=True), ui.tags.script( """ $(document).on('shiny:connected', function(event) { @@ -55,18 +58,20 @@ ), ) +session_ended_messages: List[str] = [] + def server(input: Inputs, output: Outputs, session: Session): def on_ended_sync(txt: str): def _(): - print(txt) + session_ended_messages.append(txt) return _ def on_ended_async(txt: str): async def _(): await asyncio.sleep(0) - print(txt) + session_ended_messages.append(txt) return _ @@ -181,5 +186,9 @@ def flush_txt(): def flushed_txt(): return str(flushed_vals.get()) + @render.text + def session_end_txt(): + return str(session_ended_messages) + app = App(app_ui, server) diff --git a/tests/playwright/shiny/session/flush/test_on_flush.py b/tests/playwright/shiny/session/flush/test_on_flush.py index 4e782a814..4d14a3321 100644 --- a/tests/playwright/shiny/session/flush/test_on_flush.py +++ b/tests/playwright/shiny/session/flush/test_on_flush.py @@ -1,26 +1,10 @@ -import os - -import pytest from conftest import ShinyAppProc from controls import OutputTextVerbatim from playwright.sync_api import Page -on_ci = os.environ.get("CI", "False") == "true" - def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None: - if on_ci: - # 2024-03-22: The tests pass locally, but do not pass on CI. It started with - # https://github.com/posit-dev/py-shiny/commit/2f75a9076c567690f2a6a647ec07cfa9e558ff9c - # , but the changes in that commit were unrelated. We had believe it was an - # update in uvicorn, but removing all other debug statements did not fix the - # issue. - # 2024-03-22 Barret: When inspecting the issue, we found that many log - # INFO entries have different port values. This is concerning. - # https://github.com/posit-dev/py-shiny/pull/1236 - pytest.skip("Error with stdout / stderr on CI. Related #1236") - page.goto(local_app.url) OutputTextVerbatim(page, "all_txt").expect_value( @@ -37,23 +21,10 @@ def test_output_image_kitchen(page: Page, local_app: ShinyAppProc) -> None: "('a-3-flushed', 'bx-3-first-flushed', 'by-3-first-flushed', " "'bx-3-second-flushed', 'by-3-second-flushed', 'c-3-flushed')" ) - - # Verify `on_ended` callbacks are called in the correct order (and cancelled) - local_app.close() - - # Wait up to 3 seconds for the app to close and print the logs. (Should be ~ instant) - local_app.stdout.wait_for(lambda x: "test4" in x, 3) - stdout = str(local_app.stdout) - out_indexes = [ - stdout.index("session ended - sync - test1"), - stdout.index("session ended - async - test2"), - stdout.index("session ended - async - test3"), - stdout.index("session ended - sync - test4"), - ] - for i in range(len(out_indexes)): - index = out_indexes[i] - assert index >= 0 - # Make sure they are ordered correctly - if i > 0: - prev_index = out_indexes[i - 1] - assert index > prev_index + # Session end messages have not flushed yet + OutputTextVerbatim(page, "session_end_txt").expect_value("[]") + page.reload() + # Session end messages have flushed + OutputTextVerbatim(page, "session_end_txt").expect_value( + "['session ended - sync - test1', 'session ended - async - test2', 'session ended - async - test3', 'session ended - sync - test4']" + )