LoginSignup
17
15

More than 5 years have passed since last update.

tmux上からxcodebuild(xctool)でテストするとiOS Simulatorがタイムアウトする

Posted at

xcodebuild(もしくはxctool)でテストを実行すると、以下の様なログでSimulatorの起動がタイムアウトする現象にでくわした。

  run-test MyAppTests.xctest (iphonesimulator8.1, application-test)
    [Info] Installed 'jp.horimislime.MyApp'. (614 ms)
    [Info] Launching test host and running tests ... (0 ms)
    [Info] The simulator failed to start, or the TEST_HOST application failed to run. Simulator error: Simulator session timed out.; will retry 2 more times. (0 ms)
    [Info] Verified iOS Simulators... (0 ms)
    [Info] Shut down iOS Simulator... (1230 ms)
    [Info] Stopped any existing iOS simulator jobs to get a fresh simulator. (5 ms)
    [Info] The simulator failed to start, or the TEST_HOST application failed to run. Simulator error: Simulator session timed out.; will retry 1 more time. (0 ms)
    [Info] Verified iOS Simulators... (0 ms)
    [Info] Shut down iOS Sim

〜中略〜
Failures:

  0) -[TEST_BUNDLE FAILED_TO_START] (MyAppTests.xctest)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
There was a problem starting the test bundle: The simulator failed to start, or the TEST_HOST application failed to run. Simulator error: Simulator sessi

色々試してるとtmux上でxcodebuildした時だけ再現して、素のshellで実行すると問題ないので悩んだ...

どうやらtmux上でpbcopy/pbpasteが動かない有名な問題と似た原因らしい。
ChrisJohnsen/tmux-MacOSX-pasteboard

tmux uses the daemon(3) library function when starting its server process. In Mac OS X 10.5, Apple changed daemon(3) to move the resulting process from its original bootstrap namespace to the root bootstrap namespace. This means that the tmux server, and its children, will automatically and uncontrollably lose access to what would have been their original bootstrap namespace (i.e. the one that has access to the pasteboard service).

OSXの各プロセスはnamespaceを持っていて、プロセスから他のプロセスを呼ぶ場合namespaceによってアクセスが制限される場合がある。tmuxサーバ(とクライアント)のプロセスとOSXのクリップボードプロセスは互いにアクセスできないnamespace上で動いているせいで、tmuxウインドウから素直にpbcopy/pbpasteが使えないらしい。

tmux上でxcodebiuldするとiOS Simulatorが起動できないのもこのnamespaceが問題らしく、クリップボード問題と同様にbrew install reattach-to-user-namespaceして.tmux.confに一行追記したらあっさりxcodebuildが成功した。

tmux.conf
set-option -g default-command "reattach-to-user-namespace -l zsh"

このOSXプロセスによる問題、Jenkins上でxcodebuildしてハマる人が多いらしく情報多かった。

SOのスレッドによると
jenkins - Timeout when running xcodebuild tests under Xcode 6 via SSH - Stack Overflow

  • OSXのJenkinsは初期設定だとLaunchDaemons経由で起動する
    • LaunchDaemonsで起動したプロセスはGUIへのアクセスが許可されていない
    • XCode5時代のxcodebuildはなぜかこのcontextで動いたらしいが、6以降は不可
  • LaunchAgentsから立ち上げたプロセスはGUIアプリを扱うことができる
    • Jenkinsジョブ上でiOS Simulatorを使うなら起動方法を変えると良い

OSXのsshdもLaunchDaemonsで動いているようなので、SSH越しにリモートサーバのSimulatorを起動する場合も設定を変える必要があるみたい。

17
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
15