Skip to content

Commit 9996e0f

Browse files
joemarshallpquentinillia-v
authored
Fix emscripten CI for Chrome 137+ (#3599)
Co-authored-by: Quentin Pradet <[email protected]> Co-authored-by: Illia Volochii <[email protected]>
1 parent 4fd1a99 commit 9996e0f

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ jobs:
116116
if: ${{ matrix.nox-session == 'emscripten(chrome)' }}
117117
with:
118118
install-chromedriver: true
119-
# Use stable until https://github.com/urllib3/urllib3/issues/3598 is fixed.
120-
chrome-version: stable
121119
- name: Force override system chrome
122120
run: |
123121
sudo rm -f /usr/bin/google-chrome

test/contrib/emscripten/conftest.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ def _install_packages(self: Any) -> None:
8484
result = self.run_js(
8585
f'await pyodide.loadPackage("http://{testserver_http.http_host}:{testserver_http.http_port}/dist/urllib3.whl")'
8686
)
87+
if not self.with_jspi:
88+
# force Chrome to execute the current test without JSPI
89+
# even though it is always enabled in
90+
# chrome >= 137. We do this by monkeypatching
91+
# pyodide.ffi.can_run_sync
92+
self.run_async(
93+
"""
94+
import pyodide.ffi
95+
if pyodide.ffi.can_run_sync():
96+
pyodide.ffi.can_run_sync = lambda: False
97+
"""
98+
)
99+
87100
print("Installed package:", result)
88101
self.run_js(
89102
"""
@@ -128,11 +141,14 @@ def _install_packages(self: Any) -> None:
128141

129142

130143
class ServerRunnerInfo:
131-
def __init__(self, host: str, port: int, selenium: Any, dist_dir: Path) -> None:
144+
def __init__(
145+
self, host: str, port: int, selenium: Any, dist_dir: Path, has_jspi: bool
146+
) -> None:
132147
self.host = host
133148
self.port = port
134149
self.selenium = selenium
135150
self.dist_dir = dist_dir
151+
self.has_jspi = has_jspi
136152

137153
def run_webworker(self, code: str) -> Any:
138154
if isinstance(code, str) and code.startswith("\n"):
@@ -148,6 +164,19 @@ def run_webworker(self, code: str) -> Any:
148164
"""
149165
)
150166

167+
# Monkeypatch pyodide to force disable JSPI in newer chrome
168+
# so those code paths get tested
169+
if self.has_jspi is False:
170+
jspi_fix_code = textwrap.dedent(
171+
"""
172+
import pyodide.ffi
173+
if pyodide.ffi.can_run_sync():
174+
pyodide.ffi.can_run_sync = lambda: False
175+
"""
176+
)
177+
else:
178+
jspi_fix_code = ""
179+
151180
coverage_end_code = textwrap.dedent(
152181
"""
153182
_coverage.stop()
@@ -164,7 +193,15 @@ def run_webworker(self, code: str) -> Any:
164193

165194
# the ordering of these code blocks is important - makes sure
166195
# that the first thing that happens is our wheel is loaded
167-
code = coverage_init_code + "\n" + code + "\n" + coverage_end_code
196+
code = (
197+
coverage_init_code
198+
+ "\n"
199+
+ jspi_fix_code
200+
+ "\n"
201+
+ code
202+
+ "\n"
203+
+ coverage_end_code
204+
)
168205

169206
if self.selenium.browser == "firefox":
170207
# running in worker is SLOW on firefox
@@ -232,6 +269,7 @@ def run_from_server(
232269
testserver_http.https_port,
233270
selenium_coverage,
234271
dist_dir,
272+
selenium_coverage.with_jspi,
235273
)
236274

237275

0 commit comments

Comments
 (0)