headless 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.1 (2013-02-20)
2
+
3
+ * when starting, wait for Xvfb to launch (fixed issue #33)
4
+
1
5
  ## 1.0.0 (2013-01-28)
2
6
 
3
7
  * bugfix release
data/headless.gemspec CHANGED
@@ -3,7 +3,7 @@ spec = Gem::Specification.new do |s|
3
3
  s.email = 'leonid@shevtsov.me'
4
4
 
5
5
  s.name = 'headless'
6
- s.version = '1.0.0'
6
+ s.version = '1.0.1'
7
7
  s.summary = 'Ruby headless display interface'
8
8
 
9
9
  s.description = <<-EOF
data/lib/headless.rb CHANGED
@@ -44,6 +44,8 @@ class Headless
44
44
  DEFAULT_DISPLAY_NUMBER = 99
45
45
  MAX_DISPLAY_NUMBER = 10_000
46
46
  DEFAULT_DISPLAY_DIMENSIONS = '1280x1024x24'
47
+ # How long should we wait for Xvfb to open a display, before assuming that it is frozen (in seconds)
48
+ XVFB_LAUNCH_TIMEOUT = 10
47
49
 
48
50
  class Exception < RuntimeError
49
51
  end
@@ -72,6 +74,7 @@ class Headless
72
74
  @video_capture_options = options.fetch(:video, {})
73
75
  @destroy_at_exit = options.fetch(:destroy_at_exit, true)
74
76
 
77
+ # FIXME Xvfb launch should not happen inside the constructor
75
78
  attach_xvfb
76
79
  end
77
80
 
@@ -142,9 +145,18 @@ private
142
145
  #TODO error reporting
143
146
  result = system "#{CliUtil.path_to("Xvfb")} :#{display} -screen 0 #{dimensions} -ac >/dev/null 2>&1 &"
144
147
  raise Headless::Exception.new("Xvfb did not launch - something's wrong") unless result
148
+ ensure_xvfb_is_running
145
149
  return true
146
150
  end
147
151
 
152
+ def ensure_xvfb_is_running
153
+ start_time = Time.now
154
+ begin
155
+ sleep 0.01 # to avoid cpu hogging
156
+ raise Headless::Exception.new("Xvfb is frozen") if (Time.now-start_time)>=XVFB_LAUNCH_TIMEOUT
157
+ end while !xvfb_running?
158
+ end
159
+
148
160
  def xvfb_running?
149
161
  !!read_xvfb_pid
150
162
  end
@@ -168,3 +180,4 @@ private
168
180
  end
169
181
  end
170
182
  end
183
+
@@ -17,7 +17,7 @@ describe Headless do
17
17
  end
18
18
  end
19
19
 
20
- context "when Xvfb not started yet" do
20
+ context "when Xvfb is not started yet" do
21
21
  it "starts Xvfb" do
22
22
  Headless.any_instance.should_receive(:system).with("/usr/bin/Xvfb :99 -screen 0 1280x1024x24 -ac >/dev/null 2>&1 &").and_return(true)
23
23
 
@@ -168,5 +168,8 @@ private
168
168
  Headless::CliUtil.stub!(:application_exists?).and_return(true)
169
169
  Headless::CliUtil.stub!(:read_pid).and_return(nil)
170
170
  Headless::CliUtil.stub!(:path_to).and_return("/usr/bin/Xvfb")
171
+
172
+ # TODO this is wrong. But, as long as Xvfb is started inside the constructor (which is also wrong), I don't see another option to make tests pass
173
+ Headless.any_instance.stub(:ensure_xvfb_is_running).and_return(true)
171
174
  end
172
175
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: headless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 2986386947499728446
82
+ hash: -3030427348639260588
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 2986386947499728446
91
+ hash: -3030427348639260588
92
92
  requirements:
93
93
  - Xvfb
94
94
  rubyforge_project: