Class: DatatrueClient::TestRun
- Inherits:
-
Object
- Object
- DatatrueClient::TestRun
- Defined in:
- lib/datatrue_client/test_run.rb
Instance Attribute Summary collapse
-
#job_id ⇒ Object
readonly
Returns the value of attribute job_id.
-
#polling_interval ⇒ Object
Returns the value of attribute polling_interval.
-
#polling_timeout ⇒ Object
Returns the value of attribute polling_timeout.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TestRun
constructor
A new instance of TestRun.
-
#poll_progress(print_progress = nil) ⇒ Object
Keeps querying progress until progress status is ‘complete`.
-
#query_progress ⇒ Hash
Queries test run progress.
Constructor Details
#initialize(options = {}) ⇒ TestRun
Returns a new instance of TestRun.
65 66 67 68 69 70 71 72 73 |
# File 'lib/datatrue_client/test_run.rb', line 65 def initialize(={}) @options = @bridge = Bridge.new() @polling_timeout = [:polling_timeout] || 60 @polling_interval = [:polling_interval] || 2 create end |
Instance Attribute Details
#job_id ⇒ Object (readonly)
Returns the value of attribute job_id.
55 56 57 |
# File 'lib/datatrue_client/test_run.rb', line 55 def job_id @job_id end |
#polling_interval ⇒ Object
Returns the value of attribute polling_interval.
56 57 58 |
# File 'lib/datatrue_client/test_run.rb', line 56 def polling_interval @polling_interval end |
#polling_timeout ⇒ Object
Returns the value of attribute polling_timeout.
56 57 58 |
# File 'lib/datatrue_client/test_run.rb', line 56 def polling_timeout @polling_timeout end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
55 56 57 |
# File 'lib/datatrue_client/test_run.rb', line 55 def progress @progress end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
55 56 57 |
# File 'lib/datatrue_client/test_run.rb', line 55 def title @title end |
Class Method Details
.build_progress_message(details) ⇒ String
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 |
# File 'lib/datatrue_client/test_run.rb', line 25 def (details) status = get_progress_status(details) tests = details.dig(:progress, 'tests') || [] steps = tests.map { |test| test['steps'] }.compact.flatten total_steps = details.dig(:progress, 'steps_total') current_step_index = steps.index { |step| step['running'] } if current_step_index # read step and crawled pages details step = steps[current_step_index] is_coverage_step = step['actions_total'] > 1 coverage_step_details = " (#{step['actions_completed']}/#{step['actions_total']} pages)" = %{ test_run_id=#{details[:options]['test_run_id']} step=#{current_step_index + 1}#{is_coverage_step ? coverage_step_details : ''} total_steps=#{total_steps} result=#{status} } else = %{ test_run_id=#{details[:options]['test_run_id']} result=#{status} } end .gsub(/\s+/, ' ').strip end |
.get_progress_status(details) ⇒ String
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/datatrue_client/test_run.rb', line 11 def get_progress_status(details) if details[:status] == 'completed' if details[:progress]['tests'].all? { |result| ['success', 'validated'].include? result['state'] } status = 'passed' else status = 'failed' end else status = details[:status] end end |
Instance Method Details
#poll_progress(print_progress = nil) ⇒ Object
Keeps querying progress until progress status is ‘complete`
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/datatrue_client/test_run.rb', line 83 def poll_progress(print_progress=nil) start_time = DateTime.now loop do res = query_progress @progress = progress_percentage(res) print_progress.call(@progress, res) if print_progress return res if res[:status] == 'completed' if elapsed_milliseconds(start_time, DateTime.now) >= @polling_timeout * 1000 raise TimeoutError.new("Polling progress timed out after #{@polling_timeout} seconds") break else sleep @polling_interval end end end |
#query_progress ⇒ Hash
Queries test run progress
77 78 79 |
# File 'lib/datatrue_client/test_run.rb', line 77 def query_progress @bridge.test_run_progress(job_id) end |