Class: Testjour::CLI::Run

Inherits:
BaseCommand show all
Includes:
Bonjour, RunCommand
Defined in:
lib/testjour/commands/run.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#non_options, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bonjour

#bonjour_serve, #bonjour_servers, #found_bonjour_server

Methods included from RunCommand

#run_command

Methods inherited from BaseCommand

detailed_help, help, inherited, options

Constructor Details

#initialize(*args) ⇒ Run

Returns a new instance of Run.



19
20
21
22
23
24
25
26
27
# File 'lib/testjour/commands/run.rb', line 19

def initialize(*args)
  Testjour.logger.debug "Runner command #{self.class}..."
  Testjour.load_cucumber
  
  super
  @found_server = 0
  require "testjour/cucumber_extensions/queueing_executor"
  require "testjour/colorer"
end

Class Method Details

.commandObject



15
16
17
# File 'lib/testjour/commands/run.rb', line 15

def self.command
  "run"
end

Instance Method Details

#command_for_local_runObject



104
105
106
# File 'lib/testjour/commands/run.rb', line 104

def command_for_local_run
  "#{testjour_bin_path} local:run #{testjour_uri} -- #{@non_options.join(' ')}".strip
end

#disable_cucumber_requireObject



44
45
46
47
48
49
50
# File 'lib/testjour/commands/run.rb', line 44

def disable_cucumber_require
  Cucumber::CLI.class_eval do
    def require_files
      ARGV.clear # Shut up RSpec
    end
  end
end

#no_remote?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/testjour/commands/run.rb', line 126

def no_remote?
  @options[:no_remote]
end

#option_parserObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/testjour/commands/run.rb', line 134

def option_parser
  OptionParser.new do |opts|
    opts.on("--on SERVER", "Specify a pattern to exclude servers to. Disabled local runners") do |server|
      @options[:server] ||= []
      @options[:server] << server
    end
    
    opts.on("--no-remote", "Only use local runners") do |server|
      @options[:no_remote] = true
    end
  end
end


60
61
62
63
64
65
66
67
# File 'lib/testjour/commands/run.rb', line 60

def print_results
  puts
  puts "Requesting build from #{@found_server} processes..."
  puts
  
  Cucumber::CLI.executor.wait_for_results
  Testjour.logger.debug "DONE"
end

#queue_features(queue) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/testjour/commands/run.rb', line 52

def queue_features(queue)
  Testjour.logger.debug "Queueing features..."
  disable_cucumber_require
  ARGV.replace(@non_options.clone)
  Cucumber::CLI.executor = Testjour::QueueingExecutor.new(queue, Cucumber::CLI.step_mother)
  Cucumber::CLI.execute
end

#request_build_from(server) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/testjour/commands/run.rb', line 75

def request_build_from(server)
  slave_server = DRbObject.new(nil, server.uri)
  result = slave_server.run(testjour_uri, @non_options)
  
  if result
    Testjour.logger.info "Requesting buld from available server: #{server.uri}. Accepted."
    @found_server += 1
  else
    Testjour.logger.info "Requesting buld from available server: #{server.uri}. Rejected."
  end
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/testjour/commands/run.rb', line 29

def run
  Testjour::QueueServer.with_server do |queue|
    start_local_runners unless servers_specified?
    start_slave_runners unless no_remote?
    
    if @found_server.zero?
      puts "No processes to build on. Aborting."
      exit
    end
    
    queue_features(queue)
    print_results
  end
end

#servers_specified?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/testjour/commands/run.rb', line 130

def servers_specified?
  @options[:server] && @options[:server].any?
end

#slave_servers_to_useObject



69
70
71
72
73
# File 'lib/testjour/commands/run.rb', line 69

def slave_servers_to_use
  @slave_servers_to_use ||= bonjour_servers.select do |potential_server|
    !servers_specified? || specified_servers_include?(potential_server)
  end
end

#specified_servers_include?(potential_server) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/testjour/commands/run.rb', line 120

def specified_servers_include?(potential_server)
  @options[:server].any? do |specified_server|
    potential_server.host.include?(specified_server)
  end
end

#start_local_runnerObject



99
100
101
102
# File 'lib/testjour/commands/run.rb', line 99

def start_local_runner
  run_command(command_for_local_run)
  @found_server += 1
end

#start_local_runnersObject



87
88
89
90
91
# File 'lib/testjour/commands/run.rb', line 87

def start_local_runners
  2.times do 
    start_local_runner
  end
end

#start_slave_runnersObject



93
94
95
96
97
# File 'lib/testjour/commands/run.rb', line 93

def start_slave_runners
  slave_servers_to_use.each do |server|
    request_build_from(server)
  end
end

#testjour_bin_pathObject



108
109
110
# File 'lib/testjour/commands/run.rb', line 108

def testjour_bin_path
  File.expand_path(File.dirname(__FILE__) + "/../../../bin/testjour")
end

#testjour_uriObject



112
113
114
115
116
117
118
# File 'lib/testjour/commands/run.rb', line 112

def testjour_uri
  uri = URI.parse(DRb.uri)
  uri.path = File.expand_path(".")
  uri.scheme = "testjour"
  uri.user = `whoami`.strip
  uri.to_s
end