mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
fix(agent): start sessions from their own task so repeat starts aren't swallowed (#2468)
* fix(agent): start sessions from their own task so repeat starts aren't swallowed * fix(ci): fall back to the kernel.org Ubuntu mirror when Canonical's are unreachable * fix(ci): fall back to the Berkeley ports mirror on arm64 runners
This commit is contained in:
1 parent
f16b023f0d
commit
c265b66e80
5 files changed
+53
-9
No files matched your search
@@ -31,15 +31,22 @@ install_packages() {
|
||||
if install_packages; then
|
||||
exit 0
|
||||
fi
|
||||
echo "::warning::Runner mirror failed or timed out; retrying with the official Ubuntu mirror."
|
||||
[ -f "$ubuntu_sources" ] || exit 1
|
||||
sources=$(mktemp --suffix=.sources)
|
||||
trap 'rm -f "$sources"' EXIT
|
||||
mirror=https://archive.ubuntu.com/ubuntu
|
||||
# The last mirror of each list is outside Canonical's network, so it still answers when runners cannot reach Canonical.
|
||||
mirrors=(https://archive.ubuntu.com/ubuntu https://mirrors.edge.kernel.org/ubuntu)
|
||||
case "$(dpkg --print-architecture)" in
|
||||
arm64) mirror=https://ports.ubuntu.com/ubuntu-ports ;;
|
||||
arm64) mirrors=(https://ports.ubuntu.com/ubuntu-ports https://mirrors.ocf.berkeley.edu/ubuntu-ports) ;;
|
||||
esac
|
||||
sed -E "s@^URIs:.*@URIs: $mirror@" "$ubuntu_sources" > "$sources"
|
||||
chmod 644 "$sources"
|
||||
options[1]="Dir::Etc::sourcelist=$sources"
|
||||
install_packages
|
||||
status=1
|
||||
for mirror in "${mirrors[@]}"; do
|
||||
echo "::warning::Ubuntu mirror failed or timed out; retrying with $mirror."
|
||||
sed -E "s@^URIs:.*@URIs: $mirror@" "$ubuntu_sources" > "$sources"
|
||||
chmod 644 "$sources"
|
||||
options[1]="Dir::Etc::sourcelist=$sources"
|
||||
status=0
|
||||
install_packages || status=$?
|
||||
[ "$status" = 0 ] && exit 0
|
||||
done
|
||||
exit "$status"
|
||||
@@ -171,6 +171,9 @@ def start_agent_activity(adb: str, serial: str, request: dict) -> None:
|
||||
output = (result.stdout + result.stderr).decode(errors="replace")
|
||||
if result.returncode != 0 or "status: ok" not in output.lower():
|
||||
raise ControlError(output.strip() or "The agent start Activity did not launch", "ACTIVITY_START_FAILED")
|
||||
if "activity not started" in output.lower():
|
||||
raise ControlError("Android handed the start request to an existing DroidDeck task instead of starting it: "
|
||||
+ output.strip(), "ACTIVITY_START_FAILED")
|
||||
|
||||
|
||||
def confirm_start(adb: str, serial: str, request: dict, previous: dict) -> dict:
|
||||
|
||||
@@ -58,11 +58,17 @@ class CiChecksTest(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
sudo = root / 'sudo'
|
||||
sudo.write_text('#!/bin/bash\nprintf "%s\\n" "$*" >> "$APT_LOG"\nexit "${APT_RESULT:-0}"\n')
|
||||
sudo.write_text('#!/bin/bash\nprintf "%s\\n" "$*" >> "$APT_LOG"\n'
|
||||
'for arg; do case "$arg" in Dir::Etc::sourcelist=*) '
|
||||
'grep -h "^URIs:" "${arg#*=}" >> "$APT_LOG.mirrors";; esac; done\n'
|
||||
'exit "${APT_RESULT:-0}"\n')
|
||||
sudo.chmod(0o755)
|
||||
query = root / 'dpkg-query'
|
||||
query.write_text('#!/bin/sh\nexit 1\n')
|
||||
query.chmod(0o755)
|
||||
dpkg = root / 'dpkg'
|
||||
dpkg.write_text('#!/bin/sh\necho "${DPKG_ARCH:-amd64}"\n')
|
||||
dpkg.chmod(0o755)
|
||||
log = root / 'apt.log'
|
||||
sources = root / 'ubuntu.sources'
|
||||
sources.write_text('URIs: http://mirror.invalid/ubuntu\n')
|
||||
@@ -71,8 +77,23 @@ class CiChecksTest(unittest.TestCase):
|
||||
installer = ROOT / 'tools/ci/install-ubuntu-packages.sh'
|
||||
result = subprocess.run(['bash', str(installer), 'qemu-user'], env=dict(env, APT_RESULT='17'))
|
||||
self.assertEqual(result.returncode, 17)
|
||||
self.assertEqual(len(log.read_text().splitlines()), 2)
|
||||
self.assertEqual(len(log.read_text().splitlines()), 3)
|
||||
mirrors = Path(str(log) + '.mirrors')
|
||||
self.assertEqual(mirrors.read_text().splitlines(), [
|
||||
'URIs: http://mirror.invalid/ubuntu',
|
||||
'URIs: https://archive.ubuntu.com/ubuntu',
|
||||
'URIs: https://mirrors.edge.kernel.org/ubuntu',
|
||||
])
|
||||
log.unlink()
|
||||
mirrors.unlink()
|
||||
result = subprocess.run(['bash', str(installer), 'qemu-user'], env=dict(env, APT_RESULT='17', DPKG_ARCH='arm64'))
|
||||
self.assertEqual(result.returncode, 17)
|
||||
self.assertEqual(mirrors.read_text().splitlines()[1:], [
|
||||
'URIs: https://ports.ubuntu.com/ubuntu-ports',
|
||||
'URIs: https://mirrors.ocf.berkeley.edu/ubuntu-ports',
|
||||
])
|
||||
log.unlink()
|
||||
mirrors.unlink()
|
||||
subprocess.run(['bash', str(installer), 'qemu-user'], env=env, check=True)
|
||||
update, install = log.read_text().splitlines()
|
||||
for command in (update, install):
|
||||
|
||||
@@ -213,6 +213,18 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
started = [e["args"] for e in self.calls() if e["args"][:3] == ["shell", "am", "start"]]
|
||||
self.assertIn("com.antutu.benchmark.full/com.droiddeck.launcher.agent.AgentStartActivity", started[0])
|
||||
|
||||
def test_a_start_delivered_to_an_existing_task_is_a_failure(self):
|
||||
output = (b"Starting: Intent { cmp=com.droiddeck.launcher/.agent.AgentStartActivity (has extras) }\n"
|
||||
b"Warning: Activity not started, intent has been delivered to currently running top-most instance.\n"
|
||||
b"Status: ok\nActivity: com.droiddeck.launcher/.FrontEndActivity\nComplete\n")
|
||||
|
||||
def adb(_adb, _serial, *args, timeout=30):
|
||||
return ctl.subprocess.CompletedProcess(args, 0, output, b"")
|
||||
|
||||
with unittest.mock.patch.object(ctl, "run_adb", adb), self.assertRaises(ctl.ControlError) as caught:
|
||||
ctl.start_agent_activity("adb", "fake-1", {"mode": "steam"})
|
||||
self.assertEqual("ACTIVITY_START_FAILED", caught.exception.code)
|
||||
|
||||
def test_a_malformed_package_is_refused_before_adb(self):
|
||||
with unittest.mock.patch.dict(os.environ, {"DROIDDECK_PACKAGE": "com.example;reboot"}):
|
||||
variant = load("droiddeckctl")
|
||||
|
||||
Reference in new issue
Block a user