Skip to content

Commit

Permalink
Merge pull request #9 from bitrise-io/xcode-7-ui-test-timout
Browse files Browse the repository at this point in the history
Xcode 7 ui test timout
  • Loading branch information
viktorbenei committed Sep 18, 2015
2 parents aa054d7 + 2e43971 commit 1b94c32
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 25 deletions.
6 changes: 5 additions & 1 deletion bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
app:
envs:
# define these in your .bitrise.secrets.yml
- BITRISE_SOURCE_DIR:
- SOURCE_ROOT_PATH:
- BITRISE_PROJECT_PATH:
- BITRISE_SCHEME:

Expand All @@ -15,6 +15,10 @@ workflows:
title: "Go Test"
inputs:
- content: go test ./...
- script:
title: Switch working dir to SOURCE_ROOT_PATH
inputs:
- content: envman add --key BITRISE_SOURCE_DIR --value "${SOURCE_ROOT_PATH}"
- path::./:
inputs:
- simulator_device: iPhone 6 Plus
Expand Down
32 changes: 28 additions & 4 deletions step.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ import (
"strings"
)

const timeOutMessage = "iPhoneSimulator: Timed out waiting"
// On performance limited OS X hosts (ex: VMs) the iPhone/iOS Simulator might time out
// while booting. So far it seems that a simple retry solves these issues.

// This boot timeout can happen when running Unit Tests
// with Xcode Command Line `xcodebuild`.
const timeOutMessageIPhoneSimulator = "iPhoneSimulator: Timed out waiting"

// This boot timeout can happen when running Xcode (7+) UI tests
// with Xcode Command Line `xcodebuild`.
const timeOutMessageUITest = "Terminating app due to uncaught exception '_XCTestCaseInterruptionException'"

func printConfig(projectPath, scheme, simulatorDevice, simulatorOsVersion, action, deviceDestination, cleanBuild string) {
log.Println()
Expand All @@ -33,8 +42,8 @@ func validateRequiredInput(key string) (string, error) {
return value, nil
}

func isTimeOutError(outputToSearchIn string) (bool, error) {
r, err := regexp.Compile("(?i)" + timeOutMessage)
func isStringFoundInOutput(searchStr, outputToSearchIn string) (bool, error) {
r, err := regexp.Compile("(?i)" + searchStr)
if err != nil {
return false, err
}
Expand All @@ -57,7 +66,8 @@ func runTest(action, projectPath, scheme, cleanBuild, deviceDestination string,

log.Printf("---- cmd: %#v", cmd)
if err := cmd.Run(); err != nil {
if isTimeoutStrFound, err := isTimeOutError(outBuffer.String()); err != nil {
outBuffStr := outBuffer.String()
if isTimeoutStrFound, err := isStringFoundInOutput(timeOutMessageIPhoneSimulator, outBuffStr); err != nil {
return err
} else if isTimeoutStrFound {
log.Println("=> Simulator Timeout detected")
Expand All @@ -66,7 +76,21 @@ func runTest(action, projectPath, scheme, cleanBuild, deviceDestination string,
return runTest(action, projectPath, scheme, cleanBuild, deviceDestination, false)
}
log.Println(" [!] isRetryOnTimeout=false, no more retry, stopping the test!")
return err
}

if isUITestTimeoutFound, err := isStringFoundInOutput(timeOutMessageUITest, outBuffStr); err != nil {
return err
} else if isUITestTimeoutFound {
log.Println("=> Simulator Timeout detected: isUITestTimeoutFound")
if isRetryOnTimeout {
log.Println("==> isRetryOnTimeout=true - retrying...")
return runTest(action, projectPath, scheme, cleanBuild, deviceDestination, false)
}
log.Println(" [!] isRetryOnTimeout=false, no more retry, stopping the test!")
return err
}

return err
}
return nil
Expand Down
Loading

0 comments on commit 1b94c32

Please sign in to comment.