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

Recover from simulator already booted errors #2598

Merged
Merged
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
39 changes: 35 additions & 4 deletions apple/testing/default_runner/simulator_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,48 @@ def _boot_simulator(simulator_id: str) -> None:
output = _simctl(["bootstatus", simulator_id, "-b"])
print(output, file=sys.stderr)
except subprocess.CalledProcessError as e:
exit_code = e.returncode

# When reusing simulators we may encounter the error:
# 'Unable to boot device in current state: Booted'.
#
# This is because the simulator is already booted, and we can ignore it
# if we check and the simulator is in fact booted.
if exit_code == 149:
devices = json.loads(
_simctl(["list", "devices", "-j", simulator_id]),
brentleyjones marked this conversation as resolved.
Show resolved Hide resolved
)["devices"]
device = next(
(
blob
for devices_for_os in devices.values()
for blob in devices_for_os
if blob["udid"] == simulator_id
),
None
)
if device and device["state"].lower() == "booted":
print(
f"Simulator '{device['name']}' ({simulator_id}) is already booted",
file=sys.stderr,
)
exit_code = 0

# Both of these errors translate to strange simulator states that may
# end up causing issues, but attempting to actually use the simulator
# instead of failing at this point might still succeed
#
# 164: EBADDEVICE
# 165: EBADDEVICESTATE
if e.returncode in (164, 165):
print(f"Ignoring a failure: {e.returncode}", file=sys.stderr)
else:
print(f"Not ignoring failure: {e.returncode}", file=sys.stderr)
if exit_code in (164, 165):
print(
f"Ignoring 'simctl bootstatus' exit code {exit_code}",
file=sys.stderr,
)
elif exit_code != 0:
print(f"'simctl bootstatus' exit code {exit_code}", file=sys.stderr)
raise

# Add more arbitrary delay before tests run. Even bootstatus doesn't wait
# long enough and tests can still fail because the simulator isn't ready
time.sleep(3)
Expand Down