Class: Inferno::DSL::ResumeTestRoute
- Inherits:
-
Hanami::Action
- Object
- Hanami::Action
- Inferno::DSL::ResumeTestRoute
- Defined in:
- lib/inferno/dsl/resume_test_route.rb
Overview
A base class for creating routes to resume test execution upon receiving an incoming request.
Class Method Summary collapse
Instance Method Summary collapse
- #find_test(waiting_result) ⇒ Object
- #find_test_run(test_run_identifier) ⇒ Object
- #find_waiting_result(test_run) ⇒ Object
- #handle(req, res) ⇒ Object
- #persist_request(request, test_run, waiting_result, test) ⇒ Object
- #redirect_route(test_run, test) ⇒ Object
- #result ⇒ Object
- #resume_ui_at_id(test_run, test) ⇒ Object
- #tags ⇒ Object
- #test_run_identifier_block ⇒ Object
- #update_result(waiting_result, message) ⇒ Object
Class Method Details
.call ⇒ Object
17 18 19 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 17 def self.call(...) new.call(...) end |
Instance Method Details
#find_test(waiting_result) ⇒ Object
69 70 71 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 69 def find_test(waiting_result) tests_repo.find(waiting_result.test_id) end |
#find_test_run(test_run_identifier) ⇒ Object
37 38 39 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 37 def find_test_run(test_run_identifier) test_runs_repo.find_latest_waiting_by_identifier(test_run_identifier) end |
#find_waiting_result(test_run) ⇒ Object
42 43 44 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 42 def find_waiting_result(test_run) results_repo.find_waiting_result(test_run_id: test_run.id) end |
#handle(req, res) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 79 def handle(req, res) request = Inferno::Entities::Request.from_hanami_request(req) test_run_identifier = instance_exec(request, &test_run_identifier_block) = request.query_parameters['message'] test_run = find_test_run(test_run_identifier) halt 500, "Unable to find test run with identifier '#{test_run_identifier}'." if test_run.nil? test_runs_repo.mark_as_no_longer_waiting(test_run.id) waiting_result = find_waiting_result(test_run) test = find_test(waiting_result) update_result(waiting_result, ) persist_request(request, test_run, waiting_result, test) Jobs.perform( Jobs::ResumeTestRun, test_run.id, tags: [ 'source:route', "session:#{test_run.test_session_id}", "run:#{test_run.test_suite_id || test_run.test_group_id || test_run.test_id}", "test:#{test.id}" ] ) res.redirect_to redirect_route(test_run, test) end |
#persist_request(request, test_run, waiting_result, test) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 52 def persist_request(request, test_run, waiting_result, test) requests_repo.create( request.to_hash.merge( test_session_id: test_run.test_session_id, result_id: waiting_result.id, name: test.config.request_name(test.incoming_request_name), tags: ) ) end |
#redirect_route(test_run, test) ⇒ Object
64 65 66 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 64 def redirect_route(test_run, test) "#{Application['base_url']}/test_sessions/#{test_run.test_session_id}##{resume_ui_at_id(test_run, test)}" end |
#result ⇒ Object
32 33 34 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 32 def result self.class.singleton_class.instance_variable_get(:@result) end |
#resume_ui_at_id(test_run, test) ⇒ Object
74 75 76 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 74 def resume_ui_at_id(test_run, test) test_run.test_suite_id || test_run.test_group_id || test.parent&.id || test.id end |
#tags ⇒ Object
27 28 29 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 27 def self.class.singleton_class.instance_variable_get(:@tags) end |
#test_run_identifier_block ⇒ Object
22 23 24 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 22 def test_run_identifier_block self.class.singleton_class.instance_variable_get(:@test_run_identifier_block) end |
#update_result(waiting_result, message) ⇒ Object
47 48 49 |
# File 'lib/inferno/dsl/resume_test_route.rb', line 47 def update_result(waiting_result, ) results_repo.update_result(waiting_result.id, result, ) end |