Repository navigation
fix(devicelab_ios): the agent's start brings back the app it sent to the background - #274
Open
luka-vladika-happening-xyz wants to merge 1 commit into
Conversation
…the background The agent's XCTest runner is launched as an app (simctl launch has no background launch, and xcodebuild launches it the same way), so a fresh start sent the app in front of the simulator to the background, and once the agent was up the home screen was left. A flow that starts with launchApp never noticed; a hierarchy read, or a flow that goes on from the screen another tool left, read the home screen instead. A fresh start (not a re-attach) now reads which app is in front before it launches the agent and, once the agent answers, launches that app again with simctl launch (without --terminate-running-process), which brings the running app back as it was: the same process on the same page, in about 0.25 s. simctl does not say which app is in front, but each simulator app is a process of the Mac, and its scheduling priority does: 47-53 for the app in front, 4 for one in the background, 31 for the agent's own runner (iOS 27.2). Only the apps simctl listapps lists are read: launchctl also lists system processes as apps, and the home screen's widget renderer reads 47 while the page with widgets shows. XCTest runners are left out. With no app at 40 or above the home screen was in front, and nothing is launched. Right after a switch the app that left keeps its priority for 1-5 s, so while two apps read as in front they are read again for up to 5 s; if both stay, nothing is launched. Every command has a deadline. One log line says what was brought back or why nothing was, and an app that was not brought back is said on the console too, in a line a test keeps.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #273.
A fresh agent start (not a re-attach) reads which app is in front before it launches the agent and, once the agent answers, launches that app again with
simctl launch(no--terminate-running-process). That brings the running app back as it was: the same process on the same page, in about 0.25 s. Both launch modes do it.simctldoes not say which app is in front, but each simulator app is a process of the Mac, and its scheduling priority does (ps -o pri): 47-53 for the app in front, 4 for an app in the background, 31 for the agent's own runner (iOS 27.2; iOS 17.5 the same, 47 and 4). Only the appssimctl listappslists are read:launchctl listalso lists system processes as apps, and the home screen's widget renderer reads 47 while the page with widgets shows. XCTest runners (bundle ids ending in.xctrunner) are left out. With no app at 40 or above the home screen was in front, and nothing is launched. Right after a switch the app that left keeps its priority for 1-5 s, so while two apps read as in front they are read again for up to 5 s; if both stay, nothing is launched.Every command has a deadline. One log line says what was brought back or why nothing was, and an app that was not brought back gets a console line too, whose text a test keeps for tools that look for it.
Tested: unit tests with fake
launchctl list,simctl listappsandpsanswers for each rule. On an iPhone 18 Pro simulator (iOS 27.2) with the agent stopped,hierarchyread Settings on a subpage, Safari and the home screen (both pages) as they were, withDEVICELAB_IOS_AGENT_LAUNCH=simctlandxcodebuild, and on an iPhone 15 simulator (iOS 17.5) Settings on a subpage; a fresh start took about 0.6 s more (6.0 s to 6.6 s forhierarchy).go test -race ./...and golangci-lint v2.13.2 pass.Left out: the agent's revive (a restart after it stopped answering, in the middle of a flow) goes through the same launch and could do the same. Say if you want it here. Also left: an app sent to the background a moment before a fresh start keeps its priority for 1-5 s, so it reads as in front and is brought back.