selenium-grid 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,8 @@ lib/tasks/hoe.rake
24
24
  lib/tasks/hub.rake
25
25
  lib/tasks/rc.rake
26
26
  lib/tasks/rspec.rake
27
+ lib/utils.rb
28
+ lib/utils/netstat.rb
27
29
  spec/extensions/string_spec.rb
28
30
  spec/extensions_spec_suite.rb
29
31
  spec/java/vm_spec.rb
@@ -34,3 +36,4 @@ spec/selenium-grid_spec_suite.rb
34
36
  spec/spec.opts
35
37
  spec/spec_helper.rb
36
38
  spec/spec_suite.rb
39
+ spec/utils/netstat_spec.rb
@@ -1,4 +1,4 @@
1
- AUTHOR = ['Ryan Dy', 'Corey Innis']
1
+ AUTHOR = ['Ryan Dy', 'Corey Innis', 'Kunal Anand']
2
2
  EMAIL = "ops+rubyforge@pivotallabs.com"
3
3
  DESCRIPTION = "Selenium Grid Ruby packages Selenium Grid as a gem"
4
4
  GEM_NAME = 'selenium-grid'
@@ -25,3 +25,4 @@ end
25
25
  require 'extensions'
26
26
  require 'java'
27
27
  require 'selenium-grid'
28
+ require 'utils'
@@ -3,6 +3,7 @@ require 'singleton'
3
3
  module SeleniumGrid
4
4
  class Hub
5
5
  include Singleton
6
+ include Utils
6
7
 
7
8
  HUB_PORT=4444
8
9
 
@@ -30,7 +31,7 @@ module SeleniumGrid
30
31
  end
31
32
 
32
33
  def running?
33
- Lsof.running?(HUB_PORT)
34
+ Netstat.instance.running?(HUB_PORT)
34
35
  end
35
36
  end
36
37
  end
@@ -4,6 +4,7 @@ require File.join(File.dirname(__FILE__), "hub")
4
4
  module SeleniumGrid
5
5
  class Remote
6
6
  include Singleton
7
+ include Utils
7
8
 
8
9
  DEFAULT_BROWSER = "*chrome"
9
10
  DEFAULT_PORT = 5555
@@ -33,7 +34,7 @@ module SeleniumGrid
33
34
  end
34
35
 
35
36
  def list
36
- return {} unless Lsof.running?(Hub::HUB_PORT)
37
+ return {} unless Netstat.instance.running?(Hub::HUB_PORT)
37
38
  remotes = ps.split(/\n|\r/)
38
39
  return {} if remotes.empty?
39
40
 
@@ -46,7 +47,7 @@ module SeleniumGrid
46
47
  end
47
48
 
48
49
  def running?(port = ENV['PORT'] || DEFAULT_PORT)
49
- Lsof.running?(port)
50
+ Netstat.instance.running?(port)
50
51
  end
51
52
 
52
53
  def arguments(overrides = {})
@@ -2,7 +2,7 @@ module SeleniumGrid #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'config', 'requirements')
2
+ require_path '/lib/utils/**/*.rb'
@@ -0,0 +1,12 @@
1
+ require 'singleton'
2
+
3
+ module Utils
4
+ class Netstat
5
+ include Singleton
6
+
7
+ def running?(port)
8
+ result = system("netstat -an | grep #{port}")
9
+ result
10
+ end
11
+ end
12
+ end
@@ -71,7 +71,7 @@ module SeleniumGrid
71
71
  describe "#list" do
72
72
  context "when the Hub is not running" do
73
73
  before do
74
- mock(Lsof).running?(Hub::HUB_PORT) { false }
74
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { false }
75
75
  end
76
76
 
77
77
  it "lists empty string" do
@@ -81,7 +81,7 @@ module SeleniumGrid
81
81
 
82
82
  context "when the Hub is running" do
83
83
  before do
84
- mock(Lsof).running?(Hub::HUB_PORT) { true }
84
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { true }
85
85
  end
86
86
 
87
87
  it "lists details about the running Hub" do
@@ -93,7 +93,7 @@ module SeleniumGrid
93
93
  describe "#running?" do
94
94
  context "when the Hub is not running" do
95
95
  before do
96
- mock(Lsof).running?(Hub::HUB_PORT) { false }
96
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { false }
97
97
  end
98
98
 
99
99
  it "returns false" do
@@ -103,7 +103,7 @@ module SeleniumGrid
103
103
 
104
104
  context "when the Hub is running" do
105
105
  before do
106
- mock(Lsof).running?(Hub::HUB_PORT) { true }
106
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { true }
107
107
  end
108
108
 
109
109
  it "lists returns true" do
@@ -103,7 +103,7 @@ module SeleniumGrid
103
103
  describe "#list" do
104
104
  context "when there is no Remote running" do
105
105
  before do
106
- mock(Lsof).running?(anything) { false }
106
+ mock(Utils::Netstat.instance).running?(anything) { false }
107
107
  end
108
108
 
109
109
  it "lists nothing" do
@@ -113,7 +113,7 @@ module SeleniumGrid
113
113
 
114
114
  context "when a single Remote is running" do
115
115
  before do
116
- mock(Lsof).running?(Hub::HUB_PORT) { true }
116
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { true }
117
117
  mock(remote).ps { "prefix -port #{Remote::DEFAULT_PORT} -env #{Remote::DEFAULT_BROWSER} suffix" }
118
118
  end
119
119
 
@@ -124,7 +124,7 @@ module SeleniumGrid
124
124
 
125
125
  context "when multiple Remotes are running" do
126
126
  before do
127
- mock(Lsof).running?(Hub::HUB_PORT) { true }
127
+ mock(Utils::Netstat.instance).running?(Hub::HUB_PORT) { true }
128
128
  mock(remote).ps do
129
129
  "prefix -port #{Remote::DEFAULT_PORT} -env #{Remote::DEFAULT_BROWSER} suffix\n" +
130
130
  "prefix -port 1234 -env *safari suffix\n"
@@ -143,7 +143,7 @@ module SeleniumGrid
143
143
  context "when a port number is not provided" do
144
144
  context "when a Remote is not running on the default port" do
145
145
  before do
146
- mock(Lsof).running?(Remote::DEFAULT_PORT) { false }
146
+ mock(Utils::Netstat.instance).running?(Remote::DEFAULT_PORT) { false }
147
147
  end
148
148
 
149
149
  it "returns false" do
@@ -153,7 +153,7 @@ module SeleniumGrid
153
153
 
154
154
  context "when a Remote is running on the default port" do
155
155
  before do
156
- mock(Lsof).running?(Remote::DEFAULT_PORT) { true }
156
+ mock(Utils::Netstat.instance).running?(Remote::DEFAULT_PORT) { true }
157
157
  end
158
158
 
159
159
  it "returns true" do
@@ -163,23 +163,29 @@ module SeleniumGrid
163
163
  end
164
164
 
165
165
  context "when a port number is provided" do
166
+ attr_reader :port
167
+
168
+ before do
169
+ @port = 1234
170
+ end
171
+
166
172
  context "when a Remote is not running on the provided port" do
167
173
  before do
168
- mock(Lsof).running?(1234) { false }
174
+ mock(Utils::Netstat.instance).running?(port) { false }
169
175
  end
170
176
 
171
177
  it "returns false" do
172
- remote.running?(1234).should be_false
178
+ remote.running?(port).should be_false
173
179
  end
174
180
  end
175
181
 
176
182
  context "when a Remote is running on the provided port" do
177
183
  before do
178
- mock(Lsof).running?(1234) { true }
184
+ mock(Utils::Netstat.instance).running?(port) { true }
179
185
  end
180
186
 
181
187
  it "returns true" do
182
- remote.running?(1234).should be_true
188
+ remote.running?(port).should be_true
183
189
  end
184
190
  end
185
191
  end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Utils
4
+ describe Netstat do
5
+ describe "#running?" do
6
+ context "when passed a valid port number" do
7
+ attr_reader :port
8
+
9
+ before do
10
+ @port = 1234
11
+ end
12
+
13
+ context "when the port is in use" do
14
+ before do
15
+ mock(Netstat.instance).system(anything) { true }
16
+ end
17
+
18
+ it "returns true" do
19
+ Utils::Netstat.instance.running?(port).should be_true
20
+ end
21
+ end
22
+
23
+ context "when the port is not in use" do
24
+ before do
25
+ mock(Netstat.instance).system(anything) { false }
26
+ end
27
+
28
+ it "returns false" do
29
+ Utils::Netstat.instance.running?(port).should be_false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Dy
8
8
  - Corey Innis
9
+ - Kunal Anand
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
13
 
13
- date: 2008-10-07 00:00:00 -07:00
14
+ date: 2008-10-13 00:00:00 -07:00
14
15
  default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
@@ -90,6 +91,8 @@ files:
90
91
  - lib/tasks/hub.rake
91
92
  - lib/tasks/rc.rake
92
93
  - lib/tasks/rspec.rake
94
+ - lib/utils.rb
95
+ - lib/utils/netstat.rb
93
96
  - spec/extensions/string_spec.rb
94
97
  - spec/extensions_spec_suite.rb
95
98
  - spec/java/vm_spec.rb
@@ -100,6 +103,7 @@ files:
100
103
  - spec/spec.opts
101
104
  - spec/spec_helper.rb
102
105
  - spec/spec_suite.rb
106
+ - spec/utils/netstat_spec.rb
103
107
  has_rdoc: true
104
108
  homepage: http://selenium-grid.rubyforge.org
105
109
  post_install_message:
@@ -132,3 +136,4 @@ test_files:
132
136
  - spec/java/vm_spec.rb
133
137
  - spec/selenium-grid/hub_spec.rb
134
138
  - spec/selenium-grid/remote_spec.rb
139
+ - spec/utils/netstat_spec.rb