Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-2468: Enable different test results in resume_test_route #446

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions dev_suites/dev_demo_ig_stu1/demo_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class DemoSuite < Inferno::TestSuite
end

config options: {
wait_test_url: "#{Inferno::Application['base_url']}/custom/demo/resume"
wait_test_url: "#{Inferno::Application['base_url']}/custom/demo/resume",
wait_test_fail_url: "#{Inferno::Application['base_url']}/custom/demo/resume_fail",
wait_test_skip_url: "#{Inferno::Application['base_url']}/custom/demo/resume_skip",
wait_test_omit_url: "#{Inferno::Application['base_url']}/custom/demo/resume_omit",
wait_test_cancel_url: "#{Inferno::Application['base_url']}/custom/demo/resume_cancel"
}

group do
Expand Down Expand Up @@ -124,6 +128,22 @@ class DemoSuite < Inferno::TestSuite
request.query_parameters['xyz']
end

resume_test_route :get, '/resume_fail', result: 'fail' do |request|
request.query_parameters['xyz']
end

resume_test_route :get, '/resume_skip', result: 'skip' do |request|
request.query_parameters['xyz']
end

resume_test_route :get, '/resume_omit', result: 'omit' do |request|
request.query_parameters['xyz']
end

resume_test_route :get, '/resume_cancel', result: 'cancel' do |request|
request.query_parameters['xyz']
end

test do
title 'Pass test'
run { pass }
Expand All @@ -137,8 +157,27 @@ class DemoSuite < Inferno::TestSuite
wait(
identifier: 'abc',
message: %(
[Follow this link to proceed](#{config.options[:wait_test_url]}?xyz=abc).
Waiting to receive a request at ```#{config.options[:wait_test_url]}?xyz=abc```.
[Follow this link to pass the test and proceed](#{config.options[:wait_test_url]}?xyz=abc).

[Follow this link to fail the test and proceed](#{config.options[:wait_test_fail_url]}?xyz=abc).

[Follow this link to skip the test and proceed](#{config.options[:wait_test_skip_url]}?xyz=abc).

[Follow this link to omit the test and proceed](#{config.options[:wait_test_omit_url]}?xyz=abc).

[Follow this link to cancel the test and proceed](#{config.options[:wait_test_cancel_url]}?xyz=abc).

Waiting to receive a request at one of:

```#{config.options[:wait_test_url]}?xyz=abc```,

```#{config.options[:wait_test_fail_url]}?xyz=abc```,

```#{config.options[:wait_test_skip_url]}?xyz=abc```,

```#{config.options[:wait_test_omit_url]}?xyz=abc```,

```#{config.options[:wait_test_cancel_url]}?xyz=abc```.
)
)
end
Expand Down
6 changes: 5 additions & 1 deletion docs/advanced-test-features/waiting-for-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ docs](/inferno-core/docs/Inferno/DSL/Results.html#wait-instance_method)
### Handling the Incoming Request
The route to make a test resume execution is created with
[`resume_test_route`](/inferno-core/docs/Inferno/DSL/Runnable.html#resume_test_route-instance_method),
which takes three arguments:
which takes five arguments:
* `method` - A symbol for the HTTP verb for the incoming request (`:get`,
`:post`, etc.)
* `path` - A string for the route path. The route will be served at
`INFERNO_BASE/custom/SUITE_ID/CUSTOM_ROUTE_PATH`.
* `tags` - An array of strings with which the incoming request will be tagged.
* `result` - A string for the result of the test. Must be one of `'pass'`,
`'fail'`, `'skip'`, `'omit'`, or `'cancel'`
(see [Results](/inferno-core/writing-tests/assertions-and-results.html#results)). The default is `'pass'`.
* A block which extracts `identifier` from the incoming request and returns it.
In this block, `request` can be used to access a [`Request`
object](/inferno-core/docs/Inferno/Entities/Request.html) which contains the
Expand Down
2 changes: 1 addition & 1 deletion lib/inferno/apps/web/controllers/test_runs/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def handle(req, res)

if test_run_is_waiting
waiting_result = results_repo.find_waiting_result(test_run_id: test_run.id)
results_repo.cancel_waiting_result(waiting_result.id, 'Test cancelled by user')
results_repo.update_result(waiting_result.id, 'cancel', 'Test cancelled by user')
Jobs.perform(Jobs::ResumeTestRun, test_run.id)
end

Expand Down
7 changes: 6 additions & 1 deletion lib/inferno/dsl/resume_test_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def tags
self.class.singleton_class.instance_variable_get(:@tags)
end

# @private
def result
self.class.singleton_class.instance_variable_get(:@result)
end

# @private
def find_test_run(test_run_identifier)
test_runs_repo.find_latest_waiting_by_identifier(test_run_identifier)
Expand All @@ -40,7 +45,7 @@ def find_waiting_result(test_run)

# @private
def update_result(waiting_result)
results_repo.pass_waiting_result(waiting_result.id)
results_repo.update_result(waiting_result.id, result)
end

# @private
Expand Down
5 changes: 4 additions & 1 deletion lib/inferno/dsl/runnable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,19 @@ def suite
# Router](https://github.com/hanami/router/tree/f41001d4c3ee9e2d2c7bb142f74b43f8e1d3a265#a-beautiful-dsl)
# can be used here.
# @param tags [Array<String>] a list of tags to assign to the request
# @param result [String] the result for the waiting test. Must be one of:
# 'pass', 'fail', 'skip', 'omit', 'cancel'
# @yield This method takes a block which must return the identifier
# defined when a test was set to wait for the test run that hit this
# route. The block has access to the `request` method which returns a
# {Inferno::Entities::Request} object with the information for the
# incoming request.
# @return [void]
def resume_test_route(method, path, tags: [], &block)
def resume_test_route(method, path, tags: [], result: 'pass', &block)
route_class = Class.new(ResumeTestRoute) do |klass|
klass.singleton_class.instance_variable_set(:@test_run_identifier_block, block)
klass.singleton_class.instance_variable_set(:@tags, tags)
klass.singleton_class.instance_variable_set(:@result, result)
end

route(method, path, route_class)
Expand Down
8 changes: 2 additions & 6 deletions lib/inferno/repositories/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ def current_results_for_test_session_and_runnables(test_session_id, runnables)
end
end

def pass_waiting_result(result_id, message = nil)
update(result_id, result: 'pass', result_message: message)
end

def cancel_waiting_result(result_id, message = nil)
update(result_id, result: 'cancel', result_message: message)
def update_result(result_id, result, result_message = nil)
update(result_id, result:, result_message:)
end

def json_serializer_options
Expand Down
32 changes: 32 additions & 0 deletions spec/inferno/dsl/runnable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@

expect(updated_run.identifier).to be_nil
end

it 'results in a fail when fail result is specified' do
get '/custom/demo/resume_fail?xyz=IDENTIFIER'

updated_result = Inferno::Repositories::Results.new.find(result.id)

expect(updated_result.result).to eq('fail')
end

it 'results in a skip when skip result is specified' do
get '/custom/demo/resume_skip?xyz=IDENTIFIER'

updated_result = Inferno::Repositories::Results.new.find(result.id)

expect(updated_result.result).to eq('skip')
end

it 'results in an omit when omit result is specified' do
get '/custom/demo/resume_omit?xyz=IDENTIFIER'

updated_result = Inferno::Repositories::Results.new.find(result.id)

expect(updated_result.result).to eq('omit')
end

it 'results in a cancel when cancel result is specified' do
get '/custom/demo/resume_cancel?xyz=IDENTIFIER'

updated_result = Inferno::Repositories::Results.new.find(result.id)

expect(updated_result.result).to eq('cancel')
end
end
end

Expand Down
Loading