Skip to content

Commit

Permalink
Fixes Python SDK tests when external package loading is enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Jan 16, 2025
1 parent 5377f9f commit 38bfd4d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/workerd/server/tests/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ py_wd_test("subdirectory")

py_wd_test(
"sdk",
# TODO(EW-8976): Disabled in dev due to test getting stuck
python_flags = ["0.26.0a2"],
tags = [
# TODO(someday): Fix asan failure for this, see https://github.com/cloudflare/workerd/pull/3140#discussion_r1858273318
"no-asan",
Expand Down
12 changes: 12 additions & 0 deletions src/workerd/server/tests/python/sdk/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
async fetch(req, env) {
const url = new URL(req.url);
if (url.hostname == 'pyodide-packages.runtime-playground.workers.dev') {
return env.INTERNET.fetch(req);
} else if (url.hostname == 'example.com') {
return env.PYTHON.fetch(req);
}

throw new Error('Invalid url: ' + req.url);
},
};
27 changes: 24 additions & 3 deletions src/workerd/server/tests/python/sdk/sdk.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,34 @@ const server :Workerd.Worker = (
compatibilityFlags = [%PYTHON_FEATURE_FLAGS],
);

# We need this proxy so that internal requests made to fetch packages for Python Workers are sent
# out to the open internet and not
const jsChooserProxy :Workerd.Worker = (
modules = [
(name = "proxy.js", esModule = embed "proxy.js")
],
bindings = [
( name = "PYTHON", service = "python-server" ),
( name = "INTERNET", service = "external" ),
],
compatibilityDate = "2024-10-01",
);

const unitTests :Workerd.Config = (
services = [
( name = "python-sdk",
worker = .python
( name = "external",
network = (
tlsOptions = (trustBrowserCas = true)
)
),
( name = "internet",
worker = .jsChooserProxy
),
( name = "python-server",
worker = .server
)
),
( name = "python-sdk",
worker = .python
),
],
);

0 comments on commit 38bfd4d

Please sign in to comment.