Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .nx/version-plans/cut-xctest-permission-watchdog-polling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
__default__: patch
---

The iOS permission-dialog watchdog now uses far less CPU, and its polling interval is tunable via HARNESS_XCTEST_AGENT_TICK_INTERVAL_MS.
1 change: 1 addition & 0 deletions apps/playground/rn-harness.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
defaultRunner: 'android',
platformReadyTimeout: 300000,
bridgeTimeout: 120000,
testTimeout: 10000,

permissions: true,
detectNativeCrashes: true,
Expand Down
9 changes: 9 additions & 0 deletions packages/platform-ios/src/xctest-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const xctestAgentLogger = logger.child('ios-xctest-agent');
const XCTEST_AGENT_PROJECT_NAME = 'HarnessXCTestAgent';
const XCTEST_AGENT_SCHEME_NAME = 'HarnessXCTestAgent';
const XCTEST_AGENT_PORT_ENV = 'HARNESS_XCTEST_AGENT_PORT';
const XCTEST_AGENT_TICK_INTERVAL_MS_ENV =
'HARNESS_XCTEST_AGENT_TICK_INTERVAL_MS';
const XCTEST_AGENT_TARGET_BUNDLE_ID_ENV =
'HARNESS_XCTEST_AGENT_TARGET_BUNDLE_ID';
const XCTEST_AGENT_XCTESTRUN_FILE_ENV = 'HARNESS_IOS_XCTESTRUN_FILE';
Expand Down Expand Up @@ -937,13 +939,20 @@ export const createXCTestAgentController = (options: {
let processTask: Promise<void> | null = null;

const getLaunchEnvironment = (): Record<string, string> => {
const tickIntervalMs = getEnvironmentPath(XCTEST_AGENT_TICK_INTERVAL_MS_ENV);

return Object.assign(
{},
options.appBundleId
? {
[XCTEST_AGENT_TARGET_BUNDLE_ID_ENV]: options.appBundleId,
}
: {},
tickIntervalMs
? {
[XCTEST_AGENT_TICK_INTERVAL_MS_ENV]: tickIntervalMs,
}
: {},
...capabilities.map(
(capability) => capability.getLaunchEnvironment?.() ?? {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,24 @@ private final class XCTestAgentHTTPServer {
final class HarnessXCTestAgentUITests: XCTestCase {
private enum Environment {
static let targetBundleIdentifier = "HARNESS_XCTEST_AGENT_TARGET_BUNDLE_ID"
static let tickIntervalMs = "HARNESS_XCTEST_AGENT_TICK_INTERVAL_MS"
}

private enum Constants {
static let defaultSessionDuration: TimeInterval = 60 * 60
static let tickInterval: TimeInterval = 1
static let defaultTickInterval: TimeInterval = 1
}

private static func resolveTickInterval() -> TimeInterval {
guard
let rawValue = ProcessInfo.processInfo.environment[Environment.tickIntervalMs],
let milliseconds = Int(rawValue),
milliseconds > 0
else {
return Constants.defaultTickInterval
}

return TimeInterval(milliseconds) / 1000
}

private let state = HarnessXCTestAgentState(
Expand All @@ -194,6 +207,7 @@ final class HarnessXCTestAgentUITests: XCTestCase {
private let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
private var capabilities: [AgentCapability] = []
private var httpServer: XCTestAgentHTTPServer?
private let tickInterval = HarnessXCTestAgentUITests.resolveTickInterval()

private func log(_ message: String) {
NSLog("[HarnessXCTestAgent] %@", message)
Expand Down Expand Up @@ -309,7 +323,7 @@ final class HarnessXCTestAgentUITests: XCTestCase {
}

RunLoop.current.run(
until: Date().addingTimeInterval(Constants.tickInterval)
until: Date().addingTimeInterval(tickInterval)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ final class PermissionPromptWatchdog: AgentCapability {
return
}

let guardQuery = springboard.buttons.matching(
NSPredicate(format: "label IN %@", Constants.knownPositiveButtonLabels)
).firstMatch

guard guardQuery.exists else {
return
}

for label in Constants.knownPositiveButtonLabels {
let button = springboard.buttons[label].firstMatch

Expand Down
Loading