Module: RWebSpec::Mechanize::LoadWisePlugin

Included in:
LoadTestHelper
Defined in:
lib/rwebspec-mechanize/plugins/loadwise_plugin.rb

Instance Method Summary collapse

Instance Method Details

#connect_to_loadwise(message_type, body) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rwebspec-mechanize/plugins/loadwise_plugin.rb', line 13

def connect_to_loadwise(message_type, body)
    # return unless defined?(AGILEWAY_APP_ROOT)
 
  if ENV['LOADWISE_TRACE_PORT']
      $LOADWISE_TRACE_PORT ||= ENV['LOADWISE_TRACE_PORT'].to_i
    end
	return if RUBY_PLATFORM !~ /java/i && $LOADWISE_TRACE_PORT.nil?
	# Thread.pass      
	loadwise_port = ($LOADWISE_TRACE_PORT || 7125)
   the_message = message_type + "|" + body
	puts "[DEBUG] connect to LoadWise: #{loadwise_port}"
  begin
    # $log.info("[MESSAGE] " + the_message)
    loadwise_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
    loadwise_socket.connect(Socket.pack_sockaddr_in(loadwise_port, '127.0.0.1'))
    loadwise_socket.puts(the_message)
    @last_message = the_message
    loadwise_socket.close
  rescue => e
    puts("Failed to contact LoadWise '#{message_type}|#{body}' at #{loadwise_port}: #{e}")
    # Only from load testing, the message matters.
		retry if RUBY_PLATFORM =~ /java/i
    # $log.warn("Failed to contact TestWise: #{e}")
  end
end

#debug(message) ⇒ Object



8
9
10
11
# File 'lib/rwebspec-mechanize/plugins/loadwise_plugin.rb', line 8

def debug(message)
  Thread.pass
  connect_to_loadwise(" DEBUG", message.to_s + "\r\n") if $RUN_IN_TESTWISE && message
end

#dump_caller_stackObject

find out the line (and file) the execution is on, and notify iTest via Socket



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rwebspec-mechanize/plugins/loadwise_plugin.rb', line 65

def dump_caller_stack
  # puts "CAlling dump_caller_stack"
  return unless ($TESTWISE_TRACE_EXECUTION || $LOADWISE_TRACE_EXECUTION)
  begin
    trace_lines = []
    trace_file = nil
    found_first_spec_reference = false
    caller.each_with_index do |position, idx|
      next unless position =~ /\A(.*?):(\d+)/
      trace_file = $1
      if trace_file =~ /(_spec|_test|_rwebspec)\.rb\s*$/ || trace_file =~ /\.feature$/
        found_first_spec_reference = true
        trace_lines << position
        break
      end
      trace_lines << position
      break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/
      break if trace_lines.size > 10
      # TODO: send multiple trace to be parse with pages.rb
      # break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/ or trace_file =~ /driver\.rb$/ or trace_file =~ /timeout\.rb$/ # don't include rspec or ruby trace
    end

    #  (trace_file.include?("_spec.rb") || trace_file.include?("_rwebspec.rb") || trace_file.include?("_test.rb") || trace_file.include?("_cmd.rb"))
    if !trace_lines.empty?
      connect_to_loadwise(" TRACE", trace_lines.reverse.join("|"))
    end

  rescue => e
    puts "failed to capture log: #{e}"
  end
end

#notify_screenshot_location(image_file_path) ⇒ Object



60
61
62
# File 'lib/rwebspec-mechanize/plugins/loadwise_plugin.rb', line 60

def notify_screenshot_location(image_file_path)
  connect_to_loadwise("  SHOT", image_file_path)
end

#operation_delayObject

Support of iTest to ajust the intervals between keystroke/mouse operations



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rwebspec-mechanize/plugins/loadwise_plugin.rb', line 40

def operation_delay
  begin
		
if $TESTWISE_OPERATION_DELAY && $TESTWISE_OPERATION_DELAY > 0 &&
            $TESTWISE_OPERATION_DELAY < 30000  then # max 30 seconds
      Thread.pass
      sleep($TESTWISE_OPERATION_DELAY / 1000)
    end

    while $TESTWISE_PAUSE || $LOADWISE_PAUSE
      Thread.pass
      debug("Paused, waiting ...")
      sleep 1
    end
  rescue => e
    puts "Error on delaying: #{e}"
    # ignore
  end
end