Skip to content

Commit

Permalink
Bug 1437619 [wpt PR 9484] - Correct integration with Sauce Labs servi…
Browse files Browse the repository at this point in the history
…ce, a=testonly

Automatic update from web-platform-testsCorrect integration with Sauce Labs service (#9484)

A recently merged patch centralized configuration values which defined
the domain names available during test execution [1]. That patch was
based on a mistaken assumption regarding the location of that value and
the stage of the test execution at which it would be available.
(Specifically: the value is not present in the environment configuration
object when the "environment extras" are initialized.) This interfered
with the initialization of the "environment" for the Sauce Labs service,
making it impossible to run the tests there.

Defer the retrieval of the environment configuration object to the time
that object's context manager is activated. Update the call sites to
provide the environment configuration at this moment. Also update the
signature of the context manager for the `FontInstaller` "environment
extra" to accept this second parameter.

[1] web-platform-tests/wpt#8614

wpt-commits: e56563d2b1e8bd225bf4c8b4682cbd12beeae1a7
wpt-pr: 9484
wpt-commits: e56563d2b1e8bd225bf4c8b4682cbd12beeae1a7
wpt-pr: 9484
  • Loading branch information
jugglinmike authored and jgraham committed Mar 31, 2018
1 parent f7ff2d1 commit 503f4f3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,29 @@ def get_tar(url, dest):
class SauceConnect():

def __init__(self, **kwargs):
self.config = kwargs["config"]
self.sauce_user = kwargs["sauce_user"]
self.sauce_key = kwargs["sauce_key"]
self.sauce_tunnel_id = kwargs["sauce_tunnel_id"]
self.sauce_connect_binary = kwargs.get("sauce_connect_binary")
self.sc_process = None
self.temp_dir = None
self.env_config = None

def __call__(self, env_options, env_config):
self.env_config = env_config

return self

def __enter__(self):
# Because this class implements the context manager protocol, it is
# possible for instances to be provided to the `with` statement
# directly. This class implements the callable protocol so that data
# which is not available during object initialization can be provided
# prior to this moment. Instances must be invoked in preparation for
# the context manager protocol, but this additional constraint is not
# itself part of the protocol.
assert self.env_config is not None, 'The instance has been invoked.'

def __enter__(self, options):
if not self.sauce_connect_binary:
self.temp_dir = tempfile.mkdtemp()
get_tar("https://saucelabs.com/downloads/sc-4.4.9-linux.tar.gz", self.temp_dir)
Expand All @@ -153,7 +167,7 @@ def __enter__(self, options):
"--metrics-address=0.0.0.0:9876",
"--readyfile=./sauce_is_ready",
"--tunnel-domains",
",".join(self.config['domains'].values())
",".join(self.env_config['domains'].values())
])

# Timeout config vars
Expand All @@ -180,6 +194,7 @@ def __enter__(self, options):
raise SauceException("Unable to start Sauce Connect Proxy. Process exited with code %s", self.sc_process.returncode)

def __exit__(self, exc_type, exc_val, exc_tb):
self.env_config = None
self.sc_process.terminate()
if self.temp_dir and os.path.exists(self.temp_dir):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,29 @@ def __init__(self, test_paths, ssl_env, pause_after_test, debug_info, options, e
self.cache_manager = multiprocessing.Manager()
self.stash = serve.stash.StashServer()
self.env_extras = env_extras
self.env_extras_cms = None


def __enter__(self):
self.stash.__enter__()
self.ssl_env.__enter__()
self.cache_manager.__enter__()
for cm in self.env_extras:
cm.__enter__(self.options)
self.setup_server_logging()

self.config = self.load_config()
self.setup_server_logging()
ports = serve.get_ports(self.config, self.ssl_env)
self.config = serve.normalise_config(self.config, ports)

assert self.env_extras_cms is None, (
"A TestEnvironment object cannot be nested")

self.env_extras_cms = []

for env in self.env_extras:
cm = env(self.options, self.config)
cm.__enter__()
self.env_extras_cms.append(cm)

self.servers = serve.start(self.config, self.ssl_env,
self.get_routes())
if self.options.get("supports_debugger") and self.debug_info and self.debug_info.interactive:
Expand All @@ -108,8 +119,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
for scheme, servers in self.servers.iteritems():
for port, server in servers:
server.kill()
for cm in self.env_extras:
for cm in self.env_extras_cms:
cm.__exit__(exc_type, exc_val, exc_tb)

self.env_extras_cms = None

self.cache_manager.__exit__(exc_type, exc_val, exc_tb)
self.ssl_env.__exit__(exc_type, exc_val, exc_tb)
self.stash.__exit__()
Expand Down
5 changes: 4 additions & 1 deletion testing/web-platform/tests/tools/wptrunner/wptrunner/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def __init__(self, font_dir=None, **fonts):
self.created_dir = False
self.fonts = fonts

def __enter__(self, options=None):
def __call__(self, env_options=None, env_config=None):
return self

def __enter__(self):
for _, font_path in self.fonts.items():
font_name = font_path.split('/')[-1]
install = getattr(self, 'install_%s_font' % SYSTEM, None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_sauceconnect_success():
exists.return_value = True

sauce_connect = sauce.SauceConnect(
config={
"domains": {"": "example.net"}
},
sauce_user="aaa",
sauce_key="bbb",
sauce_tunnel_id="ccc",
sauce_connect_binary="ddd")

sauce_connect.__enter__(None)
env_config = {
"domains": {"": "example.net"}
}
sauce_connect.__enter__(None, env_config)


@pytest.mark.parametrize("readyfile,returncode", [
Expand All @@ -49,16 +49,16 @@ def test_sauceconnect_failure_exit(readyfile, returncode):
exists.return_value = readyfile

sauce_connect = sauce.SauceConnect(
config={
"domains": {"": "example.net"}
},
sauce_user="aaa",
sauce_key="bbb",
sauce_tunnel_id="ccc",
sauce_connect_binary="ddd")

env_config = {
"domains": {"": "example.net"}
}
with pytest.raises(sauce.SauceException):
sauce_connect.__enter__(None)
sauce_connect.__enter__(None, env_config)

# Given we appear to exit immediately with these mocks, sleep shouldn't be called
sleep.assert_not_called()
Expand All @@ -74,16 +74,16 @@ def test_sauceconnect_failure_never_ready():
exists.return_value = False

sauce_connect = sauce.SauceConnect(
config={
"domains": {"": "example.net"}
},
sauce_user="aaa",
sauce_key="bbb",
sauce_tunnel_id="ccc",
sauce_connect_binary="ddd")

env_config = {
"domains": {"": "example.net"}
}
with pytest.raises(sauce.SauceException):
sauce_connect.__enter__(None)
sauce_connect.__enter__(None, env_config)

# We should sleep while waiting for it to create the readyfile
sleep.assert_called()
Expand All @@ -102,15 +102,15 @@ def test_sauceconnect_tunnel_domains():
exists.return_value = True

sauce_connect = sauce.SauceConnect(
config={
"domains": {"foo": "foo.bar.example.com", "": "example.net"}
},
sauce_user="aaa",
sauce_key="bbb",
sauce_tunnel_id="ccc",
sauce_connect_binary="ddd")

sauce_connect.__enter__(None)
env_config = {
"domains": {"foo": "foo.bar.example.com", "": "example.net"}
}
sauce_connect.__enter__(None, env_config)

Popen.assert_called_once()
args, kwargs = Popen.call_args
Expand Down

0 comments on commit 503f4f3

Please sign in to comment.