Skip to content

Commit

Permalink
Fixing issue where memory would bloat in UITest runner when running o…
Browse files Browse the repository at this point in the history
…n device. It seemed to have been caused by XCUIApplication() getting called multiple times per execution of an action. Its now only retained once per action.
  • Loading branch information
wcrestfield committed Dec 18, 2018
1 parent 43abdfd commit e87bed2
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions SwiftMonkey/Monkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,24 @@ public class Monkey {
and not in some other app that the Monkey randomly opened.
*/
func actInForeground(_ action: @escaping ActionClosure) -> ActionClosure {
return {
guard #available(iOS 9.0, *) else {
action()
return
}
let closure: ActionClosure = {
if XCUIApplication().state != .runningForeground {
XCUIApplication().activate()
}
action()
}
if Thread.isMainThread {
closure()
} else {
DispatchQueue.main.async(execute: closure)
}
}
guard #available(iOS 9.0, *) else {
return action
}

let app = XCUIApplication()
let closure: ActionClosure = {
if app.state != .runningForeground {
app.activate()
}
action()
}
return {
if Thread.isMainThread {
closure()
} else {
DispatchQueue.main.async(execute: closure)
}
}
}

/**
Expand Down

0 comments on commit e87bed2

Please sign in to comment.