Skip to content

Commit

Permalink
Remove console callback before closing browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Jul 26, 2023
1 parent 9060a94 commit 21b55b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ conda install -c conda-forge asv virtualenv "nodejs>=18"
To run all benchmarks:
```
cd benchmarks
asv run
asv run -e
```

The first time this is run it creates a machine file to store information about your machine. Then a virtual environment is created and each benchmark is run multiple times to obtain a statistically valid benchmark time.

The virtual environment contains `hvneuro` and its dependencies as defined in the top-level `pyproject.toml` file. It also contains `playwright`, the latest version of `chromium` as installed by `playwright`, and a particular branch of `bokeh` that contains extra code to record when the canvas is rendered. The latter is compiled by source and extra dependencies may be required for this to work on all test machines (to be determined).

The `-e` flag catches and displays stderr after the benchmark results. This should be free of errors but may contain some warnings.

# Viewing benchmark results

To list benchmark runs use
Expand Down
16 changes: 12 additions & 4 deletions benchmarks/benchmarks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@


class Base:
def __init__(self):
def __init__(self, catch_console: bool = True):
self._catch_console = catch_console
self._port = 5006
self.render_count = -1
self._figure_id = None # Unique ID of the figure to grab the console messages of.
Expand All @@ -35,7 +36,7 @@ def _console_callback(self, msg: ConsoleMessage) -> None:
if count != self.render_count:
raise RuntimeError(f"Mismatch in render count: {count} != {self.render_count}")

def _playwright_setup(self, bokeh_doc: Callable[[Document], None], catch_console: bool) -> None:
def playwright_setup(self, bokeh_doc: Callable[[Document], None]) -> None:
# Playwright context manager needs to span multiple functions,
# so manually call __enter__ and __exit__ methods.
self._playwright_context_manager = sync_playwright()
Expand All @@ -57,11 +58,18 @@ def _playwright_setup(self, bokeh_doc: Callable[[Document], None], catch_console
# This raises an error if there is more than one figure in the Bokeh document.
self._figure_id = doc.select_one(dict(type=Plot)).id

if catch_console:
if self._catch_console:
self.page.on("console", self._console_callback)

def _playwright_teardown(self):
def playwright_teardown(self):
self._figure_id = None
if self._catch_console:
self.page.remove_listener("console", self._console_callback)
self.render_count = -1
# Wait a few milliseconds for emitted console messages to be handled before closing
# browser. May need to increase this if Playwright complains that browser is closed.
self.page.wait_for_timeout(10)

self._browser.close()
self._server.stop()
self._playwright_context_manager.__exit__(None, None, None)
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class Timeseries(Base):

def setup(self, n: int, output_backend: str) -> None:
bkapp_n = partial(bkapp, n=n, output_backend=output_backend)
self._playwright_setup(bkapp_n, catch_console=True)
self.playwright_setup(bkapp_n)

def teardown(self, n: int, output_backend: str) -> None:
self._playwright_teardown()
self.playwright_teardown()

def time_values(self, n: int, output_backend: str) -> None:
button = self.page.get_by_role("button", name="run")
Expand Down

0 comments on commit 21b55b9

Please sign in to comment.