Skip to content

Commit 66f50b4

Browse files
fix(mac): reduce AltTester connection flakiness in CI
- Prefer UNITY_APP_PATH when launching the sample app on macOS. - Retry AltDriver connection with a longer timeout to handle slow startup.
1 parent 3b38482 commit 66f50b4

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

sample/Tests/test/test_mac.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ class MacTest(UnityTest):
2727
@classmethod
2828
def setUpClass(cls):
2929
open_sample_app()
30-
cls.altdriver = AltDriver()
30+
# macOS runners can take a while to start the AltTester server inside Unity.
31+
# Retry connection instead of failing immediately with "Connection refused".
32+
last_err = None
33+
for attempt in range(12): # ~60s total
34+
try:
35+
cls.altdriver = AltDriver(timeout=120)
36+
last_err = None
37+
break
38+
except Exception as e:
39+
last_err = e
40+
print(f"AltDriver connect attempt {attempt + 1}/12 failed: {e}")
41+
time.sleep(5)
42+
if last_err is not None:
43+
raise SystemExit(f"Failed to connect AltDriver on macOS: {last_err}")
3144
cls.stop_browser()
3245

3346
@classmethod
@@ -242,7 +255,18 @@ def test_6_relogin(self):
242255

243256
# Restart AltTester
244257
self.altdriver.stop()
245-
self.__class__.altdriver = AltDriver()
258+
last_err = None
259+
for attempt in range(12):
260+
try:
261+
self.__class__.altdriver = AltDriver(timeout=120)
262+
last_err = None
263+
break
264+
except Exception as e:
265+
last_err = e
266+
print(f"AltDriver reconnect attempt {attempt + 1}/12 failed: {e}")
267+
time.sleep(5)
268+
if last_err is not None:
269+
raise SystemExit(f"Failed to reconnect AltDriver on macOS: {last_err}")
246270
time.sleep(5)
247271

248272
# Wait for unauthenticated screen
@@ -275,7 +299,18 @@ def test_7_reconnect_connect_imx(self):
275299

276300
# Restart AltTester
277301
self.altdriver.stop()
278-
self.__class__.altdriver = AltDriver()
302+
last_err = None
303+
for attempt in range(12):
304+
try:
305+
self.__class__.altdriver = AltDriver(timeout=120)
306+
last_err = None
307+
break
308+
except Exception as e:
309+
last_err = e
310+
print(f"AltDriver reconnect attempt {attempt + 1}/12 failed: {e}")
311+
time.sleep(5)
312+
if last_err is not None:
313+
raise SystemExit(f"Failed to reconnect AltDriver on macOS: {last_err}")
279314
time.sleep(5)
280315

281316
# Wait for unauthenticated screen

sample/Tests/test/test_mac_helpers.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,34 @@ def get_app_name():
66
"""Get the app name from environment variable, falling back to default"""
77
return os.getenv("UNITY_APP_NAME", "SampleApp")
88

9+
def get_app_path():
10+
"""
11+
Prefer the explicit app bundle path from CI (UNITY_APP_PATH).
12+
Fallback to "<UNITY_APP_NAME>.app".
13+
"""
14+
app_path = os.getenv("UNITY_APP_PATH")
15+
if app_path:
16+
return app_path
17+
return f"{get_app_name()}.app"
18+
919
def open_sample_app():
1020
app_name = get_app_name()
1121
print(f"Opening Unity sample app ({app_name})...")
12-
subprocess.Popen(["open", f"{app_name}.app"], shell=False)
13-
time.sleep(5)
22+
app_path = get_app_path()
23+
print(f"Using app path: {app_path}")
24+
if not os.path.exists(app_path):
25+
raise SystemExit(f"Unity app bundle not found at path: {app_path}")
26+
subprocess.Popen(["open", app_path], shell=False)
27+
# macOS runners are slow to launch + start AltTester server
28+
time.sleep(10)
1429
print(f"Unity sample app ({app_name}) opened successfully.")
1530

1631
def stop_sample_app():
1732
app_name = get_app_name()
1833
print(f"Stopping sample app ({app_name})...")
1934

2035
bash_script = f"""
21-
app_path="{app_name}.app"
36+
app_path="{get_app_path()}"
2237
echo "Closing sample app..."
2338
PID=$(ps aux | grep "$app_path" | grep -v grep | awk '{{print $2}}')
2439
if [ -n "$PID" ]; then

0 commit comments

Comments
 (0)