Class: AntiSmoker::AbstractSmokeTest
- Inherits:
-
Object
- Object
- AntiSmoker::AbstractSmokeTest
- Defined in:
- lib/antismoker/tests.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(host, port, options = {}) ⇒ AbstractSmokeTest
constructor
A new instance of AbstractSmokeTest.
- #run(options = {}) ⇒ Object
- #run_once(options = {}) ⇒ Object
- #run_once_with_timeout(options = {}) ⇒ Object
- #sleep_with_progress(n) ⇒ Object
Constructor Details
#initialize(host, port, options = {}) ⇒ AbstractSmokeTest
Returns a new instance of AbstractSmokeTest.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/antismoker/tests.rb', line 8 def initialize(host, port, ={}) @host = host @port = port @options = @delay = [:delay] @count = [:count] @period = [:period] @timeout = [:timeout] @logger = Logger.new(STDERR) @logger.level = Logger.const_get(.fetch(:log, :info).to_s.upcase) end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
26 27 28 |
# File 'lib/antismoker/tests.rb', line 26 def count @count end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
25 26 27 |
# File 'lib/antismoker/tests.rb', line 25 def delay @delay end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
21 22 23 |
# File 'lib/antismoker/tests.rb', line 21 def host @host end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
30 31 32 |
# File 'lib/antismoker/tests.rb', line 30 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/antismoker/tests.rb', line 23 def @options end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
27 28 29 |
# File 'lib/antismoker/tests.rb', line 27 def period @period end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
22 23 24 |
# File 'lib/antismoker/tests.rb', line 22 def port @port end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
28 29 30 |
# File 'lib/antismoker/tests.rb', line 28 def timeout @timeout end |
Instance Method Details
#run(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/antismoker/tests.rb', line 41 def run(={}) STDOUT.write("smoke testing: #{self}: ") sleep_with_progress(delay) n = 0 while n < count if run_once_with_timeout() STDOUT.puts(" [\e[1;32m OK \e[0m]") return true else STDOUT.putc(?!) sleep_with_progress(period) n += 1 end end STDOUT.puts(" [\e[31m NG \e[0m]") return false end |
#run_once(options = {}) ⇒ Object
72 73 74 |
# File 'lib/antismoker/tests.rb', line 72 def run_once(={}) raise("must be overridden") end |
#run_once_with_timeout(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/antismoker/tests.rb', line 59 def run_once_with_timeout(={}) begin Timeout.timeout(timeout) { return run_once() } rescue Timeout::Error => error logger.warn("timed out: #{self}: #{error}") rescue => error logger.warn("unknown error: #{self}: #{error}") end false end |
#sleep_with_progress(n) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/antismoker/tests.rb', line 32 def sleep_with_progress(n) deadline = Time.now + n while Time.now < deadline STDOUT.putc(?.) STDOUT.flush sleep(n.to_f / 3) end end |