Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass server config to WebDriver via a file instead of an env variable. #28834

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions tools/serve/test_serve.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import pickle
import platform
Expand Down Expand Up @@ -78,16 +77,10 @@ def test_pickle():
pickle.dumps(c)


def test_config_json_length():
# we serialize the config as JSON for pytestrunner and put it in an env
# variable, which on Windows must have a length <= 0x7FFF (int16)
with ConfigBuilder() as c:
data = json.dumps(c.as_dict_for_wd_env_variable())
assert len(data) <= 0x7FFF

def test_alternate_host_unspecified():
ConfigBuilder(browser_host="web-platform.test")


@pytest.mark.parametrize("primary, alternate", [
("web-platform.test", "web-platform.test"),
("a.web-platform.test", "web-platform.test"),
Expand Down
23 changes: 14 additions & 9 deletions tools/wptrunner/wptrunner/executors/pytestrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ def run(path, server_config, session_config, timeout=0, environ=None):

old_environ = os.environ.copy()
try:
os.environ["WD_HOST"] = session_config["host"]
os.environ["WD_PORT"] = str(session_config["port"])
os.environ["WD_CAPABILITIES"] = json.dumps(session_config["capabilities"])
os.environ["WD_SERVER_CONFIG"] = json.dumps(server_config.as_dict_for_wd_env_variable())
if environ:
os.environ.update(environ)
with TemporaryDirectory() as cache:
os.environ["WD_HOST"] = session_config["host"]
os.environ["WD_PORT"] = str(session_config["port"])
os.environ["WD_CAPABILITIES"] = json.dumps(session_config["capabilities"])

harness = HarnessResultRecorder()
subtests = SubtestResultRecorder()
config_path = os.path.join(cache, "wd_server_config.json")
os.environ["WD_SERVER_CONFIG_FILE"] = config_path
with open(config_path, "w") as f:
json.dump(server_config.as_dict(), f)

if environ:
os.environ.update(environ)

harness = HarnessResultRecorder()
subtests = SubtestResultRecorder()

with TemporaryDirectory() as cache:
try:
pytest.main(["--strict", # turn warnings into errors
"-vv", # show each individual subtest and full failure logs
Expand Down
25 changes: 0 additions & 25 deletions tools/wptserve/wptserve/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,6 @@ def logger(self):
def as_dict(self):
return json_types(self.__dict__)

# Environment variables are limited in size so we need to prune the most egregious contributors
# to size, the origin policy subdomains.
def as_dict_for_wd_env_variable(self):
result = self.as_dict()

for key in [
("subdomains",),
("domains", "alt"),
("domains", ""),
("all_domains", "alt"),
("all_domains", ""),
("domains_set",),
("all_domains_set",)
]:
target = result
for part in key[:-1]:
target = target[part]
value = target[key[-1]]
if isinstance(value, dict):
target[key[-1]] = {k:v for (k,v) in value.items() if not k.startswith("op")}
else:
target[key[-1]] = [x for x in value if not x.startswith("op")]

return result


def json_types(obj):
if isinstance(obj, dict):
Expand Down
3 changes: 2 additions & 1 deletion webdriver/tests/support/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def http(configuration):

@pytest.fixture
def server_config():
return json.loads(os.environ.get("WD_SERVER_CONFIG"))
with open(os.environ.get("WD_SERVER_CONFIG_FILE"), "r") as f:
return json.load(f)


@pytest.fixture(scope="session")
Expand Down