rwebspec-mechanize 0.2.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 0.3
2
+ - Support RSpec 2.13
3
+
4
+ 0.2.3
5
+ - :virtual_user_count_per_rampup options
6
+
7
+ 0.2.2
8
+ - loadwise later threads will timeout in shorter time
9
+
1
10
  0.2
2
11
  - upgrade rwebspec 4
3
12
 
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rubygems'
2
+ gem 'rspec'
2
3
  require 'rspec/core/rake_task'
3
4
  # require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
+ require 'rubygems/package_task'
5
6
  # require 'rdoc' # require rdoc 2
6
7
  # gem 'darkfish-rdoc'
7
8
  # require 'darkfish-rdoc'
@@ -23,7 +24,7 @@ task :clean do
23
24
  end
24
25
 
25
26
  desc 'Run all specs'
26
- Spec::Rake::SpecTask.new('spec') do |t|
27
+ RSpec::Core::RakeTask.new('spec') do |t|
27
28
  t.spec_opts = ['--format', 'specdoc', '--colour']
28
29
  # t.libs = ["lib", "server/lib" ]
29
30
  t.pattern = Dir['spec/**/*_spec.rb'].sort
@@ -73,7 +74,7 @@ end
73
74
  spec = Gem::Specification.new do |s|
74
75
  s.platform= Gem::Platform::RUBY
75
76
  s.name = "rwebspec-mechanize"
76
- s.version = "0.2.1"
77
+ s.version = "0.4"
77
78
  s.summary = "Web application load testing specification in Ruby"
78
79
  s.description = "Load test specification for web applications in RSpec syntax and Watir"
79
80
 
@@ -92,11 +93,11 @@ spec = Gem::Specification.new do |s|
92
93
  s.files = s.files + Dir.glob( "test/**/*" )
93
94
  s.files = s.files + Dir.glob( "sample/**/*")
94
95
  s.files = s.files + Dir.glob( "docs/**/*" )
95
- s.add_dependency(%q<rspec>, ["2.10.0"])
96
- s.add_dependency("mechanize", ">= 2.5")
96
+ s.add_dependency(%q<rspec>, [">=2.14.0"])
97
+ s.add_dependency("mechanize", ">= 2.7")
97
98
  s.add_dependency("nokogiri")
98
99
  end
99
100
 
100
- Rake::GemPackageTask.new(spec) do |pkg|
101
+ Gem::PackageTask.new(spec) do |pkg|
101
102
  pkg.need_zip = true
102
103
  end
@@ -1,4 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), "plugins", "loadwise_plugin.rb")
2
+ require File.join(File.dirname(__FILE__), "plugins", "loadwise_plugin.rb")
2
3
  require "timeout"
3
4
 
4
5
  module RWebSpec
@@ -10,11 +11,10 @@ module RWebSpec
10
11
  include RWebSpec::Mechanize::Assert
11
12
  include RWebSpec::Mechanize::LoadWisePlugin
12
13
 
13
- MAX_VU = 1000
14
+ MAX_VU = 10001
14
15
 
15
- # only support firefox or Celerity
16
16
  def open_browser(base_url = nil, options = {})
17
- default_options = {:resynchronize => false, :firefox => false, :go => false }
17
+ default_options = {:resynchronize => false, :go => false }
18
18
  options = default_options.merge(options)
19
19
 
20
20
  base_url ||= $LOADWISE_PROJECT_BASE_URL
@@ -22,7 +22,7 @@ module RWebSpec
22
22
  base_url ||= ENV["LOADWISE_PROJECT_BASE_URL"] # pass to java
23
23
  end
24
24
  base_url ||= $BASE_URL
25
- puts "[DEBUG] open |#{base_url}|#{$BASE_URL}| in browser"
25
+ # puts "[DEBUG] open |#{base_url}|#{$BASE_URL}| in browser"
26
26
 
27
27
  mode_preview = ($LOADWISE_PREVIEW || ENV['LOADWISE_PREVIEW'])
28
28
 
@@ -219,11 +219,13 @@ module RWebSpec
219
219
  default_opts[:peak_virtual_user_count] = ENV["LOADWISE_PEAK_VIRTUAL_USER_COUNT"].to_i if ENV["LOADWISE_PEAK_VIRTUAL_USER_COUNT"]
220
220
  default_opts[:delay_between_thread_start] = ENV["LOADWISE_DELAY_BETWEEN_THREAD_START"].to_i if ENV["LOADWISE_DELAY_BETWEEN_THREAD_START"]
221
221
  default_opts[:for_how_long] = ENV["LOADWISE_FOR_HOW_LONG"].to_i if ENV["LOADWISE_FOR_HOW_LONG"]
222
+ default_opts[:virtual_user_count_per_rampup] = ENV["LOADWISE_VIRTUAL_USER_COUNT_PER_RAMPUP"].to_i if ENV["LOADWISE_VIRTUAL_USER_COUNT_PER_RAMPUP"]
222
223
  else
223
224
  # default to performance testing
224
225
  default_opts = {:start_virtual_user_count => 1,
225
226
  :peak_virtual_user_count => 1,
226
- :delay_between_thread_start => 0 }
227
+ :delay_between_thread_start => 0,
228
+ :virtual_user_count_per_rampup => 1 }
227
229
  end
228
230
  end
229
231
 
@@ -232,6 +234,8 @@ module RWebSpec
232
234
  start_virtual_user_count = opts[:start_virtual_user_count] || 2
233
235
  peak_virtual_user_count = opts[:peak_virtual_user_count] || 2
234
236
  delay_between_thread_start = opts[:delay_between_thread_start] || 0
237
+ virtual_user_count_per_rampup = opts[:virtual_user_count_per_rampup] || 1
238
+
235
239
  for_how_long = opts[:for_how_long]
236
240
 
237
241
  # puts "DEBUG for_how_long => #{for_how_long}"
@@ -247,6 +251,7 @@ module RWebSpec
247
251
  end
248
252
 
249
253
  connect_to_loadwise("VU_START", "")
254
+ all_start_time = Time.now
250
255
 
251
256
  if (peak_virtual_user_count <= 1)
252
257
  yield
@@ -256,7 +261,7 @@ module RWebSpec
256
261
 
257
262
  start_virtual_user_count.times do |idx|
258
263
  threads[idx] = Thread.new do
259
- Thread.current[:id] = idx
264
+ Thread.current[:id] = idx + 1
260
265
  start_time = Time.now
261
266
  vu_reports[idx] ||= []
262
267
  begin
@@ -264,6 +269,7 @@ module RWebSpec
264
269
  Timeout::timeout(for_how_long) do
265
270
  while(true)
266
271
  yield
272
+ Thread.pass
267
273
  end
268
274
  end
269
275
  else
@@ -271,11 +277,11 @@ module RWebSpec
271
277
  end
272
278
 
273
279
  vu_reports[idx] = Thread.current[:log]
274
- rescue Timeout::Error
275
- vu_reports[idx] = Thread.current[:log]
276
- puts "Too Slow 2"
280
+ rescue Timeout::Error
281
+ # Looping finished
282
+ vu_reports[idx] = Thread.current[:log]
277
283
  rescue => e
278
- vu_reports[idx] = Thread.current[:log]
284
+ vu_reports[idx] = Thread.current[:log] || []
279
285
  vu_reports[idx] ||= []
280
286
  vu_reports[idx] << { :error => e }
281
287
  # TODO
@@ -289,49 +295,65 @@ module RWebSpec
289
295
  vu_reports[idx] ||= []
290
296
  vu_reports[idx] << { :message => "Total Duration (Initial)", :start_time => start_time, :duration => Time.now - start_time }
291
297
  connect_to_loadwise("VU_END", Thread.current[:id].to_s)
292
- puts "VU[#{idx+1}] #{Time.now - start_time}s"
298
+ # puts "VU[#{idx+1}] #{Time.now - start_time}s"
293
299
  end
294
300
  end
295
301
 
296
- (peak_virtual_user_count - start_virtual_user_count).times do |nidx|
302
+ (start_virtual_user_count..peak_virtual_user_count).step(virtual_user_count_per_rampup) do |nidx|
297
303
  sleep delay_between_thread_start
298
- idx = nidx + start_virtual_user_count
299
- threads[idx] = Thread.new do
300
- start_time = Time.now
301
- vu_reports[idx] ||= []
302
- begin
303
- if for_how_long
304
- Timeout::timeout(for_how_long) do
305
- while(true)
306
- yield
307
- end
308
- end
309
- else
310
- yield
304
+ virtual_user_count_per_rampup.times do |ridx|
305
+ idx = nidx + ridx
306
+ break if idx >= peak_virtual_user_count
307
+ if idx == (peak_virtual_user_count - 1)
308
+ connect_to_loadwise("VU_FULL", "#{Time.now}|#{Time.now - all_start_time}")
309
+ end
310
+
311
+ threads[idx] = Thread.new do
312
+ Thread.current[:id] = idx + 1
313
+ start_time = Time.now
314
+ vu_reports[idx] ||= []
315
+ begin
316
+ if for_how_long
317
+ remaining_time = for_how_long - (Time.now - all_start_time)
318
+ remaining_time = 1 if remaining_time < 0
319
+ Timeout::timeout(remaining_time) do
320
+ while(true)
321
+ yield
322
+ Thread.pass
323
+ end
324
+ end
325
+ else
326
+ yield
327
+ end
328
+ vu_reports[idx] = Thread.current[:log]
329
+ rescue Timeout::Error
330
+ # Looping finished
331
+ vu_reports[idx] = Thread.current[:log]
332
+ # It is not error!!!
333
+ # connect_to_loadwise("VU_ERROR", Thread.current[:id].to_s + "|" + "Timed out at #{Time.now.strftime('%H:%M:%S')} after #{for_how_long} s")
334
+ rescue => e
335
+ vu_reports[idx] = Thread.current[:log] || []
336
+ vu_reports[idx] << { :error => e }
337
+ connect_to_loadwise("VU_ERROR", Thread.current[:id].to_s + "|" + e.to_s)
338
+ unless $vu_error_printed
339
+ puts "VU[#{idx}] Failed: " + e.backtrace.to_s
340
+ $vu_error_printed = true
341
+ end
311
342
  end
312
- vu_reports[idx] = Thread.current[:log]
313
- rescue Timeout::Error
314
- vu_reports[idx] = Thread.current[:log]
315
- puts "!!!Too Slow 2"
316
- rescue => e
317
- vu_reports[idx] = Thread.current[:log]
318
343
  vu_reports[idx] ||= []
319
- vu_reports[idx] << { :error => e }
320
- connect_to_loadwise("VU_ERROR", Thread.current[:id].to_s + "|" + e.to_s)
321
- unless $vu_error_printed
322
- puts "VU[#{idx}] Failed: " + e.backtrace.to_s
323
- $vu_error_printed = true
324
- end
325
- end
326
- vu_reports[idx] ||= []
327
- vu_reports[idx] << { :message => "Total Duration (Peak)", :start_time => start_time, :duration => Time.now - start_time }
328
- puts "VU[#{idx+1}] #{Time.now - start_time}s"
329
- end
344
+ vu_reports[idx] << { :message => "Total Duration (Peak)", :start_time => start_time, :duration => Time.now - start_time }
345
+ puts "VU[#{idx+1}] #{Time.now - start_time}s"
346
+ end
347
+
348
+ end #end of virtual user rampup
330
349
  end
331
350
 
332
351
  threads.each {|t| t.join; }
333
352
 
334
353
  =begin
354
+ #
355
+ # No, LoadWise unable to see the database, also needs SQLite3 for Java
356
+ #
335
357
  # after test finishing, don't try to parse the data, LoadWise can see $memory database
336
358
 
337
359
  vu_reports.each do |key, value|
@@ -11,11 +11,14 @@ module RWebSpec
11
11
  end
12
12
 
13
13
  def connect_to_loadwise(message_type, body)
14
+ if ENV['LOADWISE_TRACE_PORT']
15
+ $LOADWISE_TRACE_PORT ||= ENV['LOADWISE_TRACE_PORT'].to_i
16
+ end
14
17
  return if RUBY_PLATFORM !~ /java/i && $LOADWISE_TRACE_PORT.nil?
15
18
  # Thread.pass
16
- loadwise_port = ($LOADWISE_TRACE_PORT || 7125) + rand(5)
19
+ loadwise_port = ($LOADWISE_TRACE_PORT || 7125)
17
20
  the_message = message_type + "|" + body
18
-
21
+ puts "[DEBUG] connect to LoadWise: #{loadwise_port}"
19
22
  begin
20
23
  # $log.info("[MESSAGE] " + the_message)
21
24
  loadwise_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
@@ -25,7 +28,8 @@ module RWebSpec
25
28
  loadwise_socket.close
26
29
  rescue => e
27
30
  puts("Failed to contact LoadWise '#{message_type}|#{body}' at #{loadwise_port}: #{e}")
28
- retry
31
+ # Only from load testing, the message matters.
32
+ retry if RUBY_PLATFORM =~ /java/i
29
33
  # $log.warn("Failed to contact TestWise: #{e}")
30
34
  end
31
35
  end
@@ -365,11 +365,9 @@ module RWebSpec
365
365
  end
366
366
 
367
367
  # raise "No button with id: #{id} found " unless the_button
368
- if the_button.type == "submit"
369
- puts "[DEBUG] submit the form"
368
+ if the_button.type == "submit"
370
369
  @browser.submit(the_form, the_button)
371
370
  else
372
- puts "[DEBUG] Warning not submit button"
373
371
  @browser.submit(the_form, the_button)
374
372
  end
375
373
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwebspec-mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire: rwebspec-mechanize
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2013-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.10.0
21
+ version: 2.14.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 2.10.0
29
+ version: 2.14.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mechanize
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '2.5'
37
+ version: '2.7'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '2.5'
45
+ version: '2.7'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: nokogiri
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -71,7 +71,6 @@ files:
71
71
  - MIT-LICENSE
72
72
  - lib/rwebspec-mechanize/assert.rb
73
73
  - lib/rwebspec-mechanize/context.rb
74
- - lib/rwebspec-mechanize/extensions/firewatir_extensions.rb
75
74
  - lib/rwebspec-mechanize/extensions/rspec_extensions.rb
76
75
  - lib/rwebspec-mechanize/extensions/watir_extensions.rb
77
76
  - lib/rwebspec-mechanize/extensions/window_script_extensions.rb
@@ -103,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
102
  requirements:
104
103
  - none
105
104
  rubyforge_project: rwebspec-mechanize
106
- rubygems_version: 1.8.24
105
+ rubygems_version: 1.8.25
107
106
  signing_key:
108
107
  specification_version: 3
109
108
  summary: Web application load testing specification in Ruby
@@ -1,74 +0,0 @@
1
- module FireWatir
2
- class Firefox
3
-
4
- @@firefox_started = false
5
-
6
- def initialize(options = {})
7
- if(options.kind_of?(Integer))
8
- options = {:waitTime => options}
9
- end
10
-
11
- if(options[:profile])
12
- profile_opt = "-no-remote -P #{options[:profile]}"
13
- else
14
- profile_opt = ""
15
- end
16
-
17
- waitTime = options[:waitTime] || 2
18
-
19
- os = RUBY_PLATFORM
20
- if RUBY_PLATFORM =~ /java/ then
21
- require 'rbconfig'
22
- os = Config::CONFIG['host_os']
23
- end
24
-
25
- case os
26
- when /mswin/ || /mingw/
27
- begin
28
- # Get the path to Firefox.exe using Registry.
29
- require 'win32/registry.rb'
30
- path_to_bin = ""
31
- Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
32
- keys = reg.keys
33
- reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
34
- reg1.each do |subkey, type, data|
35
- if(subkey =~ /pathtoexe/i)
36
- path_to_bin = data
37
- end
38
- end
39
- end
40
- rescue LoadError => e
41
- path_to_bin = '"C:\Program Files\Mozilla Firefox\firefox.exe"'
42
- end
43
-
44
- when /linux/i
45
- path_to_bin = `which firefox`.strip
46
- when /darwin/i
47
- path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
48
- when /java/
49
- raise "Error, should have set using rbconfig: #{os}"
50
- end
51
-
52
- @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
53
-
54
- sleep waitTime
55
- begin
56
- set_defaults()
57
- rescue Watir::Exception::UnableToStartJSShException
58
- if !@t # no new thread starting browser, try again
59
- puts "Firefox with JSSH not detected after you indicated @@firefox_started"
60
- @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
61
- sleep waitTime
62
- set_defaults
63
- end
64
- end
65
- get_window_number()
66
- set_browser_document()
67
- end
68
-
69
- def self.firefox_started=(value)
70
- @@firefox_started = value
71
- end
72
-
73
- end
74
- end