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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG +4 -0
- data/headless.gemspec +4 -4
- data/lib/headless.rb +21 -6
- data/spec/headless_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93e191ea69ebabc46da9431bff74b33ccbf646c9
|
4
|
+
data.tar.gz: 68b29362c47b8e776153638f187c62f467fdd422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757f8e09da108796a51bc6b823fe8b4ab67e8d4f900ff11dcdccbfe1434a0ca5bb5cda1a28c4cdc98a49664081512fbe5c57ca54ddc21e0a797b53b1b30eca40
|
7
|
+
data.tar.gz: cde1f7f928582f1f6c6f90a0b06a5c1389b2ca66f682ad78a141294bfbfa4df9666ee87c2df2be1283c9fdeb3d8a3fe2f0e7a6dceadb9638b206df5198c60b12
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/headless.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
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.
|
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
|
20
|
-
s.add_development_dependency
|
19
|
+
s.add_development_dependency 'rspec', '~> 3'
|
20
|
+
s.add_development_dependency 'selenium-webdriver'
|
21
21
|
end
|
data/lib/headless.rb
CHANGED
@@ -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
|
-
|
183
|
-
|
184
|
-
|
185
|
-
return
|
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
|
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
|
data/spec/headless_spec.rb
CHANGED
@@ -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(:
|
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.
|
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-
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|