headless 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef56937376649ddec958dd8ebb7115513e7d2519
4
- data.tar.gz: 0af69d915022f127ce0f330cb85d5f8af3ee5cbd
3
+ metadata.gz: 93e191ea69ebabc46da9431bff74b33ccbf646c9
4
+ data.tar.gz: 68b29362c47b8e776153638f187c62f467fdd422
5
5
  SHA512:
6
- metadata.gz: ff4dbb75ff3a1c1ee0d91d4a8f4d199302957b2c0a124dbf1617a5ddd7c4bf4076f25ea068241e93876864baeea80f4df288d836b538be5770674ed77d161974
7
- data.tar.gz: 9f08e6ca9518a5eb39760739be39bdf1ab9a5063ce43e475607d87dc35da03b15b9a26a33f459d5f52f4a9b981f05b2fc1aa6a6937b007a73462502ce7981b82
6
+ metadata.gz: 757f8e09da108796a51bc6b823fe8b4ab67e8d4f900ff11dcdccbfe1434a0ca5bb5cda1a28c4cdc98a49664081512fbe5c57ca54ddc21e0a797b53b1b30eca40
7
+ data.tar.gz: cde1f7f928582f1f6c6f90a0b06a5c1389b2ca66f682ad78a141294bfbfa4df9666ee87c2df2be1283c9fdeb3d8a3fe2f0e7a6dceadb9638b206df5198c60b12
@@ -6,4 +6,5 @@ rvm:
6
6
  before_install:
7
7
  - "sudo apt-get update"
8
8
  - "sudo apt-get install -y firefox xvfb libav-tools"
9
+ - "gem install bundler"
9
10
  script: "rspec"
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.2.3 (2016-03-17)
2
+
3
+ * Fix race condition when starting Xvfb [#75] (from @NfNitLoop)
4
+
1
5
  ## 2.2.2 (2016-02-08)
2
6
 
3
7
  * Fix file permissions issue with gem. No actual changes
@@ -1,9 +1,9 @@
1
- spec = Gem::Specification.new do |s|
1
+ Gem::Specification.new do |s|
2
2
  s.author = 'Leonid Shevtsov'
3
3
  s.email = 'leonid@shevtsov.me'
4
4
 
5
5
  s.name = 'headless'
6
- s.version = '2.2.2'
6
+ s.version = '2.2.3'
7
7
  s.summary = 'Ruby headless display interface'
8
8
  s.license = 'MIT'
9
9
 
@@ -16,6 +16,6 @@ spec = Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
 
18
18
  s.add_development_dependency 'rake'
19
- s.add_development_dependency "rspec", "~> 3"
20
- s.add_development_dependency "selenium-webdriver"
19
+ s.add_development_dependency 'rspec', '~> 3'
20
+ s.add_development_dependency 'selenium-webdriver'
21
21
  end
@@ -83,6 +83,7 @@ class Headless
83
83
  @dimensions = options.fetch(:dimensions, DEFAULT_DISPLAY_DIMENSIONS)
84
84
  @video_capture_options = options.fetch(:video, {})
85
85
  @destroy_at_exit = options.fetch(:destroy_at_exit, true)
86
+ @pid = nil # the pid of the running Xvfb process
86
87
 
87
88
  # FIXME Xvfb launch should not happen inside the constructor
88
89
  attach_xvfb
@@ -176,16 +177,18 @@ private
176
177
 
177
178
  def launch_xvfb
178
179
  out_pipe, in_pipe = IO.pipe
179
- pid = Process.spawn(
180
+ @pid = Process.spawn(
180
181
  CliUtil.path_to("Xvfb"), ":#{display}", "-screen", "0", dimensions, "-ac",
181
182
  err: in_pipe)
182
- in_pipe.close
183
- raise Headless::Exception.new("Xvfb did not launch - something's wrong") unless pid
184
- ensure_xvfb_is_running(out_pipe)
185
- return true
183
+ raise Headless::Exception.new("Xvfb did not launch - something's wrong") unless @pid
184
+ # According to docs, you should either wait or detach on spawned procs:
185
+ Process.detach @pid
186
+ return ensure_xvfb_launched(out_pipe)
187
+ ensure
188
+ in_pipe.close
186
189
  end
187
190
 
188
- def ensure_xvfb_is_running(out_pipe)
191
+ def ensure_xvfb_launched(out_pipe)
189
192
  start_time = Time.now
190
193
  errors = ""
191
194
  begin
@@ -194,18 +197,30 @@ private
194
197
  if errors.include? "Cannot establish any listening sockets"
195
198
  raise Headless::Exception.new("Display socket is taken but lock file is missing - check the Headless troubleshooting guide")
196
199
  end
200
+ if errors.include? "Server is already active for display #{display}"
201
+ # This can happen if there is a race to grab the lock file.
202
+ # Not an exception, just return false to let pick_available_display choose another:
203
+ return false
204
+ end
197
205
  rescue IO::WaitReadable
198
206
  # will retry next cycle
199
207
  end
200
208
  sleep 0.01 # to avoid cpu hogging
201
209
  raise Headless::Exception.new("Xvfb launched but did not complete initialization") if (Time.now-start_time)>=@xvfb_launch_timeout
210
+ # Continue looping until Xvfb has written its pidfile:
202
211
  end while !xvfb_running?
212
+
213
+ # If for any reason the pid file doesn't match ours, we lost the race to
214
+ # get the file lock:
215
+ return @pid == read_xvfb_pid
203
216
  end
204
217
 
205
218
  def xvfb_mine?
206
219
  CliUtil.process_mine?(read_xvfb_pid)
207
220
  end
208
221
 
222
+ # Check whether an Xvfb process is running on @display.
223
+ # NOTE: This might be a process started by someone else!
209
224
  def xvfb_running?
210
225
  (pid = read_xvfb_pid) && CliUtil.process_running?(pid)
211
226
  end
@@ -8,7 +8,7 @@ describe Headless do
8
8
 
9
9
  describe 'launch options' do
10
10
  before do
11
- allow_any_instance_of(Headless).to receive(:ensure_xvfb_is_running).and_return(true)
11
+ allow_any_instance_of(Headless).to receive(:ensure_xvfb_launched).and_return(true)
12
12
  end
13
13
 
14
14
  it "starts Xvfb" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: headless
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Shevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake