Module: AntiSmoker

Defined in:
lib/antismoker.rb,
lib/antismoker/tests.rb,
lib/antismoker/loader.rb,
lib/antismoker/runner.rb,
lib/antismoker/version.rb,
lib/antismoker/deployment.rb,
lib/antismoker/tests/http.rb

Defined Under Namespace

Classes: AbstractSmokeTest, Deployment, HttpTest

Constant Summary collapse

DEFAULT_PROTOCOL_NAME =
"__default__"
DEFAULT_PROTOCOL_OPTIONS =
{
  :count => 3, # test retry count
  :delay => 0.0, # delay for first test in seconds.
  :period => 3.0, # retry interval between each tests.
  :timeout => 5.0, # test timeout
}
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.load(file, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/antismoker/loader.rb', line 15

def load(file, options={})
  env = options.fetch(:env, "development")
  defs = YAML.load(File.read(file))
  abort("No such environment was defined in #{file}: #{env}") unless defs.has_key?(env)

  smoketests = []
  defs[env].each do |host, smoke_spec|
    default_options = smoke_spec.delete(DEFAULT_PROTOCOL_NAME)
    DEFAULT_PROTOCOL_OPTIONS.update(default_options) if default_options

    smoke_spec.each do |protocol, options|
      begin
        require "antismoker/tests/#{protocol}"
      rescue LoadError => error
        abort("Could not load smoke test for #{protocol}: #{error}")
      end

      begin
        name = protocol.scan(/\w+/).map { |w| w.capitalize }.join
        klass = AntiSmoker.const_get("#{name}Test")
      rescue NameError => error
        abort("[BUG] Broken smoke test for #{protocol}: #{error}")
      end

      if options.is_a?(Hash)
        options = DEFAULT_PROTOCOL_OPTIONS.merge(options)
      else
        options = DEFAULT_PROTOCOL_OPTIONS.merge(:port => options)
      end
      begin
        options[:port] = Socket.getservbyname(protocol) unless options.has_key?(:port)
      rescue SocketError => error
        abort("Could not resolve well-known port for #{protocol}: #{error}")
      end
      ports = [ options.delete(:port) ].flatten
      smoketests += ports.map { |port| klass.new(host, port, options) }
    end
  end

  smoketests
end

.run(smoketests = [], options = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/antismoker/runner.rb', line 6

def run(smoketests=[], options={})
  results = smoketests.map { |smoketest|
    run_single(smoketest, options)
  }
rescue Interrupt
  abort("Interrupted")
end

.run_single(smoketest, options = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/antismoker/runner.rb', line 15

def run_single(smoketest, options={})
  begin
    smoketest.run(options)
  rescue => error
    false
  end
end