Class: DeepTest::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/options.rb

Defined Under Namespace

Classes: InvalidOptionError

Constant Summary collapse

VALID_OPTIONS =
[
  Option.new(:distributed_server, Option::String, nil),
  Option.new(:number_of_workers,  Option::Integer, 2),
  Option.new(:metrics_file,       Option::String, nil),
  Option.new(:pattern,            Option::String, nil),
  Option.new(:server_port,        Option::Integer, 6969),
  Option.new(:sync_options,       Option::Hash, {}),
  Option.new(:timeout_in_seconds, Option::Integer, 30),
  Option.new(:ui,                 Option::String, "DeepTest::UI::Console"),
  Option.new(:worker_listener,    Option::String, "DeepTest::NullWorkerListener"),
]
UI_INSTANCES =

Don’t store UI instances in the options instance, which will need to be dumped over DRb. UI instances may not be dumpable and we don’t want to have to start yet another DRb Server

{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Options

Returns a new instance of Options.



40
41
42
43
44
45
46
# File 'lib/deep_test/options.rb', line 40

def initialize(hash)
  @origin_hostname = Socket.gethostname
  check_option_keys(hash)
  VALID_OPTIONS.each do |option|
    send("#{option.name}=", hash[option.name] || option.default)
  end
end

Class Method Details

.from_command_line(command_line) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/deep_test/options.rb', line 32

def self.from_command_line(command_line)
  hash = {}
  VALID_OPTIONS.each do |option|
    hash[option.name] = option.from_command_line(command_line)
  end
  new(hash)
end

Instance Method Details

#cpu_countObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/deep_test/options.rb', line 105

def cpu_count
  case RUBY_PLATFORM
  when /darwin/
    output = `sysctl -n hw.ncpu`
    output.strip.to_i
  when /linux/
    File.readlines("/proc/cpuinfo").inject(0) do |count, line|
      next count + 1 if line =~ /processor\s*:\s*\d+/
      count
    end
  end
end

#gathering_metrics?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/deep_test/options.rb', line 48

def gathering_metrics?
  !@metrics_file.nil?
end

#mirror_path(base) ⇒ Object



81
82
83
84
85
# File 'lib/deep_test/options.rb', line 81

def mirror_path(base)
  raise "No source directory specified in sync_options" unless sync_options[:source]
  relative_mirror_path = origin_hostname + sync_options[:source].gsub('/','_')
  "#{base}/#{relative_mirror_path}"
end

#new_listener_listObject



52
53
54
55
56
57
# File 'lib/deep_test/options.rb', line 52

def new_listener_list
  listeners = worker_listener.split(',').map do |listener|
    eval(listener).new
  end
  ListenerList.new(listeners)
end

#new_workersObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/deep_test/options.rb', line 87

def new_workers
  if distributed_server.nil?
    LocalWorkers.new self
  else
    begin
      server = Distributed::TestServer.connect(self)
      Distributed::RemoteWorkerClient.new(self, server, LocalWorkers.new(self))
    rescue => e
      ui_instance.distributed_failover_to_local("connect", e)
      LocalWorkers.new self
    end
  end
end

#number_of_agentsObject



19
20
21
22
# File 'lib/deep_test/options.rb', line 19

def number_of_agents
  cpu_count unless @number_of_agents
  @number_of_agents
end

#origin_hostnameObject



59
60
61
# File 'lib/deep_test/options.rb', line 59

def origin_hostname
  (Socket.gethostname == @origin_hostname) ? 'localhost' : @origin_hostname
end

#serverObject



101
102
103
# File 'lib/deep_test/options.rb', line 101

def server
  Server.remote_reference(origin_hostname, server_port)
end

#to_command_lineObject



72
73
74
75
76
77
78
79
# File 'lib/deep_test/options.rb', line 72

def to_command_line
  command_line = []
  VALID_OPTIONS.each do |option|
    value = send(option.name)
    command_line << option.to_command_line(value)
  end
  command_line.compact.join(' ')
end

#ui=(value) ⇒ Object



24
25
26
# File 'lib/deep_test/options.rb', line 24

def ui=(value)
  @ui = value.to_s
end

#ui_instanceObject



68
69
70
# File 'lib/deep_test/options.rb', line 68

def ui_instance
  UI_INSTANCES[self] ||= eval(ui).new(self)
end

#worker_listener=(value) ⇒ Object



28
29
30
# File 'lib/deep_test/options.rb', line 28

def worker_listener=(value)
  @worker_listener = value.to_s
end