plu / simctl

Ruby interface to xcrun simctl
http://www.rubydoc.info/gems/simctl
MIT License
104 stars 19 forks source link

kill/shutdown 1 simulator #2

Closed oliverhu closed 7 years ago

oliverhu commented 8 years ago

Hey Johannes,

Suppose we have 5 simulators running, are you aware of any command to kill/shutdown only a single of them .. If you kill the process/simctl shutdown, all simulators will be killed :\

plu commented 8 years ago

If you know the UDID, try this:

SimCtl.device(udid: "105D3EE7-BC54-4973-9C52-0719B95B2552").kill!

This assumes that you actually launched it via the simctl gem (looking for CurrentDeviceUDID in the process list).

oliverhu commented 8 years ago

Tried, not working. All sims are killed :(

plu commented 8 years ago
#!/usr/bin/env ruby

require 'simctl'

runtime = SimCtl.runtime(name: 'iOS 9.2')
devicetype = SimCtl.devicetype(name: 'iPhone 5')

d1 = SimCtl.create_device 'Device 1', devicetype, runtime
d2 = SimCtl.create_device 'Device 2', devicetype, runtime

d1.wait! { |d| d.state == :shutdown }
d2.wait! { |d| d.state == :shutdown }

d1.launch!
d2.launch!

puts "d1: #{d1.udid}"
puts "d2: #{d2.udid}"

puts "Both devices launched..."
puts `ps auxww | grep Simulator.app`

d1.kill!

puts "One device killed..."

sleep 1

puts `ps auxww | grep Simulator.app`

Output:

d1: E75A557C-8080-4CC8-B468-1510028CE363
d2: 6E5A53D3-4856-497C-9BB0-D0DCFF121807
Both devices launched...
plu              86306  47.1  0.4  2593432  32336   ??  S     5:44PM   0:00.22 /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -ConnectHardwareKeyboard 1 -CurrentDeviceUDID E75A557C-8080-4CC8-B468-1510028CE363 -SimulatorWindowLastScale-com.apple.CoreSimulator.SimDeviceType.iPhone-5 1.0
plu              86320   0.7  0.1  2520008  11792   ??  R     5:44PM   0:00.06 /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -ConnectHardwareKeyboard 1 -CurrentDeviceUDID 6E5A53D3-4856-497C-9BB0-D0DCFF121807 -SimulatorWindowLastScale-com.apple.CoreSimulator.SimDeviceType.iPhone-5 1.0
plu              86323   0.0  0.0  2434840    760 s002  R+    5:44PM   0:00.00 grep Simulator.app
plu              86321   0.0  0.0  2452844   1088 s002  S+    5:44PM   0:00.00 sh -c ps auxww | grep Simulator.app
One device killed...
plu              86320   5.1  0.5  2612616  42932   ??  S     5:44PM   0:00.27 /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -ConnectHardwareKeyboard 1 -CurrentDeviceUDID 6E5A53D3-4856-497C-9BB0-D0DCFF121807 -SimulatorWindowLastScale-com.apple.CoreSimulator.SimDeviceType.iPhone-5 1.0
plu              86395   1.3  0.0  2436460   1076 s002  S+    5:44PM   0:00.00 sh -c ps auxww | grep Simulator.app
plu              86397   0.2  0.0  2445080    804 s002  S+    5:44PM   0:00.00 grep Simulator.app
oliverhu commented 8 years ago

This works. But .. if I killed one in the middle of running tests in multiple simulators. All of them are killed.

Basically what i want to achieve is have a retry logic. If a simulator failed to start a test bundle, we can reset that and start testing on that simulator again :D

plu commented 8 years ago

Try passing to xctool when you do run-tests: -noResetSimulatorOnFailure

plu commented 8 years ago

If that doesn't help, I'm out of ideas...