Skip to content

Commit

Permalink
Pass server config to WebDriver via a file instead of an env variable. (
Browse files Browse the repository at this point in the history
  • Loading branch information
letitz authored May 10, 2021
1 parent 03a6564 commit cd82725
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 43 deletions.
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 @@ -105,7 +105,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

0 comments on commit cd82725

Please sign in to comment.